steam-rom-manager icon indicating copy to clipboard operation
steam-rom-manager copied to clipboard

[Suggestion] Ignore Hidden Files

Open bsdf opened this issue 2 years ago • 1 comments

when scanning rom directories, SRM includes hidden files (unix-style, prefixed with a dot) in its list of candidates with no way for the user to opt out of this behavior. i cannot think of a valid use case where a user would have items in a hidden folder that they would want to be included, so i am proposing that hidden files be excluded by default. since i am new to SRM development, i do not have the context or history to know why they are explicitly included by default, so i would like to open this discussion.

Example - Multi-disc Games

to illustrate why one might want to ignore hidden files within a directory, let's take a look at a common use case—multi-disc games. users generally want a single entry in their ROM launcher of choice but most scanners would create an entry for each disc image.

a common way to deal with multi-disc games is to create an m3u "playlist" of the disc images which represents the "game". the m3u is loaded by the emulator and the user can swap between discs using emulator-provided functionality. here's how this might look on the filesystem:

~/roms/game.m3u
~/roms/game.cd1.chd
~/roms/game.cd2.chd

scanning this directory, SRM would create three entries where we'd only want one (game.m3u).

my preferred workaround is to place the disc images in a hidden folder, with a visible m3u referring to those files:

~/roms/game.m3u
~/roms/.chds/game.cd1.chd
~/roms/.chds/game.cd2.chd

ideally, this would result in a single entry for the m3u, with the disc image files hidden from the scanner.

Suggested Changes

i believe the simplest solution would be to set the dot: false configuration value when using the minimatch and glob libraries. a diff might look something like this:

diff --git a/src/lib/parsers/glob.parser.ts b/src/lib/parsers/glob.parser.ts
index 8e3f040b..28fb6bc3 100644
--- a/src/lib/parsers/glob.parser.ts
+++ b/src/lib/parsers/glob.parser.ts
@@ -138,7 +138,7 @@ tempGlob = fileGlob.replace(/.*\${title}/i, '');
     let titleRegex = '';
     let pos = 1;
     let getRegexString = (segment: string) => {
-      let mm = new minimatch.Minimatch(segment, { dot: true });
+      let mm = new minimatch.Minimatch(segment, { dot: false });
       if (mm.empty)
         return '^\\s*?$';
       else{
@@ -220,7 +220,7 @@ tempGlob = fileGlob.replace(/.*\${title}/i, '');
       const validationText = this.validate(inputs['glob']);
       if (validationText === null) {
         const titleData = this.extractTitleTag(inputs['glob']);
-        glob(titleData.finalGlob, { dot: true, cwd: directory, follow: true }).then((files: string[]) => {
+        glob(titleData.finalGlob, { dot: false, cwd: directory, follow: true }).then((files: string[]) => {
           resolve(this.extractTitles(titleData, directory, files));
         }).catch((err: string) => {
           reject(err);

updating glob-regex.parser.ts and glob.parser.ts in such a way should be sufficient for most use cases, but i believe updating other parsers could be beneficial as well.

further, a configuration option to switch this on and off would be ideal, but would require more development effort.

Discussion

  • is there a reason hidden files are explicitly included today? i haven't been following development so i'm not sure if this was an intentional design choice or not.
  • is it OK to ignore hidden files in ALL parsers? if not, which ones need to scan hidden files/directories?
  • where does winblows fit into this? the node libraries provide switches to exclude unix-style hidden files (files starting with .) but this isn't how windows handles hidden files. it is not clear whether or not these libraries are cross-platform in that regard.

bsdf avatar Nov 28 '23 16:11 bsdf

I keep my NSP tittle update and dlc in a subfolder in the rom folder. SRM picks those up as games. I sync everything to my deck with syncthing and I would love to just add a dot in the updates folder to exclude it from search. Please implement this feature even if its a toggle you have to activate manually in SRM settings.

Xarishark avatar Mar 07 '24 10:03 Xarishark

I don't see a reason why you need to use a hidden directory to have files be ignored, you could just put them in a subdirectory and have SRM's glob not parse subdirectories, or myriad other solutions. The issue with not matching .dot globs/minimatchs is that any ROMs starting starting with a period won't get parsed. Obviously this is a rare situation, but it would be a surprising undocumented behavior. Also as you say, dot files are not necessarily hidden on windows.

cbartondock avatar Apr 29 '24 23:04 cbartondock

adding a dot in front of the folder name is a MUCH easier and faster method to hardcode the behavior on the file level instead of the filter level. Also you can ignore only directories that have the dot instead of files or you can even add a toggle on the parser level to ignore dot directories. Is there a way to ignore the NSPs that are updates and not parse them as games?

Xarishark avatar May 11 '24 16:05 Xarishark