示例#1
0
        /// <summary>
        /// when the selected template to edit changes
        /// </summary>
        protected void OnEditChanged()
        {
            if (SelectedAddOrEdit())
            {
                // selected new = clear inputs
                txtEditName.Text       = txtEditPathsExclude.Text = txtEditPaths.Text =
                    txtTypeFilter.Text = lblLastUsed.Text = "";
                chbInvertType.Checked  = false;
            }
            else
            {
                // selected existing = show values of this template
                BackupTemplate template = TemplateHandler.GetTemplateByName(cmbTemplatesEdit.Text);
                if (template == null)
                {
                    SendOutput("[Templates] Selected template doesn't exist", true);
                    return;
                }

                txtEditName.Text = template.BackupName;
                // append "," for adding new values
                txtEditPaths.Text        = template.GetBackupPathsString() + ",";
                txtEditPathsExclude.Text = template.GetExcludePathsString() + ",";
                txtTypeFilter.Text       = template.GetTypeFilterString() + ",";
                chbInvertType.Checked    = template.TypeInverted;
                lblLastUsed.Text         = template.LastUsed.ToString();
            }
            // show buttons
            DisplayDeleteButton();
        }
        private bool MakeBackup(string targetPath, string backupname, bool onlyChanged)
        {
            BackupTemplate template = TemplateHandler.GetTemplateByName(backupname);

            if (template == null)
            {
                communication.SendOutput("[Backup] " + (backupname ?? "NULL") + " template does not exist", true);
                return(false);
            }
            if (string.IsNullOrEmpty(targetPath))
            {
                communication.SendOutput("[Backup] Destination folder does not exist: ", true);
                return(false);
            }

            try
            {
                // create destination, for sorting in explorer format year, month, day
                targetPath += "\\" + template.BackupName + "_" + DateTime.Now.ToString("yyyy_MM_dd");
                if (onlyChanged)
                {
                    targetPath += "_INC";
                }
                // if backup does already exist add hour + minute
                if (Directory.Exists(targetPath))
                {
                    targetPath += "_" + DateTime.Now.ToString("HH_mm");
                }
                Directory.CreateDirectory(targetPath);
            }
            catch
            {
                communication.SendOutput("[Backup] Could not create destination folder at " + targetPath, true);
                return(false);
            }

            communication.OnBackupProgressChanged("Started " + backupname);
            // copy files and folders
            CopyDirectories(template, targetPath, onlyChanged);
            AddUsedTemplate(targetPath, template);
            communication.SendOutput("[Backup] Saved at: " + targetPath);

            return(true);
        }