diff --git a/scripts/map/MapCache.cs b/scripts/map/MapCache.cs index 43cf10aa..7b251be6 100644 --- a/scripts/map/MapCache.cs +++ b/scripts/map/MapCache.cs @@ -92,6 +92,13 @@ private static void syncFiles(string[] toParseMaps) { string mapPath = BackSlashToForwardSlash(map.FolderPath); + // Older entries can have mixed separators, store them normalized so path lookups match + if (map.FolderPath != mapPath) + { + map.FolderPath = mapPath; + UpdateMap(map); + } + if (OldCacheFormat && map.Favorite) { // The new cache re-writes it from scratch with a new format, so we will need to store these for later @@ -132,15 +139,9 @@ private static void syncFiles(string[] toParseMaps) } catch (Exception ex) { + // Never delete the user's files here, a failed parse is not proof the map is broken Logger.Error(ex); - if (File.Exists(mapPath)) - { - File.Delete(mapPath); - } - else if (Directory.Exists(mapPath)) - { - Directory.Delete(mapPath, true); - } + Logger.Log($"Failed to re-sync cached map {mapPath}, removing it from the cache"); DatabaseService.Connection.Delete(map); FilesSynced.Value++; @@ -195,7 +196,7 @@ private static void addNonCachedFiles(string[] toParseMaps) var maps = FetchAll(); HashSet hashSet = []; - maps.ForEach(map => hashSet.Add(map.FolderPath)); + maps.ForEach(map => hashSet.Add(BackSlashToForwardSlash(map.FolderPath))); // Maps that need to be parsed - maps in database cache FilesToSync.Value = toParseMaps.Length - maps.Count; @@ -227,7 +228,8 @@ private static void addNonCachedFiles(string[] toParseMaps) continue; } - map.FolderPath = BackSlashToForwardSlash(toParseMap); + // .phxm files are extracted to a folder by the parser, so keep the folder path it returned + map.FolderPath = BackSlashToForwardSlash(map.FolderPath ?? toParseMap); map.MetadataObjectHash = GetMd5Checksum(map.FolderPath); if (OldCacheFormat) @@ -279,8 +281,8 @@ public static int InsertMap(Map map) return -1; } - string newPath = Path.Combine(MapUtil.MapsFolder, map.Name); - string existingPath = Path.Combine(MapUtil.MapsFolder, existing?.FolderPath ?? updated.FolderPath); + string newPath = BackSlashToForwardSlash(Path.Combine(MapUtil.MapsFolder, map.Name)); + string existingPath = BackSlashToForwardSlash(Path.Combine(MapUtil.MapsFolder, existing?.FolderPath ?? updated.FolderPath)); if (existingPath != newPath) { diff --git a/scripts/map/MapParser.cs b/scripts/map/MapParser.cs index f17ac837..5a0e1c5a 100644 --- a/scripts/map/MapParser.cs +++ b/scripts/map/MapParser.cs @@ -240,7 +240,7 @@ void addAsset(string name, byte[] buffer) map.LastModifiedMetadata = metadataModified.ToString("O", CultureInfo.InvariantCulture); map.LastModifiedNotes = objectsModified.ToString("O", CultureInfo.InvariantCulture); - map.FolderPath = mapFolderPath; + map.FolderPath = MapCache.BackSlashToForwardSlash(mapFolderPath); MapCache.InsertMap(map); @@ -766,7 +766,8 @@ public static Map PHXM(string path) if (Directory.Exists(extractedFolderPath)) { Directory.Delete(extractedFolderPath, true); - Map existingMap = DatabaseService.Connection.Table().FirstOrDefault(x => x.FolderPath == extractedFolderPath); + string cachedFolderPath = MapCache.BackSlashToForwardSlash(extractedFolderPath); + Map existingMap = DatabaseService.Connection.Table().FirstOrDefault(x => x.FolderPath == cachedFolderPath); MapCache.RemoveMap(existingMap); }