Beispiel #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)));
            }
        }
Beispiel #2
0
        public override void Run()
        {
            var patchFiles = new HashSet <string>(
                Directory.EnumerateFiles(FullPatchDir, "*", SearchOption.AllDirectories)
                .Select(file => RelPath(FullPatchDir, file)));
            var oldFiles = new HashSet <string>(
                Directory.EnumerateFiles(FullBaseDir, "*", SearchOption.AllDirectories)
                .Select(file => RelPath(FullBaseDir, file))
                .Where(relPath => !relPath.EndsWith(".patch") && !excluded.Any(relPath.StartsWith)));

            var items = new List <WorkItem>();

            foreach (var file in Directory.EnumerateFiles(FullSrcDir, "*", SearchOption.AllDirectories))
            {
                var relPath = RelPath(FullSrcDir, file);
                oldFiles.Remove(relPath);
                if (!extensions.Any(relPath.EndsWith))
                {
                    continue;
                }

                patchFiles.Remove(relPath);
                patchFiles.Remove(relPath + ".patch");

                if (excluded.Any(relPath.StartsWith) || File.GetLastWriteTime(file) < cutoff.Get())
                {
                    continue;
                }

                items.Add(File.Exists(Path.Combine(FullBaseDir, relPath))
                                        ? new WorkItem("Creating Diff: " + relPath, () => Diff(relPath))
                                        : new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(FullPatchDir, relPath))));
            }

            ExecuteParallel(items);

            taskInterface.SetStatus("Deleting Unnessesary Patches");
            foreach (var file in patchFiles)
            {
                File.Delete(Path.Combine(FullPatchDir, file));
            }

            taskInterface.SetStatus("Noting Removed Files");
            var removedFileList = Path.Combine(FullPatchDir, RemovedFileList);

            if (oldFiles.Count > 0)
            {
                File.WriteAllText(removedFileList, string.Join("\r\n", oldFiles));
            }
            else if (File.Exists(removedFileList))
            {
                File.Delete(removedFileList);
            }

            cutoff.Set(DateTime.Now);
        }
Beispiel #3
0
        public override void Run()
        {
            var items = new List <WorkItem>();

            foreach (var(file, relPath) in PatchTask.EnumerateSrcFiles(patchedDir))
            {
                if (File.GetLastWriteTime(file) < cutoff.Get())
                {
                    continue;
                }

                if (!File.Exists(Path.Combine(baseDir, relPath)))
                {
                    items.Add(new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(patchDir, relPath))));
                }
                else if (IsDiffable(relPath))
                {
                    items.Add(new WorkItem("Diffing: " + relPath, () => Diff(relPath)));
                }
            }

            ExecuteParallel(items);

            taskInterface.SetStatus("Deleting Unnecessary Patches");
            foreach (var(file, relPath) in EnumerateFiles(patchDir))
            {
                var targetPath = relPath.EndsWith(".patch") ? relPath.Substring(0, relPath.Length - 6) : relPath;
                if (!File.Exists(Path.Combine(patchedDir, targetPath)))
                {
                    DeleteFile(file);
                }
            }

            DeleteEmptyDirs(patchDir);

            taskInterface.SetStatus("Nothing Removed Files");
            var removedFiles = PatchTask.EnumerateSrcFiles(baseDir)
                               .Where(f => !File.Exists(Path.Combine(patchedDir, f.relPath)))
                               .Select(f => f.relPath)
                               .ToArray();

            var removedFileList = Path.Combine(patchDir, RemovedFileList);

            if (removedFiles.Length > 0)
            {
                File.WriteAllLines(removedFileList, removedFiles);
            }
            else
            {
                DeleteFile(removedFileList);
            }

            cutoff.Set(DateTime.Now);
        }
