Discard configuration changes radio box not working

Wishlists for new functionality and features.
Post Reply
zeromido
Posts: 15
Joined: 26 Jul 2018 17:48

Discard configuration changes radio box not working

Post by zeromido »

In HxD Options, if you choose the Discard (= configuration is readonly) radio button, clicked OK, and exited the program,
HxD Hex Editor.ini won't have the read-only attribute.
However, if you chose the Preserve, then make configuration readonly radio button, the read-only attribute would be set to HxD Hex Editor.ini.

Steps to reproduce:
1. Start HxD v2.0.0.0.
2. Click Tools, then Options....
3. Choose the Discard (= configuration is readonly) radio button.
4. Click OK.
5. Exit HxD v2.0.0.0.
6. Locate HxD Hex Editor.ini in Settings folder.
7. Right-click HxD Hex Editor.ini and click Properties.
8. The read-only checkbox would be unchecked.

When fixing this, note that choosing Preserve clears the read-only attribute if it's been manually set to HxD Hex Editor.ini.
So, for the sake of consistency, choosing Discard (= configuration is readonly) should set the read-only attribute if it's been manually cleared.
In other words, make sure that HxD Hex Editor.ini attributes match the saved configuration every startup/exit.

P.S. If this is not a bug, and something is wrong with my computer (again :roll: ), I would delete my account here immediately :lol:
Maël
Site Admin
Posts: 1455
Joined: 12 Mar 2005 14:15

Re: Discard configuration changes radio box not working

Post by Maël »

Thanks for the report.

The logic of this function is a little tricky, and maybe the options need rewording. I remember I tried various formulations to express the intent clearly, but with some distance I see how " (= configuration is readonly) " can seem inconsistent.

The goal of discard is to not touch the ini file at all, because it should be the mode used when HxD is on a non-writeable media like a CD or a USB thumb drive with write protection. So that would also mean not touching the readonly file attribute.
When fixing this, note that choosing Preserve clears the read-only attribute if it's been manually set to HxD Hex Editor.ini.
This is intentional, Preserve is the default mode, where changes are written to the configuration file, and therefor cannot be readonly.

Maybe a better formulation would be "Discard (= treat configuration as readonly)", or "Discard (changes from current session)" (see post below for the why).

What do you think?

(Regarding your PS: your reports are welcome ;).
Maël
Site Admin
Posts: 1455
Joined: 12 Mar 2005 14:15

Re: Discard configuration changes radio box not working

Post by Maël »

I thought about it more and looked at the code again.

It writes a flag WriteProtected to the ini file. This is so that HxD can differentiate between intentional write protection and unintentional, and then report an error if it can't write to the file.
If you have a usb thumb drive and enable its write protection through a physical slider for example, it would be write protected, but the ini file should not become readonly because of that. So HxD would rightfully complain if it couldn't write to the file if it wasn't readonly but the thumb drive is write protected. A CD should always have all of its files set as readonly.
So both these cases should work fine when only relying on the readonly flag.

The reason was that sometimes file flags are a little fickle and may be changed by various programs along the way. I guess the WriteProtected flag in the ini file was to ensure there were no odd surprises.

So currently it sets the readonly flag only as a "bonus", but otherwise relies on the WriteProtected flag in the ini.

So far I see no reason why HxD should not merely rely on the readonly flag and there would be no need for a WriteProtected flag (except for dealing with misbehaving programs).

However, the "Discard (= configuration is readonly)" option has another purpose as well: Discard the changes from the current session and still not change if the ini file was writeprotected/readonly or not.

Summary
So, the conclusion would be that you could set/unset the readonly file attribute, and have HxD depend on that for treating a config as readonly or not. But the Discard option would still not set whether a config is readonly or not, because it should just discard changes made to the current session, but not alter whether the config is readonly in future or not.
If you want to set the readonly flag, you'd have to pick between preserve and preserve (set readonly).

Basically, the idea is to reduce the amount of possible options to a manageable one. But I see that it could be nicer to set the readonly flag using an additional discard option, instead of relying on Preserve (set readonly), because that would ensure you made no changes besides the readonly flag.
But that would mean a fourth option.

Maybe a fourth option would still make it the most clear, even if it seems a little redundant.
Maël
Site Admin
Posts: 1455
Joined: 12 Mar 2005 14:15

Re: Discard configuration changes radio box not working

Post by Maël »

I saw you replied to the other post, what is your opinion on this? I know the reply was long...
zeromido
Posts: 15
Joined: 26 Jul 2018 17:48

Re: Discard configuration changes radio box not working

Post by zeromido »

Sorry, it took me a while to grasp the concept of those options :)

The problem as I see it, is that setting the WriteProtected=1 flag in the ini makes HxD display Discard (= configuration is readonly) as the chosen radio button. But that's not accurate, because Discard (= configuration is readonly) discards changes only once i.e in the current session.

A workaround this is to add a fourth option, Discard future changes.
With some word changes, the options would be:
Preserve
Preserve once, and discard future changes
Discard future changes
Discard once

Another workaround, is to convert the radio buttons into checkboxes. That way, you won't need the Preserve option, since checkboxes are means to change the default behavior and unchecking them all would restore it.
Maël
Site Admin
Posts: 1455
Joined: 12 Mar 2005 14:15

Re: Discard configuration changes radio box not working

Post by Maël »

But that's not accurate, because Discard (= configuration is readonly) discards changes only once i.e in the current session.
Well, it will be discarded all the time as long as the option remains chosen, because indeed, the configuration was made readonly, and is treated as such until the option is changed again.

For example recent files, or any other option changes will remain temporary. Nothing is persisted to the configuration, as long as "Discard (= configuration is readonly)" remains chosen. This is also true if you end and restart HxD, so it remains true across sessions.

I'll think about the exact wording, but it seems a fourth option could disambiguate the choices better.

Thanks.
zeromido
Posts: 15
Joined: 26 Jul 2018 17:48

Re: Discard configuration changes radio box not working

Post by zeromido »

Good luck. And thank you for making HxD :)
Post Reply