@@ -8,24 +8,22 @@ use crate::{GameType, State};
8
8
const GHOST_EXTENSION : & str = "ghost" ;
9
9
const GHOST_EXTENSION_WITH_PERIOD : & str = ".ghost" ;
10
10
11
- fn is_unghosted_plugin_file_extension ( game_type : GameType , extension : & str ) -> bool {
12
- match extension {
13
- "esp" | "esm" => true ,
14
- "esl" if game_type. supports_light_plugins ( ) => true ,
15
- _ => false ,
16
- }
11
+ fn is_unghosted_plugin_file_extension ( game_type : GameType , extension : & OsStr ) -> bool {
12
+ extension. eq_ignore_ascii_case ( "esp" )
13
+ || extension. eq_ignore_ascii_case ( "esm" )
14
+ || ( game_type. supports_light_plugins ( ) && extension. eq_ignore_ascii_case ( "esl" ) )
17
15
}
18
16
19
17
fn has_unghosted_plugin_file_extension ( game_type : GameType , path : & Path ) -> bool {
20
- match path. extension ( ) . and_then ( OsStr :: to_str ) {
18
+ match path. extension ( ) {
21
19
Some ( ext) => is_unghosted_plugin_file_extension ( game_type, ext) ,
22
20
_ => false ,
23
21
}
24
22
}
25
23
26
24
pub fn has_plugin_file_extension ( game_type : GameType , path : & Path ) -> bool {
27
- match path. extension ( ) . and_then ( OsStr :: to_str ) {
28
- Some ( GHOST_EXTENSION ) => path
25
+ match path. extension ( ) {
26
+ Some ( ext ) if ext . eq_ignore_ascii_case ( GHOST_EXTENSION ) => path
29
27
. file_stem ( )
30
28
. map ( |s| has_unghosted_plugin_file_extension ( game_type, Path :: new ( s) ) )
31
29
. unwrap_or ( false ) ,
@@ -45,10 +43,18 @@ fn add_ghost_extension(path: PathBuf) -> PathBuf {
45
43
}
46
44
}
47
45
48
- pub fn normalise_file_name ( game_type : GameType , name : & str ) -> & str {
49
- if let Some ( stem) = name. strip_suffix ( GHOST_EXTENSION_WITH_PERIOD ) {
50
- if has_unghosted_plugin_file_extension ( game_type, Path :: new ( stem) ) {
51
- return stem;
46
+ pub fn normalise_file_name ( game_type : GameType , name : & OsStr ) -> & OsStr {
47
+ let path = Path :: new ( name) ;
48
+ if path
49
+ . extension ( )
50
+ . map ( |s| s. eq_ignore_ascii_case ( GHOST_EXTENSION ) )
51
+ . unwrap_or ( false )
52
+ {
53
+ // name ends in .ghost, trim it and then check the file extension.
54
+ if let Some ( stem) = path. file_stem ( ) {
55
+ if has_unghosted_plugin_file_extension ( game_type, Path :: new ( stem) ) {
56
+ return stem;
57
+ }
52
58
}
53
59
}
54
60
@@ -89,7 +95,7 @@ mod tests {
89
95
90
96
#[ test]
91
97
fn is_unghosted_plugin_file_extension_should_be_true_for_esp_for_all_game_types ( ) {
92
- let extension = "esp" ;
98
+ let extension = OsStr :: new ( "Esp" ) ;
93
99
94
100
assert ! ( is_unghosted_plugin_file_extension(
95
101
GameType :: Morrowind ,
@@ -131,7 +137,7 @@ mod tests {
131
137
132
138
#[ test]
133
139
fn is_unghosted_plugin_file_extension_should_be_true_for_esm_for_all_game_types ( ) {
134
- let extension = "esm" ;
140
+ let extension = OsStr :: new ( "Esm" ) ;
135
141
136
142
assert ! ( is_unghosted_plugin_file_extension(
137
143
GameType :: Morrowind ,
@@ -173,7 +179,7 @@ mod tests {
173
179
174
180
#[ test]
175
181
fn is_unghosted_plugin_file_extension_should_be_true_for_esl_for_tes5se_tes5vr_fo4_and_fo4vr ( ) {
176
- let extension = "esl" ;
182
+ let extension = OsStr :: new ( "Esl" ) ;
177
183
178
184
assert ! ( is_unghosted_plugin_file_extension(
179
185
GameType :: SkyrimSE ,
@@ -195,7 +201,7 @@ mod tests {
195
201
196
202
#[ test]
197
203
fn is_unghosted_plugin_file_extension_should_be_false_for_esl_for_tes3_to_5_fo3_and_fonv ( ) {
198
- let extension = "esl" ;
204
+ let extension = OsStr :: new ( "Esl" ) ;
199
205
200
206
assert ! ( !is_unghosted_plugin_file_extension(
201
207
GameType :: Morrowind ,
@@ -221,7 +227,7 @@ mod tests {
221
227
222
228
#[ test]
223
229
fn is_unghosted_plugin_file_extension_should_be_false_for_ghost_for_all_game_types ( ) {
224
- let extension = "ghost" ;
230
+ let extension = OsStr :: new ( "Ghost" ) ;
225
231
226
232
assert ! ( !is_unghosted_plugin_file_extension(
227
233
GameType :: Morrowind ,
@@ -263,7 +269,7 @@ mod tests {
263
269
264
270
#[ test]
265
271
fn is_unghosted_plugin_file_extension_should_be_false_for_non_esp_esm_esl_for_all_game_types ( ) {
266
- let extension = "txt" ;
272
+ let extension = OsStr :: new ( "txt" ) ;
267
273
268
274
assert ! ( !is_unghosted_plugin_file_extension(
269
275
GameType :: Morrowind ,
@@ -351,7 +357,7 @@ mod tests {
351
357
fn has_plugin_file_extension_should_return_true_if_the_path_has_a_ghosted_plugin_extension ( ) {
352
358
assert ! ( has_plugin_file_extension(
353
359
GameType :: Skyrim ,
354
- Path :: new( "plugin.esp.ghost " )
360
+ Path :: new( "plugin.esp.Ghost " )
355
361
) ) ;
356
362
}
357
363
@@ -368,15 +374,15 @@ mod tests {
368
374
) {
369
375
assert ! ( !has_plugin_file_extension(
370
376
GameType :: Skyrim ,
371
- Path :: new( "plugin.bsa.ghost " )
377
+ Path :: new( "plugin.bsa.Ghost " )
372
378
) ) ;
373
379
}
374
380
375
381
#[ test]
376
382
fn has_plugin_file_extension_should_return_false_if_the_path_has_only_ghost_extension ( ) {
377
383
assert ! ( !has_plugin_file_extension(
378
384
GameType :: Skyrim ,
379
- Path :: new( "plugin.ghost " )
385
+ Path :: new( "plugin.Ghost " )
380
386
) ) ;
381
387
}
382
388
0 commit comments