Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions scripts/map/MapCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -195,7 +196,7 @@ private static void addNonCachedFiles(string[] toParseMaps)
var maps = FetchAll();

HashSet<string> 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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions scripts/map/MapParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -766,7 +766,8 @@ public static Map PHXM(string path)
if (Directory.Exists(extractedFolderPath))
{
Directory.Delete(extractedFolderPath, true);
Map existingMap = DatabaseService.Connection.Table<Map>().FirstOrDefault(x => x.FolderPath == extractedFolderPath);
string cachedFolderPath = MapCache.BackSlashToForwardSlash(extractedFolderPath);
Map existingMap = DatabaseService.Connection.Table<Map>().FirstOrDefault(x => x.FolderPath == cachedFolderPath);
MapCache.RemoveMap(existingMap);
}

Expand Down