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

Add options to reset session and plugin data when restoring defaults

This commit is contained in:
chylex 2017-08-29 14:28:33 +02:00
parent b515add94e
commit c28615d548
5 changed files with 53 additions and 12 deletions

View File

@ -12,6 +12,7 @@ static class Arguments{
// internal args
public const string ArgRestart = "-restart";
public const string ArgImportCookies = "-importcookies";
public const string ArgDeleteCookies = "-deletecookies";
public const string ArgUpdated = "-updated";
// class data and methods
@ -29,6 +30,7 @@ public static CommandLineArgs GetCurrentClean(){
CommandLineArgs args = Current.Clone();
args.RemoveFlag(ArgRestart);
args.RemoveFlag(ArgImportCookies);
args.RemoveFlag(ArgDeleteCookies);
args.RemoveFlag(ArgUpdated);
return args;
}

View File

@ -56,7 +56,7 @@ private void FormSettings_FormClosing(object sender, FormClosingEventArgs e){
private void btnManageOptions_Click(object sender, EventArgs e){
using(DialogSettingsManage dialog = new DialogSettingsManage(plugins)){
if (dialog.ShowDialog() == DialogResult.OK){
ShouldReloadBrowser = dialog.ShouldReloadUI;
ShouldReloadBrowser = dialog.ShouldReloadBrowser;
Close();
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Core.Other.Settings.Export;
@ -7,7 +8,7 @@
namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsManage : Form{
private enum State{
Deciding, Import, Export
Deciding, Reset, Import, Export
}
public ExportFileFlags Flags{
@ -21,7 +22,7 @@ public ExportFileFlags Flags{
}
}
public bool ShouldReloadUI { get; private set; }
public bool ShouldReloadBrowser { get; private set; }
private readonly PluginManager plugins;
private State currentState;
@ -59,15 +60,10 @@ private void btnContinue_Click(object sender, EventArgs e){
case State.Deciding:
// Reset
if (radioReset.Checked){
if (FormMessage.Warning("Reset TweetDuck Options", "This will reset all of your program options. Plugins will not be affected. Do you want to proceed?", FormMessage.Yes, FormMessage.No)){
Program.ResetConfig();
currentState = State.Reset;
ShouldReloadUI = true;
DialogResult = DialogResult.OK;
Close();
}
return;
Text = "Restore Defaults";
Flags = ExportFileFlags.Config;
}
// Import
@ -110,6 +106,33 @@ private void btnContinue_Click(object sender, EventArgs e){
panelExport.Visible = true;
break;
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.Config)){
Program.ResetConfig();
}
if (Flags.HasFlag(ExportFileFlags.PluginData)){
try{
Directory.Delete(Program.PluginDataPath, true);
}catch(Exception ex){
Program.Reporter.HandleException("Plugin Data Reset Error", "Could not delete plugin data.", true, ex);
}
}
if (Flags.HasFlag(ExportFileFlags.Session)){
Program.Restart(Arguments.ArgDeleteCookies);
}
else{
ShouldReloadBrowser = true;
}
DialogResult = DialogResult.OK;
Close();
}
break;
case State.Import:
if (importManager.Import(Flags)){
Program.ReloadConfig();
@ -118,7 +141,7 @@ private void btnContinue_Click(object sender, EventArgs e){
Program.Restart(Arguments.ArgImportCookies);
}
else{
ShouldReloadUI = true;
ShouldReloadBrowser = true;
}
}
else{
@ -171,6 +194,9 @@ private void SetFlag(ExportFileFlags flag, bool enable){
if (currentState == State.Import){
btnContinue.Text = selectedFlags.HasFlag(ExportFileFlags.Session) ? "Import && Restart" : "Import Profile";
}
else if (currentState == State.Reset){
btnContinue.Text = selectedFlags.HasFlag(ExportFileFlags.Session) ? "Restore && Restart" : "Restore Defaults";
}
}
}
}

View File

@ -161,6 +161,16 @@ public static void ImportCookies(){
}
}
public static void DeleteCookies(){
try{
if (File.Exists(CookiesPath)){
File.Delete(CookiesPath);
}
}catch(Exception e){
Program.Reporter.HandleException("Session Reset Error", "Could not remove the cookie file to reset the login session.", true, e);
}
}
private static IEnumerable<PathInfo> EnumerateFilesRelative(string root){
return Directory.Exists(root) ? Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories).Select(fullPath => new PathInfo{
Full = fullPath,

View File

@ -120,6 +120,9 @@ private static void Main(){
if (Arguments.HasFlag(Arguments.ArgImportCookies)){
ExportManager.ImportCookies();
}
else if (Arguments.HasFlag(Arguments.ArgDeleteCookies)){
ExportManager.DeleteCookies();
}
if (Arguments.HasFlag(Arguments.ArgUpdated)){
WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000);