--- xmlTools/posUpdate/XmlPatch.cs 2013/03/21 10:40:39 711 +++ xmlTools/trunk/posUpdate/XmlPatch.cs 2013/03/26 15:23:42 746 @@ -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); @@ -276,18 +284,18 @@ namespace xmlTools string paramType = ""; // Filename already exists? - if (command.IndexOf("filename:") != -1) + if (Util.ContainsIgnoreCase(command,"filename:")) { paramType = "filename:"; } - else if (command.IndexOf("filename=") != -1) + else if (Util.ContainsIgnoreCase(command, "filename=")) { paramType = "filename="; } // 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," -filename:" + this.forceFiles); } if (paramType != "") @@ -296,7 +304,7 @@ namespace xmlTools int endIdx = command.IndexOf(" ", startIdx); // it may end with space if (endIdx == -1) { - endIdx = command.IndexOf("\"", startIdx); // or with quotes + endIdx = command.IndexOf("\n", startIdx); // or with endline } string currFilename = command.Substring(startIdx, endIdx - startIdx); command = command.Replace(currFilename, this.forceFiles); @@ -304,34 +312,12 @@ 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, " -nobackups"); } - 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(); + Program.Main(Util.stringToArgsArray(command)); // use the current process is more efficient than start a new one } catch (Exception e) { @@ -342,49 +328,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 = "";