Changeset 331 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Sep 6, 2018, 1:46:44 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r329 r331 46 46 47 47 Profiler.BeginSample ("ReadPng"); 48 cacheEntry.pngData = File.ReadAllBytes (filename);48 cacheEntry.pngData = ReadAllBytes (filename); 49 49 Profiler.EndSample (); 50 50 } … … 63 63 lock (cache) { 64 64 CurrentZoomFile cacheEntry = cache [zoomlevel]; 65 66 if (string.IsNullOrEmpty (cacheEntry.filename)) { 65 66 string file = cacheEntry.filename; 67 if (string.IsNullOrEmpty (file)) { 67 68 return; 68 69 } … … 71 72 72 73 Profiler.BeginSample ("WritePng"); 73 File.WriteAllBytes (cacheEntry.filename, contentPng); 74 using (Stream stream = new FileStream (file, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 75 4096)) { 76 stream.Write (contentPng, 0, contentPng.Length); 77 } 74 78 Profiler.EndSample (); 75 79 } … … 92 96 } 93 97 94 return File.ReadAllBytes (filename);98 return ReadAllBytes (filename); 95 99 } 96 100 } catch (Exception e) { … … 101 105 } 102 106 107 private static byte[] ReadAllBytes (string _path) { 108 using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096)) { 109 int bytesRead = 0; 110 int bytesLeft = (int) fileStream.Length; 111 byte[] result = new byte[bytesLeft]; 112 while (bytesLeft > 0) { 113 int readThisTime = fileStream.Read (result, bytesRead, bytesLeft); 114 if (readThisTime == 0) { 115 throw new IOException ("Unexpected end of stream"); 116 } 117 118 bytesRead += readThisTime; 119 bytesLeft -= readThisTime; 120 } 121 122 return result; 123 } 124 } 125 126 103 127 private class CurrentZoomFile { 104 128 public string filename;
Note:
See TracChangeset
for help on using the changeset viewer.