/// <summary> /// save patch file to disk /// </summary> /// <param name="filename"></param> public void SavePatchFile(string filename) { //save all patch task int j = patchTasks.Count; var output = new SourceFile(filename, true); //first line of patch file is original file name output.AddLine(_ORIGINAL + " " + this.OriginalFileName); for (int i = 0; i < j; ++i) { PatchTask ptask = patchTasks[i]; List <PatchCommand> cmds = ptask.GetCommands(); //each task begin with start command output.AddLine(PatchCommand.START + " " + ptask.TaskId); output.AddLine(ptask.LandMark); int cmdCount = cmds.Count; for (int n = 0; n < cmdCount; ++n) { PatchWriter.WriteCommand(output, cmds[n], true); } } output.Save(); }
public void PatchContent() { //1. check if file is exist string originalFilename = this.OriginalFileName; if (!File.Exists(originalFilename)) { throw new NotSupportedException("file not found!"); } SourceFile input = new SourceFile(originalFilename, false); input.ReadAllLines(); SourceFile output = new SourceFile(originalFilename, true); string patchCode; if (CheckIfFileWasPatched(input, out patchCode)) { //can't patch throw new NotSupportedException("not patch again in this file"); } else { //can patch **** //input patch code with original filename output.AddLine(patchCode + " " + originalFilename); } output.IsCMakeFile = input.IsCMakeFile; //----------------------------------------------------------------- //can't patch again int j = patchTasks.Count; for (int i = 0; i < j; ++i) { patchTasks[i].PatchFile(input, output); } int linecount = input.LineCount; for (int i = input.CurrentLine; i < linecount; ++i) { output.AddLine(input.GetLine(i)); input.CurrentLine++; } output.Save(); }
/// <summary> /// save patch file to disk /// </summary> /// <param name="filename"></param> public void SavePatchFile(string filename) { //save all patch task int j = patchTasks.Count; var output = new SourceFile(filename, true); //first line of patch file is original file name output.AddLine(_ORIGINAL + " " + this.OriginalFileName); for (int i = 0; i < j; ++i) { PatchTask ptask = patchTasks[i]; List <PatchCommand> cmds = ptask.GetCommands(); //each task begin with start command if (ptask.IsPatchBlock) { //this is patch block output.AddLine(PatchCommand.BEGIN + " 0"); //pre-notes/ post-notes int noteCount = ptask.preNotes.Count; for (int m = 0; m < noteCount; ++m) { //write each line of pre note output.AddLine(PatchCommand.PRE); output.AddLine(ptask.preNotes[m]); } //--------- int contentLineCount = ptask.ContentLines.Count; for (int m = 0; m < contentLineCount; ++m) { output.AddLine(ptask.ContentLines[m]); } //--------- noteCount = ptask.postNotes.Count; for (int m = 0; m < noteCount; ++m) { //write each line of post note output.AddLine(PatchCommand.POST); output.AddLine(ptask.postNotes[m]); } output.AddLine(PatchCommand.END + " 0"); } else { if (!string.IsNullOrEmpty(ptask.PatchStartCmd)) { output.AddLine(PatchCommand.START + " " + ptask.TaskId + " " + ptask.PatchStartCmd); } else { output.AddLine(PatchCommand.START + " " + ptask.TaskId); } output.AddLine(ptask.LandMark); int cmdCount = cmds.Count; for (int n = 0; n < cmdCount; ++n) { PatchWriter.WriteCommand(output, cmds[n], true); } } } output.Save(); }
public void PatchContent() { PatchingMsg = null; //1. check if file is exist string originalFilename = this.OriginalFileName; if (!File.Exists(originalFilename)) { throw new NotSupportedException("file not found!"); } SourceFile input = new SourceFile(originalFilename, false); input.ReadAllLines(); SourceFile output = new SourceFile(originalFilename, true); string patchCode; if (CheckIfFileWasPatched(input, out patchCode)) { //can't patch //throw new NotSupportedException("not patch again in this file"); PatchingMsg = this.OriginalFileName + " => has be patched, so skip this file"; return; } else { //can patch **** //input patch code with original filename output.AddLine(patchCode + " " + originalFilename); } output.IsCMakeFile = input.IsCMakeFile; //----------------------------------------------------------------- //other patch that is not block-patch int j = patchTasks.Count; for (int i = 0; i < j; ++i) { PatchTask ptask = patchTasks[i]; if (!ptask.IsPatchBlock) { ptask.PatchFile(input, output); } else { ptask.PatchBlockSouldStartAt = output.LineCount; } } int linecount = input.LineCount; for (int i = input.CurrentLine; i < linecount; ++i) { output.AddLine(input.GetLine(i)); input.CurrentLine++; } //----------------------------------------------------------------- //only block-patch for (int i = 0; i < j; ++i) { PatchTask ptask = patchTasks[i]; if (ptask.IsPatchBlock) { int newLineCount = ptask.PatchBlockFile(output); if (newLineCount == 1) { for (int n = i + 1; n < j; ++n) { //adjust new offset PatchTask p2 = patchTasks[n]; if (p2.IsPatchBlock) { p2.PatchBlockSouldStartAt += 1; } } } else { System.Diagnostics.Debug.WriteLine("output is not saved: " + ptask.Owner.OriginalFileName); return; } } } output.Save(); }