Esempio n. 1
0
        public ExportFileFlags GetImportFlags()
        {
            ExportFileFlags flags = ExportFileFlags.None;

            try{
                using (CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None))){
                    string key;

                    while ((key = stream.SkipFile()) != null)
                    {
                        switch (key)
                        {
                        case "config":
                            flags |= ExportFileFlags.Config;
                            break;

                        case "plugin.config":
                        case "plugin.data":
                            flags |= ExportFileFlags.PluginData;
                            break;

                        case "cookies":
                            flags |= ExportFileFlags.Session;
                            break;
                        }
                    }
                }
            }catch (Exception e) {
                LastException = e;
                flags         = ExportFileFlags.None;
            }

            return(flags);
        }
        private void SetFlag(ExportFileFlags flag, bool enable)
        {
            selectedFlags    = enable ? selectedFlags | flag : selectedFlags & ~flag;
            btnApply.Enabled = selectedFlags != ExportFileFlags.None;

            if (!isExporting)
            {
                btnApply.Text = selectedFlags.HasFlag(ExportFileFlags.Session) ? "Import && Restart" : "Import Profile";
            }
        }
Esempio n. 3
0
        public bool Export(ExportFileFlags flags)
        {
            try{
                using (CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))){
                    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);

                        foreach (Plugin plugin in plugins.Plugins)
                        {
                            foreach (PathInfo path in EnumerateFilesRelative(plugin.GetPluginFolder(PluginFolder.Data)))
                            {
                                try{
                                    stream.WriteFile(new string[] { "plugin.data", plugin.Identifier, path.Relative }, path.Full);
                                }catch (ArgumentOutOfRangeException e) {
                                    FormMessage.Warning("Export Profile", "Could not include a plugin file in the export. " + e.Message, FormMessage.OK);
                                }
                            }
                        }
                    }

                    if (flags.HasFlag(ExportFileFlags.Session))
                    {
                        stream.WriteFile("cookies", CookiesPath);
                    }

                    stream.Flush();
                }

                return(true);
            }catch (Exception e) {
                LastException = e;
                return(false);
            }
        }
        private DialogSettingsExport(ExportFileFlags importFlags)
        {
            InitializeComponent();

            this.isExporting = importFlags == ExportFileFlags.None;

            if (isExporting)
            {
                Text          = "Export Profile";
                btnApply.Text = "Export Profile";
                Flags         = ExportFileFlags.All & ~ExportFileFlags.Session;
            }
            else
            {
                Text  = "Import Profile";
                Flags = importFlags;

                cbConfig.Enabled     = cbConfig.Checked;
                cbSession.Enabled    = cbSession.Checked;
                cbPluginData.Enabled = cbPluginData.Checked;
            }
        }
 public static DialogSettingsExport Import(ExportFileFlags flags)
 {
     return(new DialogSettingsExport(flags));
 }
Esempio n. 6
0
        public bool Import(ExportFileFlags flags)
        {
            try{
                HashSet <string> missingPlugins = new HashSet <string>();

                using (CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None))){
                    CombinedFileStream.Entry entry;

                    while ((entry = stream.ReadFile()) != null)
                    {
                        switch (entry.KeyName)
                        {
                        case "config":
                            if (flags.HasFlag(ExportFileFlags.Config))
                            {
                                entry.WriteToFile(Program.ConfigFilePath);
                            }

                            break;

                        case "plugin.config":
                            if (flags.HasFlag(ExportFileFlags.PluginData))
                            {
                                entry.WriteToFile(Program.PluginConfigFilePath);
                            }

                            break;

                        case "plugin.data":
                            if (flags.HasFlag(ExportFileFlags.PluginData))
                            {
                                string[] value = entry.KeyValue;

                                entry.WriteToFile(Path.Combine(Program.PluginDataPath, value[0], value[1]), true);

                                if (!plugins.IsPluginInstalled(value[0]))
                                {
                                    missingPlugins.Add(value[0]);
                                }
                            }

                            break;

                        case "cookies":
                            if (flags.HasFlag(ExportFileFlags.Session))
                            {
                                entry.WriteToFile(Path.Combine(Program.StoragePath, TempCookiesPath));
                                IsRestarting = true;
                            }

                            break;
                        }
                    }
                }

                if (missingPlugins.Count > 0)
                {
                    MessageBox.Show("Detected missing plugins when importing plugin data:" + Environment.NewLine + string.Join(Environment.NewLine, missingPlugins), "Importing " + Program.BrandName + " Profile", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                if (IsRestarting)
                {
                    Program.Restart(new string[] { Arguments.ArgImportCookies });
                }
                else
                {
                    Program.ReloadConfig();
                }

                return(true);
            }catch (Exception e) {
                LastException = e;
                return(false);
            }
        }
Esempio n. 7
0
        public bool Import(ExportFileFlags flags)
        {
            try{
                HashSet <string> missingPlugins = new HashSet <string>();

                using (CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None))){
                    CombinedFileStream.Entry entry;

                    while ((entry = stream.ReadFile()) != null)
                    {
                        switch (entry.KeyName)
                        {
                        case "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);
                            }

                            break;

                        case "plugin.data":
                            if (flags.HasFlag(ExportFileFlags.PluginData))
                            {
                                string[] value = entry.KeyValue;

                                entry.WriteToFile(Path.Combine(Program.PluginDataPath, value[0], value[1]), true);

                                if (!plugins.IsPluginInstalled(value[0]))
                                {
                                    missingPlugins.Add(value[0]);
                                }
                            }

                            break;

                        case "cookies":
                            if (flags.HasFlag(ExportFileFlags.Session))
                            {
                                entry.WriteToFile(Path.Combine(Program.StoragePath, TempCookiesPath));
                                IsRestarting = true;
                            }

                            break;
                        }
                    }
                }

                if (missingPlugins.Count > 0)
                {
                    FormMessage.Information("Importing TweetDuck Profile", "Detected missing plugins when importing plugin data:\n" + string.Join("\n", missingPlugins), FormMessage.OK);
                }

                return(true);
            }catch (Exception e) {
                LastException = e;
                return(false);
            }
        }