Closed CrimsonEdgeHope closed 1 year ago
emm One more thing.. Have you tried the backup mechanism? I was rolling out tests and found that the backup gets overwritten. I purposefully edited the json into a wrong format. It should backup the bad config with useful values however I see an empty one with all three hashes in 0 instead...
There is a problem invoking the backup method, sad losing my config values :(
When it comes to if (!Arrays.equals(Waila.BLACKLIST_CONFIG.get().pluginHash, hash))
, inside read
method in ConfigIO
class, only when no IOException, all correct json format, and matching config version will set init = false
and will not invoke config = factory.get();
If config = factory.get();
, an empty set of blacklist config is returned.
if (init) {
versionSetter.accept(config, currentVersion);
write(path, config);
}
After this, an empty json will appear. Before this, a backup operation should be already done (except the scenario where json doesn't exist) unless it comes to init = false;
.
That change (https://github.com/badasintended/wthit/pull/216/commits/257caa5bf886d00c61bdef1d193408d1c32f7f14) literally didn't make any change. ConfigIO#read
itself checks the json's existence as well. Thus, at the end of ConfigIO#read
, blacklist.json
will come to existence for sure, regardless of what scenario at beginning.
Try this one (https://github.com/badasintended/wthit/pull/216/commits/e4e586e0626bd04aabea890f19ed354980ef3811) it should do the trick.
I think deleting the following block is enough:
if (Waila.BLACKLIST_CONFIG.isFileExists()) {
Waila.BLACKLIST_CONFIG.backup();
}
When the json doesn't exist, ofc no backup. But when it does exist, unless the json format is correct, all hashes and configversion match, backup shall be done only once for sure. Invoking backup
another time in lock
is actually backing up the empty json.
The DATE_FORMAT
uses "yyyy.MM.dd.HH.mm.ss", which brings a great chance of overwritting the backup with the same file name.
Hmm, this became a more complicated problem than I anticipated 😅 .
The current solution is not ideal as that would make the config lost and not backuped when the hash changes. I think it would need a marker property inside the json itself to mark whether it is empty because no blacklist from plugin or because of user.
OR, just simply skip the backup if the current config hash is [0, 0, 0]
, as the plugin hash would never be [0, 0, 0]
in runtime anyway.
I think it works now, please test it on your end.
Yeah it looks the magic works now, awesome! (Minecraft Fabric 1.20.1)
Previously on https://github.com/badasintended/wthit/pull/215
https://github.com/badasintended/wthit/pull/215#issuecomment-1605381094
So, it's mentioned that the plugin is supposed to be reset config when the hash value mismatch, otherwise keep using the config value and don't change. However, in
Registrar
enum class, after invokingaddBlacklist
inWailaPluginVanilla
that adds values toblacklist
field declared inRegistrar
, all the values are written toblacklist.json
without further checking, right inlock
method. This results in any default value that is removed fromblacklist.json
being re-added upon every time launching game.(The
Registrar
: https://github.com/badasintended/wthit/blob/22fcc2b4224a0df185acdc11cbb263aacd81c253/src/main/java/mcp/mobius/waila/registry/Registrar.java)Note, under my circumstance, I want to remove barrier block from
blacklist.json
once for allFirst:
When it comes to this piece of code, there are already default blacklist values added in
blacklist
field. I get the following hash seen inblacklist.json
:Second:
This is exactly what the if statement does.
Third:
During my manual test process, If I purposefully edit the hash value in the json to a wrong one, it's definitely going to trigger a backup operation. But this is the only thing to be done under the if statement. Right after this, all the blacklist values in
blacklist
field previously added by invokingaddBlacklist
inWailaPluginVanilla
are all added without checking, including BARRIER block. As a consequence, my own setting that removes barrier block from blacklist gets reverted.I think the hash-value mechanism is just to write a set of default values when creating the json.
Later on I make a small change in
Registrar
enum class, so when it comes tolock
method, first it would compare the hash value. It's notable that if the json doesn't exist at first, invokingWaila.BLACKLIST_CONFIG.get()
will lead to the creation of an emptyblacklist.json
, where all the three blacklist setting arrays are empty, and all the hashes are same 0. TheConfigIO
does the work, when invokingIJsonConfig#get
without the json's existence,config = factory.get()
inConfigIO#read
returns an empty set of blacklist config,boolean init
remainstrue
and finallyif (init)
is true so an emptyblacklist.json
gets written. The emptyblacklist.json
is read,Waila.BLACKLIST_CONFIG.get()
returns a new instance ofBlacklistConfig
, thepluginHash
are all 0 which does not equal to1510828157, 0, -846312502
.if (!Arrays.equals(Waila.BLACKLIST_CONFIG.get().pluginHash, hash))
becomes true. Because the empty json gets written first,Waila.BLACKLIST_CONFIG.isFileExists()
is true thus the backup operation will be triggered, leaving an empty backup.newBlacklist
points to the loaded reference, adding values and invokingsave
will perfectly save default values.Now using this patch I rolled out some manual tests. I can see my own settings get preserved. Easy fix!
Please see if I had messed up with anything.