Esempio n. 1
0
        private WorkItem DecompileSourceFile(DecompilerTypeSystem ts, IGrouping <string, TypeDefinitionHandle> src, string projectName, string conditional = null)
        {
            return(new WorkItem("Decompiling: " + src.Key, updateStatus =>
            {
                var path = Path.Combine(srcDir, projectName, src.Key);
                CreateParentDirectory(path);

                using (var w = new StringWriter())
                {
                    if (conditional != null)
                    {
                        w.WriteLine("#if " + conditional);
                    }

                    CreateDecompiler(ts)
                    .DecompileTypes(src.ToArray())
                    .AcceptVisitor(new CSharpOutputVisitor(w, projectDecompiler.Settings.CSharpFormattingOptions));

                    if (conditional != null)
                    {
                        w.WriteLine("#endif");
                    }

                    string source = w.ToString();
                    if (formatOutput)
                    {
                        updateStatus("Formatting: " + src.Key);
                        source = FormatTask.Format(source, taskInterface.CancellationToken, true);
                    }

                    File.WriteAllText(path, source);
                }
            }));
        }
Esempio n. 2
0
        private void Diff(string relPath)
        {
            var srcFile  = Path.Combine(FullSrcDir, relPath);
            var baseFile = Path.Combine(FullBaseDir, relPath);

            string temp = null;

            if (srcFile.EndsWith(".cs") && format != null)
            {
                temp = Path.GetTempPath() + Guid.NewGuid() + ".cs";
                File.WriteAllText(temp, FormatTask.FormatCode(File.ReadAllText(baseFile), format, taskInterface.CancellationToken()));
                baseFile = temp;
            }

            var patch = CallDiff(baseFile, srcFile, Path.Combine(baseDir, relPath), Path.Combine(srcDir, relPath));

            if (temp != null)
            {
                File.Delete(temp);
            }

            var patchFile = Path.Combine(FullPatchDir, relPath + ".patch");

            if (patch.Trim() != "")
            {
                CreateParentDirectory(patchFile);
                File.WriteAllText(patchFile, StripDestHunkOffsets(patch));
            }
            else if (File.Exists(patchFile))
            {
                File.Delete(patchFile);
            }
        }
Esempio n. 3
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 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))
                {
                    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
                {
                    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
            {
                if (logFile != null)
                {
                    logFile.Close();
                }
            }

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

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

            case 2:
                DiffTask.tModLoaderDiffCutoff.Set(DateTime.Now);
                break;
            }
        }
Esempio n. 4
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);
        }