Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Caedendi opened this issue Apr 9, 2024 · 3 comments
Closed

Comments

@Caedendi
Copy link

Caedendi commented Apr 9, 2024

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
Copy link
Owner

olegbl commented Apr 9, 2024

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
Copy link
Author

Caedendi commented Apr 9, 2024

So if I understand this correctly:

  • if no previous mod touches file A and I use D2RMM.readJson() on it, a duplicate of the original version will be saved
  • if a previous mod touches file A (either using only D2RMM.readJson() or in conjunction with D2RMM.writeJson(), thus adding a duplicate) and I use D2RMM.readJson() (not using D2RMM.writeJson()), nothing is changed?

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
Copy link
Owner

olegbl commented Apr 9, 2024

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:

  • If it already exists in the output directory, it will be read from there.
  • Otherwise, it will be extracted from the CASC archive, written to the output directory, and then used.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants