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

Upgrade to .NET Framework Settings System #114

Merged
merged 22 commits into from
Feb 4, 2024
Merged

Conversation

gbakeman
Copy link
Contributor

@gbakeman gbakeman commented Oct 21, 2023

The primary goal of this PR is to move WinNUT from the custom Registry preferences storage system, to the built-in .NET Framework Settings system. This should make adding or modifying settings easier, as well as migrating them between versions. It will also set the stage for upgrading WinNUT to the ClickOnce deployment scheme.

  • Created a form to prompt the user to upgrade their old preferences to the new system, and optionally remove the old set as well.
  • Decided to standardize on Windows XP-era icons throughout

Changes

  • Created specialized SerializedProtectedString for storing protected data (username, password) in the .Net Application Settings system
  • Removed code and references relating to old .INI Import system
  • Removed extraneous UPS code from Common library
  • Streamlined WinNUT_Params with OOP principles in mind, and intending for detect, read & total delete functionality only (no write)
  • Create additional migration helper class
  • Define Settings information, using well-defined object type information
  • Create a preferences upgrade/migration wizard dialog following a vague MVC/MVP design pattern and utilizing databindings and a backing model class. Import, Export (to .reg file) and Delete operations are implemented. Resources in need of translation have also been added
  • Test Import operation
  • Test Backup/Export operation
  • Test Delete operation
  • Ensure Settings save and load correctly

Closes #100

First iteration of the form, along with translation files (in need of translators!)
Also includes a new icon. I like the smooth gradient XP-style of the little orange guy carrying the electrical plug, so I'm standardizing around XP icons.
- Correcting PreRelease build config so that projects are building correctly as needed.
- Logger class handles its own directory since the Logging API provides default file locations.
- Removing global variables and logic relating to data paths since the only code that really used it was the Logger class.
- Specified output path for crashbugs.
- Simplified Logger initialization to be more predictable and utilize standard values and paths.
Creating application settings files for later integration.
Merging some changes from upstream, and some automatic VS changes as well.
@gbakeman gbakeman added the enhancement New feature or request label Oct 21, 2023
@gbakeman gbakeman self-assigned this Oct 21, 2023
@gbakeman gbakeman linked an issue Oct 21, 2023 that may be closed by this pull request
4 tasks
Upgraded the .NET Framework target version for both client projects. Specified default language, and removed unused settings from Client library.
Tweaking some types in the main Settings file. Adding new resource strings for UpgradePrefsDialog. Removing embedded binary data in main resources file.
Integrate UpgradePrefsDialog helper and Settings migration into WinNUT.

ApplicationEvents.vb
- Adjust Parameters/Settings portion of crash report generator to support the new Settings system.

MultilingualResources: Applied new resource strings, and removal of embedded binary data.

WinNUT.vb
- Replace parameter init code with new code to check for old preferences data and begin import procedure if necessary.
- Remove WinNUT 1.x INI import code

Added relevant helper code to Common library. Upgraded Client and main project .Net targets to 4.8.1.
- Refreshed .editorconfig, making sure the only copy is applied solution-wide (no significant changes were actually made to the file)
- Application.myapp definition file was automatically updated by the designer (no significant changes)
Removed extra .editorconfig file as well as leftover Ini importing code and duplicate UPS code, relocated prefs-related classes into their own folder & namespace, and moved the SerializedProtectedString file back into the main library/namespace.
- SerializedProtectedString: Standardized naming conventions w.r.t protection/encryption. Made two properties to help control serialization (fixes unprotected strings being written to the settings file), added cast operators, and a new constructor to also assist with serialization.
- WinNUT_Params: Cleaned up class structure, simplified params loading method, removed param saving method, created param export and deletion methods
- UpgradableParams: Corrected reference to Password property, removed public property for the old params, updated how old params are counted, created an upgrade worker arguments subclass.
- Renamed NUT_PasswordEnc setting to NUT_Password
- Created Model codefile for UpgradePrefsDialog. Move necessary bacing properties and bound them on the Form.
- Updated some strings concerning the form
- Added a regedit icon to represent the UpgradePrefsDialog wizard.
- Removed excess Imports
- Removed much of the logic out of UpgradePrefsDialog.vb and into the model. Also made small changes to the Form and resources.
- Removed extraneous WinNUT icon
- Some reorganization in WinNUT.vb; adding a Form event handling region, moving old preferences detection code into a later form event so the Form will appear with user-friendly log output displayed. Linked up manual upgrade launch command in the toolstrip menu. Also make sure settings are saved when preferences are changed.
- Updated data in Setup project file; updated icon reference, attempted to remove extra references again.
Reverting significant minimum requirements change that was not intended so casually. Also Visual Studio Designer slipping in a random tweak to one of its files.
Miscellaneous changes to Setup project file, and creation of a dedicated PreRelease configuration targeting it.
In the old Registry preferences storage system, the 'frequency in nominal' value was stored as an index of the `Cbx_Freq_Input` combobox control in the `Pref_Gui` preferences form. However, the new Settings system stores the frequency value literally. To work around this, we set the combobox selectedindex value to the first full match with the loaded Settings value. When saving, the value of the selecteditem is read directly into the Settings value.
Prevent auto update check from running before we've had a chance to import the preferences.
- Make sure the registry key root is opened as writable so delete procedure completes without error.
- Check for existing registry export file before exporting, to prevent reg.exe from hanging.
- Handle any errors produced by reg.exe.
- Corrected Icon property and binding (only using WinNUT icon, to avoid having to convert the registry graphic)
- Add reference to parent Form instance
- Initialize Form bindings
- Move save file dialog for capturing user location preference back into the UI thread.
- Support cancelling the background worker (although it should finish very quickly.)
- Remove debugging thread sleep statements.
- Better handling of upgrade worker completing, including if there was an error.
- Move most logic out of primary Form code file.
@gbakeman gbakeman changed the base branch from Dev-2.2 to dev-2.3 January 31, 2024 19:40
@gbakeman
Copy link
Contributor Author

Retargetting dev-2.3 branch

@gbakeman gbakeman marked this pull request as ready for review January 31, 2024 19:45
@gbakeman gbakeman added this to the 2.3 Stable Release milestone Jan 31, 2024
The input frequency calibration preference value used to be stored as the index value of the dropdown box in the preferences window; 0 for 50hz, and 1 for 60hz. The new settings system stores the value literally now, although the rest of WinNUT was not updated to reflect this change.

- WinNUT.vb now passes the Settings value directly to the `UPS_Device` constructor instead of converting it.
- UPS_Device.vb also refers to the value directly when getting parameter info from the UPS.
- Prefs upgrade import procedure now has an edge case to convert the old value to the new one.
@gbakeman gbakeman merged commit a2a439e into dev-2.3 Feb 4, 2024
1 check passed
@gbakeman gbakeman deleted the 100-new-settings branch February 4, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transfer settings from Windows Registry to .NET Application Settings
1 participant