コード例 #1
0
        public void CreatePatchingBatchFiles()
        {
            this.MainParent.PatchProgress = 0;
            this._Progress = 0;

            if (!File.Exists(Path.Combine(MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory)) && !this.MainParent.Options.CreateBatchFileOnly)
            {
                Directory.CreateDirectory(Path.Combine(MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory));
            }

            //Batch creation - Windows//
            StreamWriter patchWriterWindows = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "2.Apply Patch-Windows.bat"));

            patchWriterWindows.WriteLine("@echo off");
            patchWriterWindows.WriteLine("mkdir output");
            // Batch creation - Linux //
            StreamWriter patchWriterLinux = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "2.Apply Patch-Linux.sh"));

            patchWriterLinux.NewLine = "\n";
            patchWriterLinux.WriteLine("#!/bin/sh");
            patchWriterLinux.WriteLine("cd \"$(cd \"$(dirname \"$0\")\" && pwd)\"");
            patchWriterLinux.WriteLine("mkdir ./output");
            patchWriterLinux.WriteLine("chmod +x ./exec/" + Path.GetFileName(MainWindow.XDELTA3_BINARY_LINUX));
            // Batch creation - Mac //
            StreamWriter patchWriterMac = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "2.Apply Patch-Mac.command"));

            patchWriterMac.NewLine = "\n";
            patchWriterMac.WriteLine("#!/bin/sh");
            patchWriterMac.WriteLine("cd \"$(cd \"$(dirname \"$0\")\" && pwd)\"");
            patchWriterMac.WriteLine("mkdir ./output");
            patchWriterMac.WriteLine("chmod +x ./exec/" + Path.GetFileName(MainWindow.XDELTA3_BINARY_MACOS));

            StreamWriter currentPatchScript = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "doNotDelete-In-Progress.bat"));

            if (!this.MainParent.Options.CreateBatchFileOnly)
            {
                currentPatchScript.Close();
                try
                {
                    File.Delete(Path.Combine(this.MainParent.Options.PatchFileDestination, "doNotDelete-In-Progress.bat"));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                currentPatchScript = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat"));
            }
            List <string> oldFileNames = new List <string>();
            List <string> newFileNames = new List <string>();

            this.MainParent.OldFilesList.ForEach(c => oldFileNames.Add(c.ShortName));
            this.MainParent.NewFilesList.ForEach(c => newFileNames.Add(c.ShortName));

            patchWriterWindows.WriteLine("echo Place the files to be patched in the \"original\" directory with the following names:");
            patchWriterLinux.WriteLine("echo Place the files to be patched in the \\\"original\\\" directory with the following names:");
            patchWriterMac.WriteLine("echo Place the files to be patched in the \\\"original\\\" directory with the following names:");
            patchWriterWindows.WriteLine("echo --------------------");
            patchWriterLinux.WriteLine("echo --------------------");
            patchWriterMac.WriteLine("echo --------------------");

            for (int i = 0; i < this.MainParent.OldFilesList.Count; i++)
            {
                patchWriterWindows.WriteLine("echo " + oldFileNames[i]);
                patchWriterLinux.WriteLine("echo \"" + oldFileNames[i] + "\"");
                patchWriterMac.WriteLine("echo \"" + oldFileNames[i] + "\"");
            }
            patchWriterWindows.WriteLine("echo --------------------");
            patchWriterLinux.WriteLine("echo --------------------");
            patchWriterMac.WriteLine("echo --------------------");

            patchWriterWindows.WriteLine("echo Patched files will be in the \"output\" directory");
            patchWriterLinux.WriteLine("echo Patched files will be in the \\\"output\\\" directory");
            patchWriterMac.WriteLine("echo Patched files will be in the \\\"output\\\" directory");

            patchWriterWindows.WriteLine("pause");
            patchWriterLinux.WriteLine("read -p \"Press enter to continue...\" inp");
            patchWriterMac.WriteLine("read -p \"Press enter to continue...\" inp");

            for (int i = 0; i < this.MainParent.OldFilesList.Count; i++)
            {
                // Batch creation - Windows
                patchWriterWindows.WriteLine("exec\\" + Path.GetFileName(MainWindow.XDELTA3_BINARY_WINDOWS) + " -v -d -s \".\\original\\{0}\" " + "\".\\" + this.MainParent.Options.PatchSubdirectory + "\\" + "{0}." + this.MainParent.Options.PatchExtention + "\" \".\\output\\{2}\"", oldFileNames[i], this.MainParent.Options.PatchSubdirectory + "\\" + (i + 1).ToString(), newFileNames[i]);
                // Batch creation - Linux //
                patchWriterLinux.WriteLine("./exec/" + Path.GetFileName(MainWindow.XDELTA3_BINARY_LINUX) + " -v -d -s \"./original/{0}\" " + '"' + this.MainParent.Options.PatchSubdirectory + '/' + "{0}." + this.MainParent.Options.PatchExtention + "\" \"./output/{2}\"", oldFileNames[i], this.MainParent.Options.PatchSubdirectory + (i + 1).ToString(), newFileNames[i]);
                // Batch creation - Mac //
                patchWriterMac.WriteLine("./exec/" + Path.GetFileName(MainWindow.XDELTA3_BINARY_MACOS) + " -v -d -s \"./original/{0}\" " + '"' + this.MainParent.Options.PatchSubdirectory + '/' + "{0}." + this.MainParent.Options.PatchExtention + "\" \"./output/{2}\"", oldFileNames[i], this.MainParent.Options.PatchSubdirectory + (i + 1).ToString(), newFileNames[i]);

                // Script for patch creation
                if (!this.MainParent.Options.CreateBatchFileOnly)
                {
                    currentPatchScript.WriteLine("\"" + MainWindow.XDELTA3_PATH + "\"" + " " + this.MainParent.Options.XDeltaArguments + " " + "\"" + this.MainParent.OldFilesList[i].FullPath + "\" \"" + this.MainParent.NewFilesList[i].FullPath + "\" \"" + Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, oldFileNames[i]) + "." + this.MainParent.Options.PatchExtention + "\"");
                }
            }
            patchWriterWindows.WriteLine("echo Completed!");
            patchWriterWindows.WriteLine("@pause");
            patchWriterWindows.Close();
            patchWriterLinux.Close();
            patchWriterMac.Close();

            currentPatchScript.Close();

            if (this.MainParent.Options.CreateBatchFileOnly)
            {
                try
                {
                    File.Delete(Path.Combine(MainParent.Options.PatchFileDestination, "doNotDelete-In-Progress.bat"));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
                this.MainParent.PatchProgress = 0;
                if (this.MainParent.Options.ZipFilesWhenDone)
                {
                    this.ZipFiles();
                }
                this.MainParent.AlreadyBusy = false;
                Dispatcher.UIThread.InvokeAsync(new Action(() =>
                {
                    SuccessDialog dialog = new SuccessDialog(this.MainParent);
                    dialog.Show();
                    dialog.Topmost = true;
                    dialog.Topmost = false;
                }));
            }
            else
            {
                CreateNewXDeltaThread().Start();
            }
        }
