public void Do_CMake_txt_New_3_2704_up() { var patch = new PatchFile(RootDir + "\\cefclient\\" + "CMakeLists.txt"); patch.NewTask("# Source files.") .Append(@"set(CEFCLIENT_MYCEF_MYCEF_SRCS myext/dll_init.cpp myext/dll_init.h myext/ExportFuncs.cpp myext/ExportFuncs.h myext/mycef.cc myext/mycef.h myext/mycef_msg_const.h ) source_group(cefclient\\\\myext FILES ${CEFCLIENT_MYCEF_MYCEF_SRCS}) set(CEFCLIENT_MYCEF_SRCS ${CEFCLIENT_MYCEF_MYCEF_SRCS} )"); patch.NewTask("# Windows configuration.") .FindNext("if(OS_WINDOWS)") .FindNext("set(CEFCLIENT_SRCS") .Append("${CEFCLIENT_MYCEF_MYCEF_SRCS}"); patch.PatchContent(); }
public void Do_LibCefDll_CMake_txt(string cmakeSrc) { var patch = new PatchFile(cmakeSrc); patch.NewTask("set(CEF_TARGET libcef_dll_wrapper)") .FindNext("source_group(libcef_dll FILES ${LIBCEF_SRCS})") .Append(@"set(LIBCEF_MYEXT_SRCS myext/myext.cpp myext/myext.h myext/ExportFuncAuto.cpp myext/ExportFuncAuto.h myext/InternalHeaderForExportFunc.h ) source_group(libcef_dll\\\\myext FILES ${LIBCEF_MYEXT_SRCS}) "); //=================== patch.NewTask("add_library(${CEF_TARGET}") .FindNext("${LIBCEF_WRAPPER_SRCS}") .Append("${LIBCEF_MYEXT_SRCS}"); //=================== patch.NewTask("# Mac OS X configuration.") .FindNext("if(OS_MACOSX)") .FindNext("${LIBCEF_WRAPPER_SRCS}") .Append("${LIBCEF_MYEXT_SRCS}"); //=================== patch.NewTask("# Linux configuration.") .FindNext("if(OS_MACOSX)") .FindNext("${LIBCEF_WRAPPER_SRCS}") .Append("${LIBCEF_MYEXT_SRCS}"); patch.PatchContent(); }
/// <summary> /// save all patches into a specific folder /// </summary> /// <param name="folder"></param> public void Save(string folder) { for (int i = pfiles.Count - 1; i >= 0; --i) { PatchFile pfile = pfiles[i]; //save patch file into a folder string filename = folder + "\\" + Path.GetFileName(pfile.OriginalFileName) + ".patch"; pfile.SavePatchFile(filename); } }
//EXPERIMENT! private void cmdMacApplyPatches_Click(object sender, EventArgs e) { throw new NotSupportedException(); //EXPERIMENT! //cef_binary_3.3071.1647 string srcRootDir = @"D:\projects\cef_binary_3.3071.1647.macos\tests"; string patchSrcFolder = "d:\\WImageTest\\cefbridge_patches_mac"; PatchBuilder builder2 = new PatchBuilder(new string[] { srcRootDir, }); builder2.LoadPatchesFromFolder(patchSrcFolder); List <PatchFile> pfiles = builder2.GetAllPatchFiles(); string newPathName = srcRootDir; for (int i = pfiles.Count - 1; i >= 0; --i) { //can change original filename before patch PatchFile pfile = pfiles[i]; string onlyFileName = System.IO.Path.GetFileName(pfile.OriginalFileName); string onlyPath = System.IO.Path.GetDirectoryName(pfile.OriginalFileName); int indexOfCefClient = onlyPath.IndexOf("\\cefclient\\"); if (indexOfCefClient < 0) { indexOfCefClient = onlyPath.IndexOf("\\shared\\"); if (indexOfCefClient < 0) { throw new NotSupportedException(); } } string rightSide = onlyPath.Substring(indexOfCefClient); //string replaceName = onlyPath.Replace("D:\\projects\\cef_binary_3.2623.1399\\cefclient", newPathName); string replaceName = newPathName + rightSide; pfile.OriginalFileName = replaceName + "//" + onlyFileName; pfile.PatchContent(); } ManualPatcher manualPatcher = new ManualPatcher(newPathName); string extTargetDir = newPathName + "\\cefclient\\myext"; //manualPatcher.CopyExtensionSources(extTargetDir); manualPatcher.Do_CefClient_CMake_txt(); }
public void LoadPatchesFromFolder(string folder) { pfiles.Clear(); this.filenames.Clear(); string[] filenames = Directory.GetFiles(folder); for (int i = filenames.Length - 1; i >= 0; --i) { PatchFile pfile = PatchFile.BuildPatchFile(filenames[i]); if (pfile != null) { pfiles.Add(pfile); } } }
//public string RootDir //{ // get; // set; //} public void MakePatch() { //from root dir //just find line with specific values pfiles.Clear(); filenames.Clear(); foreach (string srcFolder in this.srcFolders) { CollectFilesRecursive(srcFolder); } //-------------------------------------- for (int i = filenames.Count - 1; i >= 0; --i) { PatchFile pfile = PatchFile.BuildPatchFile(filenames[i]); if (pfile != null) { pfiles.Add(pfile); } } }
public void Do_CefClient_CMake_txt() { //for 3_2704+ var patch = new PatchFile(RootDir + "\\cefclient\\" + "CMakeLists.txt"); patch.NewTask("# Source files.") .Append(@"set(CEFCLIENT_MYCEF_MYCEF_SRCS myext/ExportFuncs.cpp myext/ExportFuncs.h myext/mycef.cc myext/mycef.h myext/MyCefJs.cpp myext/MyCefJs.h myext/mycef_msg_const.h myext/mycef_buildconfig.h ) source_group(cefclient\\\\myext FILES ${CEFCLIENT_MYCEF_MYCEF_SRCS}) set(CEFCLIENT_MYCEF_SRCS ${CEFCLIENT_MYCEF_MYCEF_SRCS} )"); //=================== patch.NewTask("# Windows configuration.") .FindNext("if(OS_WINDOWS)") .FindNext("set(CEFCLIENT_SRCS") .Append("${CEFCLIENT_MYCEF_MYCEF_SRCS}"); //=================== patch.NewTask("# Mac OS X configuration.") .FindNext("if(OS_MACOSX)") .FindNext("set(CEFCLIENT_SRCS") .Append("${CEFCLIENT_MYCEF_MYCEF_SRCS}"); //=================== patch.NewTask("# Linux configuration.") .FindNext("if(OS_MACOSX)") .FindNext("set(CEFCLIENT_SRCS") .Append("${CEFCLIENT_MYCEF_MYCEF_SRCS}"); patch.PatchContent(); }
private void cmdLoadPatchAndApplyPatch_Click(object sender, EventArgs e) { string backup_nativePatcher = _selectedPreSet.Backup_NativePatcher_Folder; string backup_NativePatcher_BridgeBuilder_folder = _selectedPreSet.Backup_NativePatcher_BridgeBuilder; string srcRootDir0 = _cefSrcRootDir; //where is patch folder string cefBridge_PatchFolder = _selectedPreSet.PatchFolder; string org_cefclient_test_folder = srcRootDir0 + "\\tests"; //copy my extension file relative folder to this project FolderUtils.CopyFolder(backup_NativePatcher_BridgeBuilder_folder + @"\Patcher_ExtCode\myext", org_cefclient_test_folder + "\\cefclient"); //copy my extension file FolderUtils.CopyFolder(backup_NativePatcher_BridgeBuilder_folder + @"\Patcher_ExtCode_libcef_dll\myext", srcRootDir0 + "\\libcef_dll"); //----------- ManualPatcher manualPatcher = new ManualPatcher(org_cefclient_test_folder); //1. System.IO.File.Copy(backup_NativePatcher_BridgeBuilder_folder + @"\Patcher_ExtCode_Others\cef_base.h", srcRootDir0 + "\\include\\cef_base.h", true); //2. System.IO.File.Copy(backup_NativePatcher_BridgeBuilder_folder + @"\Patcher_ExtCode_Others\cpptoc_ref_counted.h", srcRootDir0 + "\\libcef_dll\\cpptoc\\cpptoc_ref_counted.h", true); //3. System.IO.File.Copy(backup_NativePatcher_BridgeBuilder_folder + @"\Patcher_ExtCode_Others\ctocpp_ref_counted.h", srcRootDir0 + "\\libcef_dll\\ctocpp\\ctocpp_ref_counted.h", true); //----------- manualPatcher.Do_LibCefDll_CMake_txt(srcRootDir0 + "\\libcef_dll\\CMakeLists.txt"); manualPatcher.Do_CefClient_CMake_txt(); //----------- PatchBuilder builder2 = new PatchBuilder(new string[] { org_cefclient_test_folder, }); builder2.LoadPatchesFromFolder(cefBridge_PatchFolder); List <PatchFile> pfiles = builder2.GetAllPatchFiles(); //string oldPathName = srcRootDir; for (int i = pfiles.Count - 1; i >= 0; --i) { //can change original filename before patch PatchFile pfile = pfiles[i]; string onlyFileName = System.IO.Path.GetFileName(pfile.OriginalFileName); string onlyPath = System.IO.Path.GetDirectoryName(pfile.OriginalFileName); int indexOfCefClient = onlyPath.IndexOf("\\cefclient\\"); if (indexOfCefClient < 0) { indexOfCefClient = onlyPath.IndexOf("\\shared\\"); if (indexOfCefClient < 0) { indexOfCefClient = onlyPath.IndexOf("\\cefclient"); if (indexOfCefClient < 0) { throw new NotSupportedException(); } } } string rightSide = onlyPath.Substring(indexOfCefClient); string replaceName = org_cefclient_test_folder + rightSide; if (onlyFileName.Contains("performance_test.cc")) { } pfile.OriginalFileName = replaceName + "//" + onlyFileName; pfile.PatchContent(); } }
/// <summary> /// create patch file from a patch file in disk /// </summary> /// <param name="filename"></param> /// <returns></returns> public static PatchFile BuildPatchFile(string filename) { //create patch command for specific filename PatchFile patchFile = new PatchFile(filename); SourceFile sourceFile = new SourceFile(filename, false); sourceFile.ReadAllLines(); int j = sourceFile.LineCount; if (j == 0) { return(null); } // PatchTask ptask = null; int i = 0; string line = sourceFile.GetLine(0); //first line is original filename string originalFilename; if (GetOriginalFilename(line, out originalFilename)) { //change origial file name for patch file patchFile.OriginalFileName = originalFilename; i++; //next line } for (; i < j; ++i) { line = sourceFile.GetLine(i).TrimStart(); //*** if (line.StartsWith("//###_")) { //what is the comamnd line = line.TrimEnd(); string cmdline; int taskId; string additionalInfo; ParseCommand(line, out cmdline, out taskId, out additionalInfo); switch (cmdline) { case PatchCommand.START: { //start new patch task //read next line for info i++; //read next line for land mark string cmd_value = sourceFile.GetLine(i); //create new task ptask = new PatchTask(cmd_value, taskId); ptask.Owner = patchFile; if (additionalInfo == "-X") //special cmd { ptask.PatchStartCmd = additionalInfo; } // patchFile.AddTask(ptask); } break; case PatchCommand.BEGIN: { //begin block *** //create new patch block ptask = new PatchTask("", taskId); //we will set land mark later ptask.Owner = patchFile; ptask.IsPatchBlock = true; patchFile.AddTask(ptask); ParseAutoContextPatchBlock(ptask, sourceFile, ref i); //parse auto context patch block } break; case PatchCommand.APPPEND_START: { //start collect append string //until find append_stop var collectAppendStBuilder = new StringBuilder(); i++; string cmd_value = sourceFile.GetLine(i); line = cmd_value.TrimStart(); //eval do { if (line.StartsWith(PatchCommand.APPPEND_STOP)) { //stop here break; } else { if (line.StartsWith("//###_")) { //other command throw new NotSupportedException(); } else { //collect this line collectAppendStBuilder.AppendLine(line); //read next line i++; line = sourceFile.GetLine(i).TrimStart(); } } } while (true); //finish command ptask.Append(collectAppendStBuilder.ToString()); } break; case PatchCommand.APPPEND_STOP: throw new NotSupportedException(); case PatchCommand.FIND_NEXT_LANDMARK: { i++; string cmd_value = sourceFile.GetLine(i); if (taskId != ptask.TaskId) { throw new NotSupportedException(); } ptask.FindNext(cmd_value); } break; case PatchCommand.FOLLOW_BY: { i++; string cmd_value = sourceFile.GetLine(i); if (taskId != ptask.TaskId) { throw new NotSupportedException(); } ptask.FollowBy(cmd_value); } break; case PatchCommand.SKIP_UNTIL_AND_ACCEPT: { i++; string cmd_value = sourceFile.GetLine(i); if (taskId != ptask.TaskId) { throw new NotSupportedException(); } ptask.SkipUntilAndAccept(cmd_value); } break; case PatchCommand.SKIP_UNTIL_PASS: { //has 2 parameters if (additionalInfo == null) { throw new NotSupportedException(); } // ptask.SkipUntilPass(additionalInfo); } break; default: throw new NotSupportedException(); } } } if (patchFile.TaskCount > 0) { return(patchFile); } else { return((ptask != null && ptask.CommandCount > 0) ? patchFile : null); } }
private void cmdLoadPatchAndApplyPatch_Click(object sender, EventArgs e) { //string srcRootDir = @"D:\projects\cef_binary_3.2526.1366" + "\\cefclient"; //2526.1366 //string srcRootDir = @"D:\projects\cef_binary_3.2623.1395" + "\\cefclient"; //2526.1366 //string srcRootDir = @"D:\projects\cef_binary_3.2623.1399" + "\\cefclient"; //2526.1366 //string srcRootDir = @"D:\projects\cef_binary_3.2704.1418"; //string srcRootDir = @"D:\projects\cef_binary_3.2785.1466"; //string srcRootDir = @"D:\projects\cef_binary_3.2883.1548\\tests"; string srcRootDir = @"D:\projects\cef_binary_3.2883.1553\\tests"; string saveFolder = "d:\\WImageTest\\cefbridge_patches"; PatchBuilder builder2 = new PatchBuilder(new string[] { srcRootDir, @"D:\projects\cef_binary_3.2883.1553\\shared" }); builder2.LoadPatchesFromFolder(saveFolder); List <PatchFile> pfiles = builder2.GetAllPatchFiles(); //string oldPathName = srcRootDir; string newPathName = srcRootDir;// "d:\\projects\\CefBridge\\cef3\\cefclient"; for (int i = pfiles.Count - 1; i >= 0; --i) { //can change original filename before patch PatchFile pfile = pfiles[i]; string onlyFileName = System.IO.Path.GetFileName(pfile.OriginalFileName); string onlyPath = System.IO.Path.GetDirectoryName(pfile.OriginalFileName); int indexOfCefClient = onlyPath.IndexOf("\\cefclient\\"); if (indexOfCefClient < 0) { indexOfCefClient = onlyPath.IndexOf("\\shared\\"); if (indexOfCefClient < 0) { throw new NotSupportedException(); } } string rightSide = onlyPath.Substring(indexOfCefClient); //string replaceName = onlyPath.Replace("D:\\projects\\cef_binary_3.2623.1399\\cefclient", newPathName); string replaceName = newPathName + rightSide; pfile.OriginalFileName = replaceName + "//" + onlyFileName; pfile.PatchContent(); } ManualPatcher manualPatcher = new ManualPatcher(newPathName); string extTargetDir = newPathName + "\\cefclient\\myext"; manualPatcher.CopyExtensionSources(extTargetDir); manualPatcher.Do_CMake_txt_New_3_2704_up(); //bool is3_2704 = true; //if (is3_2704) //{ // string extTargetDir = newPathName + "\\cefclient\\myext"; // manualPatcher.CopyExtensionSources(extTargetDir); // manualPatcher.Do_CMake_txt_New_3_2704_up(); //} //else //{ // string extTargetDir = newPathName + "\\myext"; // manualPatcher.CopyExtensionSources(extTargetDir); // manualPatcher.Do_CMake_txt_old(); ; //} }
/// <summary> /// create patch file from a patch file in disk /// </summary> /// <param name="filename"></param> /// <returns></returns> public static PatchFile BuildPatchFile(string filename) { //if (filename == "d:\\projects\\CefBridge\\cef3\\cefclient\\browser\\client_handler.cc") //{ //} //create patch command for specific filename PatchFile patchFile = new PatchFile(filename); SourceFile sourceFile = new SourceFile(filename, false); sourceFile.ReadAllLines(); int j = sourceFile.LineCount; PatchTask ptask = null; int i = 0; string line = sourceFile.GetLine(0); //first line is original filename string originalFilename; if (GetOriginalFilename(line, out originalFilename)) { //change origial file name for patch file patchFile.OriginalFileName = originalFilename; i++; //next line } for (; i < j; ++i) { line = sourceFile.GetLine(i).TrimStart(); if (line.StartsWith("//###_")) { //what is the comamnd int pos0 = line.IndexOf(' '); //first (must have if (pos0 < 0) { throw new NotSupportedException("pos 0"); } else { string additionalInfo; int taskId = GetTaskId(line, pos0 + 1, out additionalInfo); string cmdline = line.Substring(0, pos0); switch (cmdline) { case PatchCommand.START: //start new patch task //read next line for info { i++; string cmd_value = sourceFile.GetLine(i); //create new task ptask = new PatchTask(cmd_value, taskId); patchFile.AddTask(ptask); } break; case PatchCommand.APPPEND_START: //start collect append string //until find append_stop { var collectAppendStBuilder = new StringBuilder(); i++; string cmd_value = sourceFile.GetLine(i); line = cmd_value.TrimStart(); //eval do { if (line.StartsWith(PatchCommand.APPPEND_STOP)) { //stop here break; } else { if (line.StartsWith("//###_")) { //other command throw new NotSupportedException(); } else { //collect this line collectAppendStBuilder.AppendLine(line); //read next line i++; line = sourceFile.GetLine(i).TrimStart(); } } } while (true); //finish command ptask.Append(collectAppendStBuilder.ToString()); } break; case PatchCommand.APPPEND_STOP: throw new NotSupportedException(); case PatchCommand.FIND_NEXT_LANDMARK: { i++; string cmd_value = sourceFile.GetLine(i); if (taskId != ptask.TaskId) { throw new NotSupportedException(); } ptask.FindNext(cmd_value); } break; case PatchCommand.FOLLOW_BY: { i++; string cmd_value = sourceFile.GetLine(i); if (taskId != ptask.TaskId) { throw new NotSupportedException(); } ptask.FollowBy(cmd_value); } break; case PatchCommand.SKIP_UNTIL_AND_ACCEPT: { i++; string cmd_value = sourceFile.GetLine(i); if (taskId != ptask.TaskId) { throw new NotSupportedException(); } ptask.SkipUntilAndAccept(cmd_value); } break; case PatchCommand.SKIP_UNTIL_PASS: { //has 2 parameters if (additionalInfo == null) { throw new NotSupportedException(); } // ptask.SkipUntilPass(additionalInfo); } break; default: throw new NotSupportedException(); } } } } return((ptask != null && ptask.CommandCount > 0) ? patchFile : null); }