internal void Initialize(AssetStore assetStore) { // We need to check if there is an existing MapCache.ini file and if yes, // load it so that we can figure out which entries are outdated. // Then we need to update these entries, update the file, and parse it // again. In order to do that we first load it in a temporary scope. assetStore.PushScope(); var mapCacheIniEntry = _contentManager.UserDataFileSystem.GetFile(MapCacheIniPath); if (mapCacheIniEntry != null) { _contentManager.LoadIniFile(mapCacheIniEntry); } // for each map, check if it was modified and the MapCache needs to be updated. var mapCacheEntries = new Dictionary <string, MapCache>(); foreach (var mapEntry in EnumerateMaps()) { var buildMapCache = false; var mapCache = assetStore.MapCaches.GetByName(mapEntry.FullFilePath); var fileInfo = new FileInfo(mapEntry.FullFilePath); if (mapCache == null) { // new map buildMapCache = true; } else { var timestamp = DateTime.FromFileTime((((long)mapCache.TimestampHi) << 32) | (uint)mapCache.TimestampLo); // TODO: Should we check the CRC here as well? // If yes, which implementation should we use? if (fileInfo.LastWriteTime != timestamp && fileInfo.Length != mapCache.FileSize) { // existing map modified buildMapCache = true; } } if (buildMapCache) { mapCache = BuildMapCache(mapEntry, fileInfo, assetStore); } mapCacheEntries.Add(mapEntry.FullFilePath, mapCache); } // Get rid of the old MapCaches, generate the file based on // the updated ones and load it again, this time for real. assetStore.PopScope(); var fullMapCacheIniPath = Path.Combine(_contentManager.UserDataFileSystem.RootDirectory, MapCacheIniPath); GenerateMapCacheIniFile(fullMapCacheIniPath, mapCacheEntries); mapCacheIniEntry = new FileSystemEntry( _contentManager.UserDataFileSystem, MapCacheIniPath, (uint)new FileInfo(fullMapCacheIniPath).Length, () => File.OpenRead(fullMapCacheIniPath)); _contentManager.UserDataFileSystem.Update(mapCacheIniEntry); _contentManager.LoadIniFile(mapCacheIniEntry); }