Changeset 402 for binary-improvements2/MapRendering/src/MapTileCache.cs
- Timestamp:
- Jan 27, 2023, 7:28:00 PM (22 months ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/src/MapTileCache.cs
r399 r402 1 1 using System; 2 using System.Diagnostics.CodeAnalysis; 2 3 using System.IO; 3 4 using UnityEngine; 4 5 using UnityEngine.Profiling; 6 using Webserver.FileCache; 5 7 using Object = UnityEngine.Object; 6 8 7 namespace AllocsFixes.FileCache{9 namespace MapRendering { 8 10 // Special "cache" for map tile folder as both map rendering and webserver access files in there. 9 11 // Only map rendering tiles are cached. Writing is done by WriteThrough. … … 25 27 } 26 28 29 // SetZoomCount only called before processing happens in MapRenderer.ctor, no locking required 30 [SuppressMessage ("ReSharper", "InconsistentlySynchronizedField")] 27 31 public void SetZoomCount (int _count) { 28 32 cache = new CurrentZoomFile[_count]; … … 55 59 } 56 60 } catch (Exception e) { 57 Log.Warning ( "Error in MapTileCache.LoadTile: " + e);61 Log.Warning ($"Error in MapTileCache.LoadTile: {e}"); 58 62 } 59 63 … … 81 85 } 82 86 } catch (Exception e) { 83 Log.Warning ( "Error in MapTileCache.SaveTile: " + e);87 Log.Warning ($"Error in MapTileCache.SaveTile: {e}"); 84 88 } 85 89 } … … 92 96 } 93 97 } catch (Exception e) { 94 Log.Warning ( "Error in MapTileCache.ResetTile: " + e);98 Log.Warning ($"Error in MapTileCache.ResetTile: {e}"); 95 99 } 96 100 } … … 108 112 } 109 113 } catch (Exception e) { 110 Log.Warning ( "Error in MapTileCache.GetFileContent: " + e);114 Log.Warning ($"Error in MapTileCache.GetFileContent: {e}"); 111 115 } 112 116 … … 119 123 120 124 private static byte[] ReadAllBytes (string _path) { 121 using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096)) { 122 int bytesRead = 0; 123 int bytesLeft = (int) fileStream.Length; 124 byte[] result = new byte[bytesLeft]; 125 while (bytesLeft > 0) { 126 int readThisTime = fileStream.Read (result, bytesRead, bytesLeft); 127 if (readThisTime == 0) { 128 throw new IOException ("Unexpected end of stream"); 129 } 130 131 bytesRead += readThisTime; 132 bytesLeft -= readThisTime; 125 using FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096); 126 127 int bytesRead = 0; 128 int bytesLeft = (int) fileStream.Length; 129 byte[] result = new byte[bytesLeft]; 130 while (bytesLeft > 0) { 131 int readThisTime = fileStream.Read (result, bytesRead, bytesLeft); 132 if (readThisTime == 0) { 133 throw new IOException ("Unexpected end of stream"); 133 134 } 134 135 135 return result; 136 bytesRead += readThisTime; 137 bytesLeft -= readThisTime; 136 138 } 139 140 return result; 137 141 } 138 142
Note:
See TracChangeset
for help on using the changeset viewer.