Exemplo n.º 1
0
        public void Start(BackUpSettings settings)
        {
            this.settings       = settings;
            this.overwriteState = settings.DefaultOverwriteState;
            this.skipState      = settings.DefaultSkipState;

            if (!Directory.Exists(settings.TargetDirectory))
            {
                throw new DirectoryNotFoundException("Target Directory Non-existent");
            }

            // Filters all non-existing directories from the origin.
            foreach (string dir in settings.OriginDirectories)
            {
                if (!Directory.Exists(dir))
                {
                    throw new DirectoryNotFoundException("Origin Directory Non-Existent");
                }
            }

            // TODO: when two origin folders have the same name all non-first ones are removed here because the names don't match the original.

            RemoveAbandonedFiles();
            CreateBackUp();
        }
Exemplo n.º 2
0
        private void InitializeWithDefaultValues(BackUpSettings settings)
        {
            textBox1.Text = settings.TargetDirectory;
            foreach (string path in settings.OriginDirectories)
            {
                richTextBox1.Text += path + '\n';
            }

            if (settings.DefaultOverwriteState == ActionState.Yes)
            {
                radioButton1.Checked = true;
            }
            else if (settings.DefaultOverwriteState == ActionState.No)
            {
                radioButton2.Checked = true;
            }
            else
            {
                radioButton3.Checked = true;
            }

            if (settings.DefaultSkipState == ActionState.Yes)
            {
                radioButton4.Checked = true;
            }
            else if (settings.DefaultSkipState == ActionState.No)
            {
                radioButton5.Checked = true;
            }
            else
            {
                radioButton6.Checked = true;
            }
        }
Exemplo n.º 3
0
        public Form1(BackUpSettings settings)
        {
            InitializeComponent();

            if (settings != null)
            {
                InitializeWithDefaultValues(settings);
            }
        }
Exemplo n.º 4
0
        public static string Save(BackUpSettings settings, string name)
        {
            string json = JsonUtility.ToJson(settings);

            name = Path.Combine(SettingsPath, name);
            name = Path.ChangeExtension(name, "json");

            File.WriteAllText(name, json);

            return(name);
        }
        private void StartBackUp(string userSettings)
        {
            LoadBackingUpMenu();

            backUpThread = new Thread(() =>
            {
                LoggingUtilities.SetAppDataRoot(AppDataRoot);
                try
                {
                    LoadingIcon();
                    LoggingUtilities.LogFormat("\nInitiating Simple Back-Up ({0})\n", DateTime.Now.ToString());

                    BackUpSettings loadedSettings = settings.Load(userSettings);

                    backUp = new BackUp();
                    backUp.Start(loadedSettings);
                }
                catch (Exception ex)
                {
                    LoggingUtilities.Log("ERROR\n");
                    LoggingUtilities.Log(ex.StackTrace + "\n");
                    LoggingUtilities.Log(ex.Message + "\n");
                    LoggingUtilities.Log(ex.Data.ToString() + "\n");

                    Console.Beep(200, 500);
                    Console.Beep(200, 500);
                    Console.Beep(200, 500);
                }
                finally
                {
                    if (loadIconThread != null)
                    {
                        loadIconThread.Abort();
                        loadIconThread = null;
                        trayIcon.Icon  = Resources.AppIcon;
                    }

                    Reloadmenu();

                    Console.Beep(400, 500);
                    LoggingUtilities.LogFormat("Finished AFB ({0})\n", DateTime.Now.ToString());
                }
            });

            backUpThread.Start();
        }
Exemplo n.º 6
0
        private void button3_Click(object sender, EventArgs e)
        {
            string name = textBox2.Text;

            string targetPath = textBox1.Text;

            string[] originPaths = richTextBox1.Text.Split('\n');

            ActionState overwriteState = radioButton1.Checked
                                ? ActionState.Yes
                                : radioButton2.Checked
                                        ? ActionState.No
                                        : ActionState.Unset;

            ActionState skipState = radioButton4.Checked
                                ? ActionState.Yes
                                : radioButton5.Checked
                                        ? ActionState.No
                                        : ActionState.Unset;

            BackUpSettings settings = new BackUpSettings()
            {
                TargetDirectory       = targetPath,
                OriginDirectories     = originPaths,
                DefaultOverwriteState = overwriteState,
                DefaultSkipState      = skipState
            };

            foreach (string path in originPaths)
            {
                if (!Directory.Exists(path))
                {
                    throw new DirectoryNotFoundException();
                }
            }

            Settings.Save(settings, name);
        }