@@ -14,7 +14,7 @@ namespace DTAClient.Domain.Multiplayer
14
14
public class MapLoader
15
15
{
16
16
public const string MAP_FILE_EXTENSION = ".map" ;
17
- private const string CUSTOM_MAPS_DIRECTORY = "Maps/ Custom" ;
17
+ private const string CUSTOM_MAPS_DIRECTORY = "Maps\\ Custom" ;
18
18
private static readonly string CUSTOM_MAPS_CACHE = SafePath . CombineFilePath ( ProgramConstants . ClientUserFilesPath , "custom_map_cache" ) ;
19
19
private const string MultiMapsSection = "MultiMaps" ;
20
20
private const string GameModesSection = "GameModes" ;
@@ -23,9 +23,9 @@ public class MapLoader
23
23
24
24
/// <summary>
25
25
/// The relative path to the folder where custom maps are stored.
26
- /// This is the public version of CUSTOM_MAPS_DIRECTORY ending in a slash for convenience .
26
+ /// This is the public version of CUSTOM_MAPS_DIRECTORY.
27
27
/// </summary>
28
- public const string CustomMapsDirectory = CUSTOM_MAPS_DIRECTORY + "/" ;
28
+ public const string CustomMapsDirectory = CUSTOM_MAPS_DIRECTORY ;
29
29
30
30
/// <summary>
31
31
/// List of game modes.
@@ -95,7 +95,7 @@ public void LoadMapsAsync()
95
95
/// </summary>
96
96
public void StartCustomMapFileWatcher ( )
97
97
{
98
- customMapFileWatcher = new FileSystemWatcher ( $ " { ProgramConstants . GamePath } { CustomMapsDirectory } " ) ;
98
+ customMapFileWatcher = new FileSystemWatcher ( SafePath . CombineDirectoryPath ( ProgramConstants . GamePath , CustomMapsDirectory ) ) ;
99
99
100
100
customMapFileWatcher . Filter = $ "*{ MAP_FILE_EXTENSION } ";
101
101
customMapFileWatcher . NotifyFilter = NotifyFilters . Attributes
@@ -127,8 +127,8 @@ public void HandleCustomMapFolder_Created(object sender, FileSystemEventArgs e)
127
127
{
128
128
// Get the map filename without the extension.
129
129
// The extension gets added in LoadCustomMap so we need to excise it to avoid "file.map.map".
130
- string name = e . Name . EndsWith ( MAP_FILE_EXTENSION ) ? e . Name . Remove ( e . Name . Length - MAP_FILE_EXTENSION . Length ) : e . Name ;
131
- string relativeMapPath = $ " { CustomMapsDirectory } { name } " ;
130
+ string name = Path . GetFileNameWithoutExtension ( e . Name ) ;
131
+ string relativeMapPath = SafePath . CombineFilePath ( CustomMapsDirectory , name ) ;
132
132
Map map = LoadCustomMap ( relativeMapPath , out string result ) ;
133
133
134
134
if ( map == null )
@@ -149,9 +149,11 @@ public void HandleCustomMapFolder_Deleted(object sender, FileSystemEventArgs e)
149
149
Logger . Log ( $ "Map was deleted: map={ e . Name } ") ;
150
150
// The way we're detecting the loaded map is hacky, but we don't
151
151
// have the sha1 to work with.
152
+ string name = Path . GetFileNameWithoutExtension ( e . Name ) ;
152
153
foreach ( GameMode gameMode in GameModes )
153
154
{
154
- gameMode . Maps . RemoveAll ( map => map . CompleteFilePath . EndsWith ( e . Name ) ) ;
155
+ string test = Path . GetFileNameWithoutExtension ( gameMode . Name ) ;
156
+ gameMode . Maps . RemoveAll ( map => Path . GetFileNameWithoutExtension ( map . CompleteFilePath ) . EndsWith ( name ) ) ;
155
157
}
156
158
157
159
RemoveEmptyGameModesAndUpdateGameModeMaps ( ) ;
@@ -170,15 +172,29 @@ public void HandleCustomMapFolder_Deleted(object sender, FileSystemEventArgs e)
170
172
/// <param name="e"></param>
171
173
public void HandleCustomMapFolder_Renamed ( object sender , RenamedEventArgs e )
172
174
{
173
- string name = e . Name . EndsWith ( MAP_FILE_EXTENSION ) ? e . Name . Remove ( e . Name . Length - MAP_FILE_EXTENSION . Length ) : e . Name ;
174
- string relativeMapPath = $ "{ CustomMapsDirectory } { name } ";
175
+ string name = Path . GetFileNameWithoutExtension ( e . Name ) ;
176
+ string relativeMapPath = SafePath . CombineFilePath ( CustomMapsDirectory , name ) ;
177
+ bool oldPathIsMap = Path . GetExtension ( e . OldName ) == MAP_FILE_EXTENSION ;
178
+ bool newPathIsMap = Path . GetExtension ( e . Name ) == MAP_FILE_EXTENSION ;
175
179
176
180
// Check if the user is renaming a non ".map" file.
177
181
// This is just for logging to help debug.
178
- if ( ! e . OldName . EndsWith ( MAP_FILE_EXTENSION ) )
182
+ if ( ! oldPathIsMap && newPathIsMap )
179
183
{
180
184
Logger . Log ( $ "Renaming file changed the file extension. User is likely renaming a '.yrm' from Final Alert 2: old={ e . OldName } , new={ e . Name } ") ;
181
185
}
186
+ else if ( oldPathIsMap && ! newPathIsMap )
187
+ {
188
+ // A bit hacky, but this is a rare case.
189
+ Logger . Log ( $ "Renaming file changed the file extension to no longer be '.map' for some reason, removing from map list: old={ e . OldName } , new={ e . Name } ") ;
190
+ HandleCustomMapFolder_Deleted ( sender , e ) ;
191
+ }
192
+
193
+ if ( ! newPathIsMap )
194
+ {
195
+ Logger . Log ( $ "Renaming file. New extension is not '{ MAP_FILE_EXTENSION } ', moving on: file={ e . Name } ") ;
196
+ return ;
197
+ }
182
198
183
199
Map map = LoadCustomMap ( relativeMapPath , out string result ) ;
184
200
0 commit comments