add try catch load settings
This commit is contained in:
@@ -31,12 +31,21 @@ namespace SafeBagDE70.Admin
|
||||
public AdminSettingsUC()
|
||||
{
|
||||
InitializeComponent();
|
||||
try
|
||||
{
|
||||
LoadStartupSetting();
|
||||
timePicker.SelectedTime = Properties.Settings.Default.RestartTime;
|
||||
SetupAutoRestart();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Log.Fatal(ex, "AdminSettingsUC");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoadStartupSetting()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open the registry key for the current user's startup applications
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", false);
|
||||
@@ -50,6 +59,12 @@ namespace SafeBagDE70.Admin
|
||||
cbStartWithWindows.IsChecked = value != null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "LoadStartupSetting");
|
||||
}
|
||||
|
||||
}
|
||||
private void cbStartWithWindows_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Add the app to startup when the checkbox is checked
|
||||
@@ -63,6 +78,8 @@ namespace SafeBagDE70.Admin
|
||||
}
|
||||
|
||||
private void AddApplicationToStartup()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the path to the executable
|
||||
string exePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
@@ -76,6 +93,12 @@ namespace SafeBagDE70.Admin
|
||||
key.SetValue(appName, exePath);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "AddApplicationToStartup");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void RemoveApplicationFromStartup()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user