Beispiel #4
0
        public static bool SelectTerrariaDialog()
        {
            while (true)
            {
                var dialog = new OpenFileDialog {
                    InitialDirectory = Path.GetFullPath(Directory.Exists(SteamDir.Get()) ? SteamDir.Get() : Program.baseDir),
                    Filter           = "Terraria|Terraria.exe",
                    Title            = "Select Terraria.exe"
                };

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                string err = null;
                if (Path.GetFileName(dialog.FileName) != "Terraria.exe")
                {
                    err = "File must be named Terraria.exe";
                }
                else if (!File.Exists(Path.Combine(Path.GetDirectoryName(dialog.FileName), "TerrariaServer.exe")))
                {
                    err = "TerrariaServer.exe does not exist in the same directory";
                }

                if (err != null)
                {
                    if (MessageBox.Show(err, "Invalid Selection", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }
                else
                {
                    SteamDir.Set(Path.GetDirectoryName(dialog.FileName));
                    return(true);
                }
            }
        }
Beispiel #5
0
        public override void Run()
        {
            taskInterface.SetStatus("Deleting Old Src");

            if (Directory.Exists(FullSrcDir))
            {
                Directory.Delete(FullSrcDir, true);
            }

            var baseFiles  = Directory.EnumerateFiles(FullBaseDir, "*", SearchOption.AllDirectories);
            var patchFiles = Directory.EnumerateFiles(FullPatchDir, "*", SearchOption.AllDirectories);

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

            var copyItems   = new List <WorkItem>();
            var patchItems  = new List <WorkItem>();
            var formatItems = new List <WorkItem>();


            foreach (var file in baseFiles)
            {
                var relPath = RelPath(FullBaseDir, file);
                if (DiffTask.excluded.Any(relPath.StartsWith) || removedFiles.Contains(relPath))
                {
                    continue;
                }

                var srcPath = Path.Combine(FullSrcDir, relPath);
                copyItems.Add(new WorkItem("Copying: " + relPath, () => Copy(file, srcPath)));

                if (format != null && file.EndsWith(".cs"))
                {
                    formatItems.Add(new WorkItem("Formatting: " + relPath,
                                                 () => FormatTask.Format(srcPath, format, taskInterface.CancellationToken())));
                }
            }

            foreach (var file in patchFiles)
            {
                var relPath = RelPath(FullPatchDir, file);
                if (relPath.EndsWith(".patch"))
                {
                    patchItems.Add(new WorkItem("Patching: " + relPath, () => Patch(relPath)));
                }
                else if (relPath != DiffTask.RemovedFileList)
                {
                    copyItems.Add(new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(FullSrcDir, relPath))));
                }
            }

            taskInterface.SetMaxProgress(copyItems.Count + formatItems.Count + patchItems.Count);
            ExecuteParallel(copyItems, false);
            ExecuteParallel(formatItems, false);

            try
            {
                CreateDirectory(Program.LogDir);
                logFile = new StreamWriter(Path.Combine(Program.LogDir, "patch.log"));
                ExecuteParallel(patchItems, false);
            }
            finally {
                logFile?.Close();
            }

            cutoff.Set(DateTime.Now);
        }
Beispiel #6
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)));
            }
        }
Beispiel #7
0
        public override void Run()
        {
            List <string> patchesFiles = new List <string>();          // (Directory.EnumerateFiles(FullPatchDir, "*", SearchOption.AllDirectories));

            foreach (var file in Directory.EnumerateFiles(FullPatchDir, "*", SearchOption.AllDirectories))
            {
                patchesFiles.Add(RelPath(FullPatchDir, file));
            }
            //if (Directory.Exists(FullPatchDir))
            //	Directory.Delete(FullPatchDir, true);

            var files = Directory.EnumerateFiles(FullSrcDir, "*", SearchOption.AllDirectories).Where(f => extensions.Any(f.EndsWith));
            var items = new List <WorkItem>();

            foreach (var file in files)
            {
                var relPath = RelPath(FullSrcDir, file);
                patchesFiles.Remove(relPath);
                patchesFiles.Remove(relPath + ".patch");
                if (excluded.Any(relPath.StartsWith))
                {
                    continue;
                }

                //bool skip = false;
                if ((stepNumber == 0 && (File.GetLastWriteTime(file) < MergedDiffCutoff.Get())) ||
                    (stepNumber == 1 && (File.GetLastWriteTime(file) < TerrariaDiffCutoff.Get())) ||
                    (stepNumber == 2 && (File.GetLastWriteTime(file) < tModLoaderDiffCutoff.Get())))
                {
                    continue;
                }
                //skip = true;

                //if (!skip)
                items.Add(File.Exists(Path.Combine(FullBaseDir, relPath))
                                        ? new WorkItem("Creating Diff: " + relPath, () => Diff(relPath))
                                        : new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(FullPatchDir, relPath))));
            }

            ExecuteParallel(items);

            taskInterface.SetStatus("Deleting Unnessesary Patches");

            foreach (string file in patchesFiles)
            {
                File.Delete(file);
            }

            switch (stepNumber)
            {
            case 0:
                MergedDiffCutoff.Set(DateTime.Now);
                break;

            case 1:
                TerrariaDiffCutoff.Set(DateTime.Now);
                break;

            case 2:
                tModLoaderDiffCutoff.Set(DateTime.Now);
                break;
            }
        }