mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-23 12:15:48 +02:00
Implement system config export/import/reset (without UI)
This commit is contained in:
parent
be08fd4445
commit
6df68629f7
Core/Other/Settings
@ -16,7 +16,7 @@ public ExportFileFlags Flags{
|
||||
|
||||
set{
|
||||
// this will call events and SetFlag, which also updates the UI
|
||||
cbConfig.Checked = value.HasFlag(ExportFileFlags.Config);
|
||||
cbConfig.Checked = value.HasFlag(ExportFileFlags.UserConfig);
|
||||
cbSession.Checked = value.HasFlag(ExportFileFlags.Session);
|
||||
cbPluginData.Checked = value.HasFlag(ExportFileFlags.PluginData);
|
||||
}
|
||||
@ -42,7 +42,7 @@ private void radioDecision_CheckedChanged(object sender, EventArgs e){
|
||||
}
|
||||
|
||||
private void cbConfig_CheckedChanged(object sender, EventArgs e){
|
||||
SetFlag(ExportFileFlags.Config, cbConfig.Checked);
|
||||
SetFlag(ExportFileFlags.UserConfig, cbConfig.Checked);
|
||||
}
|
||||
|
||||
private void cbSession_CheckedChanged(object sender, EventArgs e){
|
||||
@ -63,7 +63,7 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
currentState = State.Reset;
|
||||
|
||||
Text = "Restore Defaults";
|
||||
Flags = ExportFileFlags.Config;
|
||||
Flags = ExportFileFlags.UserConfig;
|
||||
}
|
||||
|
||||
// Import
|
||||
@ -108,10 +108,18 @@ 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.Config)){
|
||||
if (Flags.HasFlag(ExportFileFlags.UserConfig)){
|
||||
Program.ResetConfig();
|
||||
}
|
||||
|
||||
if (Flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||
try{
|
||||
File.Delete(Program.SystemConfigFilePath);
|
||||
}catch(Exception ex){
|
||||
Program.Reporter.HandleException("System Config Reset Error", "Could not delete system config.", true, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (Flags.HasFlag(ExportFileFlags.PluginData)){
|
||||
try{
|
||||
File.Delete(Program.PluginConfigFilePath);
|
||||
@ -124,6 +132,9 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
if (Flags.HasFlag(ExportFileFlags.Session)){
|
||||
Program.Restart(Arguments.ArgDeleteCookies);
|
||||
}
|
||||
else if (Flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||
Program.Restart();
|
||||
}
|
||||
else{
|
||||
ShouldReloadBrowser = true;
|
||||
}
|
||||
@ -139,7 +150,12 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
Program.UserConfig.Reload();
|
||||
|
||||
if (importManager.IsRestarting){
|
||||
Program.Restart(Arguments.ArgImportCookies);
|
||||
if (Flags.HasFlag(ExportFileFlags.Session)){
|
||||
Program.Restart(Arguments.ArgImportCookies);
|
||||
}
|
||||
else if (Flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||
Program.Restart();
|
||||
}
|
||||
}
|
||||
else{
|
||||
ShouldReloadBrowser = true;
|
||||
@ -171,6 +187,8 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
}
|
||||
|
||||
Program.UserConfig.Save();
|
||||
Program.SystemConfig.Save();
|
||||
|
||||
ExportManager manager = new ExportManager(file, plugins);
|
||||
|
||||
if (!manager.Export(Flags)){
|
||||
|
@ -4,9 +4,10 @@ namespace TweetDuck.Core.Other.Settings.Export{
|
||||
[Flags]
|
||||
enum ExportFileFlags{
|
||||
None = 0,
|
||||
Config = 1,
|
||||
Session = 2,
|
||||
PluginData = 4,
|
||||
All = Config|Session|PluginData
|
||||
UserConfig = 1,
|
||||
SystemConfig = 2,
|
||||
Session = 4,
|
||||
PluginData = 8,
|
||||
All = UserConfig|SystemConfig|Session|PluginData
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,14 @@ public ExportManager(string file, PluginManager plugins){
|
||||
public bool Export(ExportFileFlags flags){
|
||||
try{
|
||||
using(CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))){
|
||||
if (flags.HasFlag(ExportFileFlags.Config)){
|
||||
if (flags.HasFlag(ExportFileFlags.UserConfig)){
|
||||
stream.WriteFile("config", Program.UserConfigFilePath);
|
||||
}
|
||||
|
||||
if (flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||
stream.WriteFile("system", Program.SystemConfigFilePath);
|
||||
}
|
||||
|
||||
if (flags.HasFlag(ExportFileFlags.PluginData)){
|
||||
stream.WriteFile("plugin.config", Program.PluginConfigFilePath);
|
||||
|
||||
@ -67,7 +71,11 @@ public ExportFileFlags GetImportFlags(){
|
||||
while((key = stream.SkipFile()) != null){
|
||||
switch(key){
|
||||
case "config":
|
||||
flags |= ExportFileFlags.Config;
|
||||
flags |= ExportFileFlags.UserConfig;
|
||||
break;
|
||||
|
||||
case "system":
|
||||
flags |= ExportFileFlags.SystemConfig;
|
||||
break;
|
||||
|
||||
case "plugin.config":
|
||||
@ -99,12 +107,20 @@ public bool Import(ExportFileFlags flags){
|
||||
while((entry = stream.ReadFile()) != null){
|
||||
switch(entry.KeyName){
|
||||
case "config":
|
||||
if (flags.HasFlag(ExportFileFlags.Config)){
|
||||
if (flags.HasFlag(ExportFileFlags.UserConfig)){
|
||||
entry.WriteToFile(Program.UserConfigFilePath);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "system":
|
||||
if (flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||
entry.WriteToFile(Program.SystemConfigFilePath);
|
||||
IsRestarting = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "plugin.config":
|
||||
if (flags.HasFlag(ExportFileFlags.PluginData)){
|
||||
entry.WriteToFile(Program.PluginConfigFilePath);
|
||||
|
Loading…
Reference in New Issue
Block a user