--- xmlTools/trunk/posUpdate/XmlPatch.cs 2013/03/21 10:43:10 714 +++ xmlTools/trunk/posUpdate/XmlPatch.cs 2013/03/26 02:30:48 742 @@ -13,16 +13,19 @@ namespace xmlTools { String fileName; String forceFiles = ""; + bool globalNoBackups = false; - public XmlPatch(String file) + public XmlPatch(String file, bool noBackups) { fileName = file; + globalNoBackups = noBackups; } - public XmlPatch(String file, String forceInFiles) + public XmlPatch(String file, String forceInFiles, bool noBackups) { fileName = file; forceFiles = forceInFiles; //We support apply the operation in diverse forced files (NameOfFile parameter will be ignored) + globalNoBackups = noBackups; } /// @@ -134,8 +137,10 @@ namespace xmlTools //---------------------------------------------------XML Injection (start) foreach (String currFile in filesToProcess) { - - Util.backupFile(currFile); + if (!this.globalNoBackups && !Util.ContainsIgnoreCase(operation, "NoBackups")) // only skip backup if specified via global parameter or in patch file + { + Util.backupFile(currFile); + } XmlDocument xdoc = new XmlDocument(); xdoc.Load(currFile); @@ -227,7 +232,10 @@ namespace xmlTools foreach (String currFile in filesToProcess) { - Util.backupFile(currFile); + if (!this.globalNoBackups && !Util.ContainsIgnoreCase(operation, "NoBackups")) // only skip backup if specified via global parameter or in patch file + { + Util.backupFile(currFile); + } XmlDocument xdoc = new XmlDocument(); xdoc.Load(currFile); @@ -287,7 +295,7 @@ namespace xmlTools // Add the filename if it doesn't exists else { - command = command.Insert(command.Length-1," -filename:" + this.forceFiles); // -2 to be inside quotes + command = command.Insert(command.Length-1," -filename:" + this.forceFiles); // -1 to be inside quotes } if (paramType != "") @@ -304,34 +312,14 @@ namespace xmlTools } - command = command.Replace("\"", ""); // remove quotes - - ProcessStartInfo startInfo = new ProcessStartInfo(); - if (!Util.IsRunningOnMono()) + if (this.globalNoBackups && !Util.ContainsIgnoreCase(command,"nobackups")) // add noBackup flag if provided as global parameter { - startInfo.FileName = Util.getExeFileName(); - } - else{ - startInfo.FileName = "mono"; - } - if (!Util.IsRunningOnMono()) - { - startInfo.Arguments = command; - } - else{ - startInfo.Arguments = Util.getExeFileName() + " " + command; + command = command.Insert(command.Length - 1, " -nobackups"); // -1 to be inside quotes } - startInfo.UseShellExecute = false; // necessary to redirect output - startInfo.RedirectStandardOutput = true; - startInfo.RedirectStandardError = true; - startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // hide new process window - Process p = System.Diagnostics.Process.Start(startInfo); - p.OutputDataReceived += commandStdOutputReceived; - p.ErrorDataReceived += commandStdErrorReceived; - p.BeginOutputReadLine(); - p.BeginErrorReadLine(); - p.WaitForExit(); + command = command.Replace("\"", ""); // remove quotes + + Program.Main(command.Split(' ')); // use the current process is more efficient than start a new one } catch (Exception e) { @@ -342,49 +330,6 @@ namespace xmlTools return true; } - /// - /// Reads asynchronously output from the new process where the command will be executed - /// - /// - /// - private void commandStdOutputReceived(object sender, DataReceivedEventArgs e) - { - - string myData = e.Data; - - if (myData != null) - { - if (myData.EndsWith("\n")) - { - Console.Write(myData); - } - else - { - Console.WriteLine(myData); - } - } - - } - - private void commandStdErrorReceived(object sender, DataReceivedEventArgs e) - { - - string myData = e.Data; - - if (myData != null) - { - if (myData.EndsWith("\n")) - { - Console.Error.Write(myData); - } - else - { - Console.Error.WriteLine(myData); - } - } - - } - private string getPatchParameter(string line, string parameterName) { string result = "";