Exemple #1
0
 public SourceEditFrm(SourceDef def, bool addMode)
 {
     InitializeComponent();
     this.addMode            = addMode;
     this.Text               = addMode ? "Add Source Backup Definition" : "Edit Source Backup Definition";
     Result                  = (def == null) ? new SourceDef() : def.DeepCopyUsingJson();
     StartFolderName_TB.Text = Result.StartingFolder;
     SubfoldersCB.Checked    = Result.TraverseSubs;
     IDTB.Text               = Result.ID.ToString();
     RefreshAllGlobRules();
     PopulateFixedFolders();
 }
Exemple #2
0
 private void CopySrc()
 {
     if (OneSourceIsSelected())
     {
         int       ndx = SourceDefsLV.SelectedIndices[0];
         SourceDef def = settings.SourceDefs[ndx].DeepCopyUsingJson();
         // duplicate entire record minus the ID, which must be unique
         int nextID = GenNextSrcID();
         def.ID = nextID;
         settings.SourceDefs.Add(def);
         settings.HighestSourceID = nextID;
         SaveSettings();
         PopulateSourceDefs();
     }
 }
Exemple #3
0
        private void AddSrc()
        {
            int nextID = GenNextSrcID();
            var def    = new SourceDef(nextID, string.Empty, true, new List <ExcludeRule> {
                CommonRules.DefaultAttrRuleForFiles
            }, null);
            var frm = new SourceEditFrm(def, true);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                // Important: Update highest Source ID in settings for future adds
                settings.HighestSourceID = nextID;
                settings.SourceDefs.Add(frm.Result);
                SaveSettings();
                PopulateSourceDefs();
            }
        }
Exemple #4
0
        private bool Validate(bool simMode, bool debugMode)
        {
            RunError = string.Empty;
            Stats    = new BackupStats {
                JobID = this.JobID, RunInSimMode = simMode, RunInDebugMode = debugMode
            };
            job = Settings.Jobs.FirstOrDefault <BackupJob>(j => j.ID == JobID);
            if (job == null)
            {
                var eligibleList = string.Join(", ", Settings.Jobs.Select(j => j.ID.ToString()));
                RunError = $"Job {JobID} is an invalid Backup Job ID. Try one of: {eligibleList}";
                return(false);
            }
            // destination folder has JobID appended
            string destOutPath = Path.Combine(job.Destination, JobID.ToString());

            // append trailing slash for small performance improvement over time so it's not constantly added for each filename grafted later
            if (destOutPath[destOutPath.Length - 1] != Path.DirectorySeparatorChar)
            {
                destOutPath += Path.DirectorySeparatorChar;
            }
            // set the destination root, then the dependent log and stats file names
            Stats.DestPathRoot     = destOutPath;
            Stats.ErrLogFileName   = GetDestRootFileNameLog(ErrorFilePrefix);
            Stats.StatsLogFileName = GetDestRootFileNameLog(StatsFilePrefix);
            Stats.DebugFileName    = GetDestRootFileNameLog(DebugFilePrefix);

            // setup folder skips for delete detection. The paths must have a trailing slash so matching works correctly
            foldersToSkipForDeleteDetection.Clear();
            foldersToSkipForDeleteDetection.Add(Path.Combine(Stats.DestPathRoot, HistoryFolderName) + Path.DirectorySeparatorChar);
            foldersToSkipForDeleteDetection.Add(Path.Combine(Stats.DestPathRoot, TrashFolderName) + Path.DirectorySeparatorChar);

            // build a list of known Bum files to skip (based on prefix convention) for delete detection
            prefixesToSkipForDeleteDetection.Clear();
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + ErrorFilePrefix + FileNameSegmentSep);
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + StatsFilePrefix + FileNameSegmentSep);
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + DebugFilePrefix + FileNameSegmentSep);
            // skip any Settings_* backup files
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + BackupSettings.SettingsFilenameBase + FileNameSegmentSep);

            // make sure all folder structures exist including special folders for BUM
            FileUtils.CreateDestFolderStructure(Stats.DestPathRoot);
            if (Stats.RunInDebugMode)
            {
                AddDebugEntryToLog($"Creating root output folder (if not present): {Stats.DestPathRoot}");
            }
            foreach (var folderName in foldersToSkipForDeleteDetection)
            {
                FileUtils.CreateDestFolderStructure(folderName);
                if (Stats.RunInDebugMode)
                {
                    AddDebugEntryToLog($"Creating special output folder (if not present): {folderName}");
                }
            }
            sourcesToBackup = new List <SourceDef>();
            foreach (var id in job.SourceIDs)
            {
                SourceDef srcDef = Settings.SourceDefs.FirstOrDefault(s => s.ID == id);
                if (srcDef == null)
                {
                    RunError = $"Job {JobID} references an invalid source ID {id} that is not found in the current settings";
                    return(false);
                }
                sourcesToBackup.Add(srcDef);
                // create dictionary lookup of "SouceID-Foldername" for each known exclusion folder
                foreach (var folder in srcDef.KnownFolderExcludes)
                {
                    knownFolderExcludeDict.Add(MakeFolderExcludeDictKey(srcDef.ID, folder.Loc), folder);
                }
                for (int ndx = 0; ndx < srcDef.GlobalExcludeRules.Count; ndx++)
                {
                    // global rule lookup id will use SourceID-RuleListIndex
                    CompiledExclusionRule excRule = new CompiledExclusionRule(srcDef.GlobalExcludeRules[ndx]);
                    if (excRule.HasErrors)
                    {
                        RunError = $"Job {JobID} and Backup Source ID {srcDef.ID} have compile errors in rule {ndx + 1}";
                        return(false);
                    }
                    globalExcludeDict.Add(MakeCompiledCodeDictKey(srcDef.ID, ndx), excRule);
                }
            }

            return(true);
        }