Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: File miscapitalization detector -- cross platform mods FTW  (Read 2460 times)

Garmine

  • Lieutenant
  • **
  • Posts: 97
  • We're The Borg. Every resistance is futile.
    • View Profile
File miscapitalization detector -- cross platform mods FTW
« on: December 08, 2015, 04:23:30 AM »

Hi!

TL;DR : I'm working on a file capitaliztaion VS file reference capitalization checker tool. Where should I look for a mod's stored references (e.g. filename strings in code) to compare them to the actual filename recorded on the file system?

---

Every time I try to play StarSector with many mods I spend a few hours just debugging case mismatches between the file system and the mods' code - e.g. "starsector/mods/mod/somedir/image.PNG" referenced as "somedir/iMage.png". This is not a problem on any Windows as the OS ignores file case BUT NTFS does store filename entires with case. Thus the mods' uploaded zip archives contain the file path+name and the reference with different cases. Linux and UNIXes are on the other hand do not ignore case mismatches causing a few errors during startup.

As I see many modders use Windows and many mods/Linux users suffer from the above issue.

I'd like to implement a tool (in Java with both a GUI and CLI) to automatically check for these issues before running Starsector and waiting for long long times between each detected mismatch. So far I have seen mismatches on image files and maybe even on a .java source file. Where shall I look for these files/which files can be affected by this and where shall I look for references to these files?

@Alex : maybe enforcing case matches in StarSector file access routines OR including some checking+warning toggleable dev tool would help a lot to Linux folks like myself in the future :)

I might be wrong on that Java is capable to read back the file name case-correctly, in which case I'm sorry for the technical inaccuracy in my post! (And am gonna use C++ in my project in this case.)

Also sorry for not RTFMing, but as this is quite a meta-modding question I think it'll be faster and more accurate to rely on modders' experiences regarding this.

Thank you for the help in advance!

Regards,
Garmine
Logged
I went outside one day, the graphics were amazing, but the gameplay sucked...
Prepare yourselves for miscapitalization errors! *evil laugh*

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: File miscapitalization detector -- cross platform mods FTW
« Reply #1 on: December 08, 2015, 04:54:32 AM »

Obtaining the actual file name is possible in Java.

Pre-1.8, File.getCanonicalFile()
Post-1.8, Path.toRealPath(...)

As for determining what needs renaming, you'd have to parse the various Java source and Starsector json/CSV files that the mod contained. (Performing this statically is more complicated than it sounds if you want to account for dynamically constructed resource names; e.g. "Image"+i+".png")

It'd be easiest (and most flexible) to achieve with an SSME mod, as you'd be able to inject the necessary checks into SS's resource loading methods. Though ultimately such a fix would be best implemented by Alex in the SS source base itself.

(Or for mod makers to be more careful with their cases, and follow Java's standard naming conventions!)
« Last Edit: December 08, 2015, 05:00:39 AM by TJJ »
Logged

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2806
    • View Profile
    • Sc2Mafia
Re: File miscapitalization detector -- cross platform mods FTW
« Reply #2 on: December 08, 2015, 09:29:53 AM »

The "Image"+i+".png" case is not common, and unlikely to be miscapitalized in the first place.  A checker could just scan all the files in a directory, add them to a name dictionary, and then search for (non-case-sensitive) matches throughout all the files' content.  For each match, it would then see if the case matches; otherwise, display a warning.

The fun part is making it not O(n^2).
Logged

Garmine

  • Lieutenant
  • **
  • Posts: 97
  • We're The Borg. Every resistance is futile.
    • View Profile
Re: File miscapitalization detector -- cross platform mods FTW
« Reply #3 on: December 08, 2015, 09:46:44 AM »

The fun part is making it not O(n^2).

That's why I asked you, guys :)

I have near 0 experience regarding SS modding, so I don't know where shall I look for files found in different folders of a mod. Heck, I don't even know for sure which files are referenced by the mod itself usually :)

E.g. I guess it's unneccessary to check for 'mod_info.json' being correct. But what about .java .jar or similars? I think I found a miscapitalized .java file once.

Edit: Obviusly files can not be referenced by image files, audio files, etc. So it's not o(n^2), but still quite suboptimal. Thus the needed information is: which files can reference which types of files? If I really want to optimize I can even filter by which files usually reference which types of files.
« Last Edit: December 08, 2015, 10:03:20 AM by Garmine »
Logged
I went outside one day, the graphics were amazing, but the gameplay sucked...
Prepare yourselves for miscapitalization errors! *evil laugh*

Zaphide

  • Admiral
  • *****
  • Posts: 799
    • View Profile
Re: File miscapitalization detector -- cross platform mods FTW
« Reply #4 on: December 08, 2015, 02:53:14 PM »

The following files will have path strings:
 - .csv
 - .json
 - .ship
 - .skin
 - .wpn
 - .proj
 - .faction

Maybe just total all the paths up from those (and remove duplicates) and check if the file exists?

I guess theoretically there could also be hard-coded links in code files (i.e. pulling in specific settings for a mod) but I'm not sure if that might require the case to be correct, even on Windows? Regardless, such a file could be in a .jar so probably not worth worrying about.
Logged