1 module zgrf.filetable.common; 2 3 import zgrf.types : GRFFile; 4 5 /** 6 * Checks if a given [GRFFile] matches one of our filters. 7 * 8 * The check converts the name of the file to lowercase. 9 * 10 * Params: 11 * file = The file to check 12 * filterList = The array of filters to check against 13 * 14 * Returns: 15 * Whether the file matches one of the provided filters 16 */ 17 bool inFilter(in ref GRFFile file, in ref const(wstring)[] filterList) 18 { 19 if (filterList.length == 0) 20 { 21 return true; 22 } 23 import std.uni : toLower; 24 25 auto filenameLower = file.name.toLower; 26 foreach (const filterString; filterList) 27 { 28 import std.algorithm : startsWith; 29 30 if (filenameLower.startsWith(filterString)) 31 { 32 return true; 33 } 34 } 35 return false; 36 } 37 38 /** 39 * Checks if a given [GRFFile] is a directory. 40 * 41 * Params: 42 * file = The [GRFFile] to check 43 * 44 * Returns: 45 * Whether the file is a directory or not 46 */ 47 bool isDirectory(in ref GRFFile file) pure @safe @nogc 48 { 49 import zgrf.constants : FileFlags; 50 51 return ((file.flags & FileFlags.FILE) == 0 || 52 file.compressed_size_padded == 0x0714 || 53 file.compressed_size == 0x0449 || 54 file.size == 0x055C || 55 file.offset == 0x058A); 56 }