示例#1
0
        public override void Run()
        {
            mode = (Patcher.Mode)Settings.Default.PatchMode;

            taskInterface.SetStatus("Deleting Old Src");

            if (Directory.Exists(patchedDir))
            {
                //Delete directories' files without deleting the directories themselves. This prevents weird UnauthorizedAccessExceptions from the directory being in a state of limbo.
                EmptyDirectoryRecursive(patchedDir);
            }

            var removedFileList = Path.Combine(patchDir, DiffTask.RemovedFileList);
            var noCopy          = File.Exists(removedFileList) ? new HashSet <string>(File.ReadAllLines(removedFileList)) : new HashSet <string>();

            var items = new List <WorkItem>();

            foreach (var(file, relPath) in EnumerateFiles(patchDir))
            {
                if (relPath.EndsWith(".patch"))
                {
                    items.Add(new WorkItem("Patching: " + relPath, () => Patch(file)));
                    noCopy.Add(relPath.Substring(0, relPath.Length - 6));
                }
                else if (relPath != DiffTask.RemovedFileList)
                {
                    items.Add(new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(patchedDir, relPath))));
                }
            }

            foreach (var(file, relPath) in EnumerateSrcFiles(baseDir))
            {
                if (!noCopy.Contains(relPath))
                {
                    items.Add(new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(patchedDir, relPath))));
                }
            }

            //Delete empty directories, since the directory was recursively wiped instead of being deleted.
            DeleteEmptyDirs(patchedDir);

            try
            {
                CreateDirectory(Program.logsDir);
                logFile = new StreamWriter(Path.Combine(Program.logsDir, "patch.log"));

                taskInterface.SetMaxProgress(items.Count);
                ExecuteParallel(items);
            }
            finally {
                logFile?.Close();
            }

            cutoff.Set(DateTime.Now);

            if (fuzzy > 0)
            {
                taskInterface.Invoke(new Action(() => ShowReviewWindow(results)));
            }
        }
示例#2
0
        public void Patch(Patcher.Mode mode)
        {
            if (baseLines == null)
            {
                LoadBaseFile();
            }

            var patcher = new Patcher(patchFile.patches, baseLines);

            patcher.Patch(mode);
            results      = patcher.Results.ToList();
            patchedLines = patcher.ResultLines;
        }
示例#3
0
        public override void Run()
        {
            mode = (Patcher.Mode)Settings.Default.PatchMode;

            string removedFileList = Path.Combine(patchDir, DiffTask.RemovedFileList);
            var    noCopy          = File.Exists(removedFileList) ? new HashSet <string>(File.ReadAllLines(removedFileList)) : new HashSet <string>();

            var items    = new List <WorkItem>();
            var newFiles = new HashSet <string>();

            foreach (var(file, relPath) in EnumerateFiles(patchDir))
            {
                if (relPath.EndsWith(".patch"))
                {
                    items.Add(new WorkItem("Patching: " + relPath, () => newFiles.Add(PreparePath(Patch(file).PatchedPath))));
                    noCopy.Add(relPath.Substring(0, relPath.Length - 6));
                }
                else if (relPath != DiffTask.RemovedFileList)
                {
                    string destination = Path.Combine(patchedDir, relPath);

                    items.Add(new WorkItem("Copying: " + relPath, () => Copy(file, destination)));
                    newFiles.Add(destination);
                }
            }

            foreach (var(file, relPath) in EnumerateSrcFiles(baseDir))
            {
                if (!noCopy.Contains(relPath))
                {
                    string destination = Path.Combine(patchedDir, relPath);

                    items.Add(new WorkItem("Copying: " + relPath, () => Copy(file, destination)));
                    newFiles.Add(destination);
                }
            }

            try
            {
                CreateDirectory(Program.logsDir);
                logFile = new StreamWriter(Path.Combine(Program.logsDir, "patch.log"));

                taskInterface.SetMaxProgress(items.Count);
                ExecuteParallel(items);
            }
            finally {
                logFile?.Close();
            }

            cutoff.Set(DateTime.Now);

            //Remove files and directories that weren't in patches and original src.

            taskInterface.SetStatus("Deleting Old Src");

            foreach (var(file, relPath) in EnumerateSrcFiles(patchedDir))
            {
                if (!newFiles.Contains(file))
                {
                    File.Delete(file);
                }
            }

            DeleteEmptyDirs(patchedDir);

            //Show patch reviewer if there were any fuzzy patches.

            if (fuzzy > 0)
            {
                taskInterface.Invoke(new Action(() => ShowReviewWindow(results)));
            }
        }