1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-13 17:34:08 +02:00

Refactor Program.ResetConfig & Program.RestartWithArgs

This commit is contained in:
chylex 2018-01-18 10:58:58 +01:00
parent 1a2b967749
commit b53c672768
3 changed files with 20 additions and 19 deletions
Configuration
Core/Other/Settings/Dialogs
Program.cs

View File

@ -174,6 +174,18 @@ public void Reload(){
}
}
public void Reset(){
try{
File.Delete(file);
File.Delete(GetBackupFile(file));
}catch(Exception e){
Program.Reporter.HandleException("Configuration Error", "Could not delete configuration files to reset the options.", true, e);
return;
}
Reload();
}
private void LoadInternal(bool backup){
Serializer.Read(backup ? GetBackupFile(file) : file, this);

View File

@ -109,7 +109,7 @@ private void btnContinue_Click(object sender, EventArgs e){
case State.Reset:
if (FormMessage.Warning("Reset TweetDuck Options", "This will reset the selected items. Are you sure you want to proceed?", FormMessage.Yes, FormMessage.No)){
if (Flags.HasFlag(ExportFileFlags.UserConfig)){
Program.ResetConfig();
Program.UserConfig.Reset();
}
if (Flags.HasFlag(ExportFileFlags.SystemConfig)){

View File

@ -192,18 +192,6 @@ private static string GetDataStoragePath(){
}
}
public static void ResetConfig(){
try{
File.Delete(UserConfigFilePath);
File.Delete(UserConfig.GetBackupFile(UserConfigFilePath));
}catch(Exception e){
Reporter.HandleException("Configuration Reset Error", "Could not delete configuration files to reset the options.", true, e);
return;
}
UserConfig.Reload();
}
public static void Restart(params string[] extraArgs){
CommandLineArgs args = Arguments.GetCurrentClean();
CommandLineArgs.ReadStringArray('-', extraArgs, args);
@ -211,13 +199,14 @@ public static void Restart(params string[] extraArgs){
}
public static void RestartWithArgs(CommandLineArgs args){
FormBrowser browserForm = Application.OpenForms.OfType<FormBrowser>().FirstOrDefault();
if (browserForm == null)return;
browserForm.ForceClose();
FormBrowser browserForm = FormManager.TryFind<FormBrowser>();
ExitCleanup();
RestartWithArgsInternal(args);
if (browserForm != null){
browserForm.ForceClose();
ExitCleanup();
RestartWithArgsInternal(args);
}
}
private static void RestartWithArgsInternal(CommandLineArgs args){