コード例 #2
0
        public void CreatePatchingBatchFiles()
        {
            this.MainParent.PatchProgress = 0;
            this._Progress = 0;

            if (!File.Exists(Path.Combine(MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory)) && !this.MainParent.Options.CreateBatchFileOnly)
            {
                Directory.CreateDirectory(Path.Combine(MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory));
            }

            //Batch creation - Windows//
            StreamWriter patchWriterWindows = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "2.Apply Patch-Windows.bat"));

            patchWriterWindows.WriteLine("@echo off");
            patchWriterWindows.WriteLine("mkdir old");
            // Batch creation - Linux //
            StreamWriter patchWriterLinux = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "2.Apply Patch-Linux.sh"));

            patchWriterLinux.NewLine = "\n";
            patchWriterLinux.WriteLine("#!/bin/sh");
            patchWriterLinux.WriteLine("cd \"$(cd \"$(dirname \"$0\")\" && pwd)\"");
            patchWriterLinux.WriteLine("mkdir old");
            patchWriterLinux.WriteLine("chmod +x ./" + Path.GetFileName(MainWindow.XDELTA3_BINARY_LINUX));
            // Batch creation - Mac //
            StreamWriter patchWriterMac = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "2.Apply Patch-Mac.command"));

            patchWriterMac.NewLine = "\n";
            patchWriterMac.WriteLine("#!/bin/sh");
            patchWriterMac.WriteLine("cd \"$(cd \"$(dirname \"$0\")\" && pwd)\"");
            patchWriterMac.WriteLine("mkdir ./old");
            patchWriterMac.WriteLine("chmod +x ./" + Path.GetFileName(MainWindow.XDELTA3_BINARY_MACOS));

            StreamWriter currentPatchScript = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, "doNotDelete-In-Progress.bat"));

            if (!this.MainParent.Options.CreateBatchFileOnly)
            {
                currentPatchScript.Close();
                try
                {
                    File.Delete(Path.Combine(this.MainParent.Options.PatchFileDestination, "doNotDelete-In-Progress.bat"));
                } catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                currentPatchScript = new StreamWriter(Path.Combine(MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat"));
            }
            List <string> oldFileNames = new List <string>();
            List <string> newFileNames = new List <string>();

            this.MainParent.OldFilesList.ForEach(c => oldFileNames.Add(c.ShortName));
            this.MainParent.NewFilesList.ForEach(c => newFileNames.Add(c.ShortName));

            for (int i = 0; i < this.MainParent.OldFilesList.Count; i++)
            {
                patchWriterWindows.WriteLine(MainWindow.XDELTA3_BINARY_WINDOWS + " -v -d -s \"{0}\" " + "\".\\" + this.MainParent.Options.PatchSubdirectory + "\\" + "{0}." + this.MainParent.Options.PatchExtention + "\" \"{2}\"", oldFileNames[i], this.MainParent.Options.PatchSubdirectory + "\\" + (i + 1).ToString(), newFileNames[i]);
                patchWriterWindows.WriteLine("move \"{0}\" old", oldFileNames[i]);
                // Batch creation - Linux //
                patchWriterLinux.WriteLine(MainWindow.XDELTA3_BINARY_LINUX + " -v -d -s \"{0}\" " + '"' + this.MainParent.Options.PatchSubdirectory + '/' + "{0}." + this.MainParent.Options.PatchExtention + "\" \"{2}\"", oldFileNames[i], this.MainParent.Options.PatchSubdirectory + (i + 1).ToString(), newFileNames[i]);
                patchWriterLinux.WriteLine("mv \"{0}\" old", oldFileNames[i]);
                // Batch creation - Mac //
                patchWriterMac.WriteLine(MainWindow.XDELTA3_BINARY_MACOS + " -v -d -s \"{0}\" " + '"' + this.MainParent.Options.PatchSubdirectory + '/' + "{0}." + this.MainParent.Options.PatchExtention + "\" \"{2}\"", oldFileNames[i], this.MainParent.Options.PatchSubdirectory + (i + 1).ToString(), newFileNames[i]);
                patchWriterMac.WriteLine("mv \"{0}\" old", oldFileNames[i]);

                // Script for patch creation
                if (!this.MainParent.Options.CreateBatchFileOnly)
                {
                    currentPatchScript.WriteLine("\"" + MainWindow.XDELTA3_PATH + "\"" + " " + this.MainParent.Options.XDeltaArguments + " " + "\"" + this.MainParent.OldFilesList[i].FullPath + "\" \"" + this.MainParent.NewFilesList[i].FullPath + "\" \"" + Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, oldFileNames[i]) + "." + this.MainParent.Options.PatchExtention + "\"");
                }
            }
            patchWriterWindows.WriteLine("echo Completed!");
            patchWriterWindows.WriteLine("@pause");
            patchWriterWindows.Close();
            patchWriterLinux.Close();
            patchWriterMac.Close();

            currentPatchScript.Close();

            if (!this.MainParent.Options.CreateBatchFileOnly)
            {
                new Thread(() =>
                {
                    using (Process activeCMD = new Process())
                    {
                        activeCMD.OutputDataReceived += HandleCMDOutput;
                        activeCMD.ErrorDataReceived  += HandleCMDError;

                        ProcessStartInfo info = new ProcessStartInfo();

                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                        {
                            info.FileName = Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat");
                        }
                        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                        {
                            string args        = Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat");
                            string escapedArgs = "/bin/bash " + args.Replace("\"", "\\\"");
                            info.FileName      = "/bin/bash";
                            info.Arguments     = $"-c \"{escapedArgs}\"";
                        }
                        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                        {
                            // Todo test
                            string args        = Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat");
                            string escapedArgs = "/bin/bash " + args.Replace("\"", "\\\"");
                            info.FileName      = "/bin/bash";
                            info.Arguments     = $"-c \"{escapedArgs}\"";
                        }

                        info.WindowStyle            = ProcessWindowStyle.Hidden;
                        info.CreateNoWindow         = true;
                        info.UseShellExecute        = false;
                        info.RedirectStandardOutput = true;
                        info.RedirectStandardError  = true;

                        activeCMD.StartInfo           = info;
                        activeCMD.EnableRaisingEvents = true;

                        activeCMD.Start();
                        activeCMD.BeginOutputReadLine();
                        activeCMD.BeginErrorReadLine();
                        activeCMD.WaitForExit();
                        try
                        {
                            File.Delete(Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat"));
                        } catch (Exception e)
                        {
                            Debug.WriteLine(e);
                        }

                        if (this.MainParent.Options.ZipFilesWhenDone)
                        {
                            this.ZipFiles();
                        }
                        this.MainParent.AlreadyBusy   = false;
                        this.MainParent.PatchProgress = 0;
                        Dispatcher.UIThread.InvokeAsync(new Action(() =>
                        {
                            SuccessDialog dialog = new SuccessDialog(this.MainParent);
                            dialog.Show();
                            dialog.Topmost = true;
                            dialog.Topmost = false;
                        }));
                    }
                })
                {
                    IsBackground = true
                }.Start();
            }
            else
            {
                try
                {
                    File.Delete(Path.Combine(MainParent.Options.PatchFileDestination, "doNotDelete-In-Progress.bat"));
                } catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
                this.MainParent.PatchProgress = 0;
                if (this.MainParent.Options.ZipFilesWhenDone)
                {
                    this.ZipFiles();
                }
                this.MainParent.AlreadyBusy = false;
                Dispatcher.UIThread.InvokeAsync(new Action(() =>
                {
                    SuccessDialog dialog = new SuccessDialog(this.MainParent);
                    dialog.Show();
                    dialog.Topmost = true;
                    dialog.Topmost = false;
                }));
            }
        }
コード例 #3
0
        private Thread CreateNewXDeltaThread()
        {
            return(new Thread(() =>
            {
                using (Process activeCMD = new Process())
                {
                    activeCMD.OutputDataReceived += HandleCMDOutput;
                    activeCMD.ErrorDataReceived += HandleCMDError;

                    ProcessStartInfo info = new ProcessStartInfo();

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        info.FileName = Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat");
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        string args = Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat");
                        string escapedArgs = "/bin/bash " + args.Replace("\"", "\\\"").Replace(" ", "\\ ").Replace("(", "\\(").Replace(")", "\\)");
                        info.FileName = "/bin/bash";
                        info.Arguments = $"-c \"{escapedArgs}\"";
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    {
                        string args = Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat");
                        string escapedArgs = "/bin/bash " + args.Replace("\"", "\\\"").Replace(" ", "\\ ").Replace("(", "\\(").Replace(")", "\\)");
                        info.FileName = "/bin/bash";
                        info.Arguments = $"-c \"{escapedArgs}\"";
                    }

                    info.WindowStyle = ProcessWindowStyle.Hidden;
                    info.CreateNoWindow = true;
                    info.UseShellExecute = false;
                    info.RedirectStandardOutput = true;
                    info.RedirectStandardError = true;

                    activeCMD.StartInfo = info;
                    activeCMD.EnableRaisingEvents = true;

                    activeCMD.Start();
                    activeCMD.BeginOutputReadLine();
                    activeCMD.BeginErrorReadLine();
                    activeCMD.WaitForExit();
                    try
                    {
                        File.Delete(Path.Combine(this.MainParent.Options.PatchFileDestination, this.MainParent.Options.PatchSubdirectory, "doNotDelete-In-Progress.bat"));
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }

                    if (this.MainParent.Options.ZipFilesWhenDone)
                    {
                        this.ZipFiles();
                    }
                    this.MainParent.AlreadyBusy = false;
                    this.MainParent.PatchProgress = 0;
                    Dispatcher.UIThread.InvokeAsync(new Action(() =>
                    {
                        SuccessDialog dialog = new SuccessDialog(this.MainParent);
                        dialog.Show();
                        dialog.Topmost = true;
                        dialog.Topmost = false;
                    }));
                }
            })
            {
                IsBackground = true
            });
        }