olegbl / d2rmm

Mod Manager for Diablo II: Resurrected
https://www.nexusmods.com/diablo2resurrected/mods/169
MIT License
54 stars 9 forks source link

Bug: readJson() saves the opened file, even when not using writeJson() #19

Closed Caedendi closed 1 month ago

Caedendi commented 3 months ago
let unused = D2RMM.readJson(`hd\\character\\npc\\act2guard2.json`);

let path = `hd\\character\\enemy\\act2hire.json`;
let file = D2RMM.readJson(path);

D2RMM.writeJson(path, file);

Expected behaviour: only act2hire.json is created. Actual behaviour: both files are created.

let unused = D2RMM.readJson(`hd\\character\\npc\\act2guard2.json`);

let path = `hd\\character\\enemy\\act2hire.json`;
let file = D2RMM.readJson(path);

// D2RMM.writeJson(path, file);

Expected behaviour: no files are created. Actual behaviour: both files are created.

olegbl commented 3 months ago

When D2RMM reads any file, it also immediately writes it to the output directory. This is basically a small performance optimization to prevent D2RMM from having to read the same file from the CASC archive (which is slower than reading a normal file from disk) over and over again when one file is used by a number of mods, but not modified.

Is there an issue you are running into with this behavior? i.e. Does the presence of the original file mess something up?

Caedendi commented 3 months ago

So if I understand this correctly:

If this is indeed true, then the presence of the file will not mess anything up, but its presence is confusing. If I don't modify a file, it should not be included in the generated mod. Can this be easily fixed without severely impacting performance?

Thanks for the quick reply and the clarification by the way, very much appreciated:)

olegbl commented 3 months ago

I'm unsure what you mean by duplicate, but I think you got the gist of it. :)

If you use D2RMM.readJson() on a file:

Can this be easily fixed without severely impacting performance?

Yup! I have on my mental todo list (which hopefully I get to one day...) to rework file writing a little bit anyway, and one of the things that I'd like to do is keep a record of which mods read/wrote which files during the install (primarily to use for some automated conflict detection). This would then also allow D2RMM to simply delete any unmodified/vanilla files at the end.