-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Hosts] Backup Settings #37778
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
base: main
Are you sure you want to change the base?
[Hosts] Backup Settings #37778
Conversation
I suggest as we have the on/of checkbox for cleanup to set the number boxes to min=1. |
The idea is that user can configure retention by:
In case both are set to 0 the warning is displayed and no backups are deleted. Do you think this makes sense? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some ui nits
These all feels to complicated. I think keep it simple is the way to go. And simple for me is:
|
I started with this idea, but #37666 (comment) made me change it.
But I am happy to have a feedback on this. |
Okay. But then lets allow the following logic: Remove backups older x days (x = setting >= 1) and hard coded keep always 1 backup. The if-else-else solution is to complicated. We can add a description to cleanup checkbox that at least one backup is always kept regardless of its age. |
I need to think about this: the idea around the PR is to remove any hardcoded/hidden logic related to backups. |
The point that we have multiple ways of doing it which influence each other. And that you can configure it to not clean up even that zhe clean up is enabled. |
@htcfreek any thoughts on this UX?
|
@davidegiacometti With zero as date or time all backups will be deleted on the |
The backups cleanup is always executed on editor startup. These options are used to determine for how many days backups are kept or/and how many fixed backups are kept. |
Yes. What I mean is: It makes a difference with 0 days if I start Hosts multiple times per day or not. And for me keeping 0 days means deleting at the day of creating and not keeping indefinitely. That is confusing. |
I think the drop downs are limiting.. 🤔 |
Hey @htcfreek Can I have a feedback on these mocks? ![]() ![]() ![]() Let me know if you think this solution is clear. If your answer is positive I am going to reopen this PR and tweak the implementation. |
Two suggestions:
Can't follow you. There are only these two number boxes in the screenshots. Are there any screenshots missing? And I still see see the problem that 0 means nothing. So we should explain the meaning of 0 in the number box description. |
Ok for the suggestions. Please see the update screenshot. |
Sory. My mistake. Was confused after all the solutions we discussed. |
Yes. It is clear. Let's implement that solution. |
Thanks for the feedback.. And I like this solution! |
Addressed the last feedback and updated the screenshot in the first post. |
a9c52d1
to
011f108
Compare
011f108
to
897277c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds customizable backup settings for the Hosts File Editor, replacing hardcoded backup logic with configurable settings and integrating backup creation/deletion into the Hosts service. Key changes include:
- Implementation of a BackupManager with configurable backup creation and deletion modes.
- Updates to Hosts settings, view models, and properties to expose backup-related configuration.
- Addition of tests and adjustments to the HostsService to integrate the new backup manager functionality.
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/modules/Hosts/HostsUILib/Helpers/BackupManager.cs | Introduces backup creation and deletion logic with new settings support. |
src/modules/Hosts/Hosts.Tests/BackupManagerTest.cs | Adds tests for verifying backup creation and deletion behavior. |
src/settings-ui/Settings.UI.Library/Enumerations/HostsDeleteBackupMode.cs | Provides new enumeration for backup deletion modes. |
src/modules/Hosts/HostsUILib/Settings/HostsDeleteBackupMode.cs | Mirrors the new backup deletion mode enumeration for Hosts. |
src/modules/Hosts/HostsUILib/Helpers/IBackupManager.cs | Defines the new IBackupManager interface. |
src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs | Adds new properties and a method to select a backup path. |
src/modules/Hosts/Hosts/Settings/UserSettings.cs | Updates default values and JSON loading to include backup settings. |
src/settings-ui/Settings.UI.Library/HostsProperties.cs | Adds backup settings default values and properties. |
src/modules/Hosts/HostsUILib/Settings/IUserSettings.cs | Extends the user settings interface with backup-related properties. |
src/modules/Hosts/Hosts/HostsXAML/App.xaml.cs | Registers the BackupManager and invokes backup deletion on startup. |
src/settings-ui/Settings.UI/SettingsXAML/Views/HostsPage.xaml.cs | Updates UI strings for backup settings. |
src/modules/Hosts/HostsUILib/Helpers/HostsService.cs | Integrates the new BackupManager in place of previous backup logic. |
src/modules/Hosts/Hosts.FuzzTests/FuzzTests.cs, src/modules/Hosts/Hosts.Tests/HostsServiceTest.cs | Adjusts tests to work with the new backup manager integration. |
@@ -54,6 +65,11 @@ public UserSettings() | |||
LoopbackDuplicates = false; | |||
AdditionalLinesPosition = HostsAdditionalLinesPosition.Top; | |||
Encoding = HostsEncoding.Utf8; | |||
BackupHosts = true; | |||
BackupPath = @"C:\Windows\system32\drivers\etc"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would that be better if change to Environment.GetEnvironmentVariable("windir")?
https://learn.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable?view=net-9.0&redirectedfrom=MSDN#System_Environment_GetEnvironmentVariable_System_String_
then fall back to hard-code string as needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
I used the same logic we are using for the hosts file path: no issues so far, so I think a fallback isn't needed.
_hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"System32\drivers\etc\hosts"); |
return; | ||
} | ||
|
||
if (!_fileSystem.Directory.Exists(_userSettings.BackupPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest move to try-catch block below, in case if CreateDirectory failed (e.g.: due to permission). otherwise, unhandled exception may cause hosts crash.
public HostsProperties() | ||
{ | ||
ShowStartupWarning = true; | ||
LaunchAdministrator = true; | ||
LoopbackDuplicates = false; | ||
AdditionalLinesPosition = HostsAdditionalLinesPosition.Top; | ||
Encoding = HostsEncoding.Utf8; | ||
BackupHosts = true; | ||
BackupPath = @"C:\Windows\System32\drivers\etc"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, try get from EnviromentVariable?
public HostsProperties() | ||
{ | ||
ShowStartupWarning = true; | ||
LaunchAdministrator = true; | ||
LoopbackDuplicates = false; | ||
AdditionalLinesPosition = HostsAdditionalLinesPosition.Top; | ||
Encoding = HostsEncoding.Utf8; | ||
BackupHosts = true; | ||
BackupPath = @"C:\Windows\System32\drivers\etc"; | ||
DeleteBackupsMode = HostsDeleteBackupMode.Age; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[non-blocking-comment] it seems initialization code are dup in both Hosts (src/modules/Hosts/Hosts/Settings/UserSettings.cs) & Settings.UI.Library
is that possible to have one ?
{ | ||
public interface IBackupManager | ||
{ | ||
void CreateBackup(string hostsFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[non-blocking-comment] suggest change to Create, Delete.
similar naming pattern as File.Create (https://learn.microsoft.com/en-us/dotnet/api/system.io.file.create?view=net-9.0)
my bad, forgot to click 'Submit' to save my review comments. apology for the delay... :( |
73b0562
to
5d2f3c7
Compare
Don't worry and thanks for the review. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
5d2f3c7
to
1a37664
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Summary of the Pull Request
Add backup settings for the Hosts File Editor to allow users to customize the existing hardcoded logic.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed