public static string fDelocalise(string _sPath) { _sPath = _sPath.Replace('\"', ' ');//REmove quote // Debug.fTrace("Deloc: " + _sPath); if (!File.Exists(_sPath)) { Output.TraceError("File not found: " + _sPath); } ConfigMng.oConfig.fAddRecent(_sPath); string _sExtention = Path.GetExtension(_sPath).Trim(); // Debug.fTrace("GetExtension: " + Path.GetExtension(_sPath).ToLower()); switch (_sExtention.ToLower()) { case ".cwmake": case ".cwc": // Debug.fTrace("!!!"); return(fDelocaliseFile(_sPath, _sExtention)); case ".exe": case ".bat": return(fDelocaliseExe(_sPath)); default: Output.TraceError("Unrecognised extention: " + _sExtention); break; } return(""); }
public static bool fManageMessages(CppCmd _oCmd, string _sMsg) { if (_sMsg.IndexOf("Unhandled Exception") >= 0) { Output.TraceError(_sMsg); nError++; return(true); } if (_sMsg.Length >= 3 && _sMsg[1] == '|' && (_sMsg[2] != '/' || _sMsg[2] != '\\')) { string _sMessage = _sMsg.Substring(2).Trim(); switch (_sMsg[0]) { case 'W': Output.TraceWarning(_sMessage); return(true); case 'I': Output.TraceAction(_sMessage); return(true); case 'E': Output.TraceError(_sMessage); nError++; return(true); case 'A': String[] _aMsg = _sMessage.Split('|'); if (_aMsg.Length >= 2) { switch (_aMsg[0]) { case "[C~:Lib]": Output.TraceAction(_sMessage); fAssistCwLib(_sMessage); return(true); case "C~>C++": case "C~2Cpp": case "Cw2Cpp": Output.TraceAction(_sMessage); _oCmd.fAddCompiledObject(_aMsg[1] + ".cpp"); //Know as .cpp object return(true); case "C~:UpToDate": case "CwUpToDate": case "CwUp2Date": Output.TraceColored("\f27C~:Up2Date|\f28" + _aMsg[1]); _oCmd.fAddUpToDateObject(_aMsg[1] + ".cpp"); return(true); } } break; } } return(false); }
public void fExit(LaunchTool _oTool) { if (Data.oLaunchProject.oCurLaunch != null) { Output.TraceError("Exit: " + _oTool.sExeName); Data.oLaunchProject.oCurLaunch = null; Build.EndExecution(); } }
public void fCompressionExit(LaunchTool _oTool) { //Output.TraceWarning("--!!!fCompressionExit!-----: " ); bExtracting = false; fGetLastVersions(); // Output.TraceWarning("-#1: " ); if (oForm != null) { oForm.fExtractProgress(100, ""); } // Debug.fTrace("----------------------fCompressionExit : " ); try { //Debug.fTrace("-Trydelete : " + _oTool.sSourceFile); if (File.Exists(_oTool.sSourceFile)) { File.Delete(_oTool.sSourceFile); // Debug.fTrace("-Deleted : " + _oTool.sSourceFile); } }catch (Exception Ex) { Output.TraceError("--Error: " + Ex.Message); } if (!fCheckForAutoExtractFiles(_oTool)) { bExtact_InProgress = false; // Output.TraceGood("----- Complete All Sub Extraction ------ " ); bSubExtract = false; if (oForm != null) { oForm.fModuleFinish(); } } else { Output.TraceGood("----- Complete " + _oTool.sSourceFile); } if (sName == "Cwc") { //Cwc update now! if (oForm != null) { oForm.fExecuteUpdater(this); } } }
internal static void fUpdated(string _sArg) { if (_sArg == Data.sVersion) { Output.TraceGood("UPDATED TO: " + _sArg); //CleanFolder Thread.Sleep(500); //Wait for update close //TODO add retry ?? FileUtils.DeleteDirectory(PathHelper.GetExeDirectory() + "Upd_Cwc", true); } else { Output.TraceError("UPDATE FAIL TO: " + _sArg); Output.TraceWarning("Current " + Data.sVersion); } }
public static void fPrjOut(string _sLetter, string _sOut) { if (_sOut == null) { return; } string _sPrefix = _sLetter + "> "; if (_sOut.Length > 4) //ex T[1]:xxxx { if (_sOut[1] == '[') { switch (_sOut[0]) { case 'P': Output.TraceGood(_sPrefix + _sOut); break; case 'E': Output.TraceError(_sPrefix + _sOut); break; case 'W': Output.TraceWarning(_sPrefix + _sOut); break; case 'A': Output.TraceAction(_sPrefix + _sOut); break; case 'T': Output.TraceStd(_sPrefix + _sOut); break; default: Output.Trace(_sPrefix + _sOut); break; } return; } } Output.Trace(_sPrefix + _sOut); return; }
public void ReadStdErr() { string _sLine; if (oTool.dError != null) { try { while (!proc.HasExited) { _sLine = proc.StandardError.ReadLine(); if (_sLine != "") { oTool.dError(oTool, _sLine); } else { Thread.CurrentThread.Join(1); } } } catch (Exception e) { Output.TraceError("Error: " + e.Message); } } }
public static void fUpdateFiles(string _sSource) { Base.bAlive = true; //Thread.Sleep(10000); Output.TraceGood("Update Cwc to ver: " + Data.sUpdateVer); string _sBaseSrc = PathHelper.GetExeDirectory(); string _sBaseDest = _sSource; // Output.TraceGood("Copy Tools: " +_sBaseSrc + "Tools/"+ " "+_sBaseDest + "Tools/"); try { FileUtils.CopyFolderContents(_sBaseSrc + "Utils/", _sBaseDest + "Utils/"); //TODO on run pass only? }catch (Exception e) { Output.TraceError(e.Message); } Output.Trace("--- Copy Cwc ----"); //Thread.Sleep(10); //Use Retry int _nCount = 16; int _nRetryCount = _nCount; string _sErrror = ""; while (_nRetryCount > 0) { try { _sErrror = ""; File.Copy(_sBaseSrc + "cwc.exe", _sBaseDest + "cwc.exe", true); //_nRetryCount =0; break; }catch (Exception e) { if (_nRetryCount == _nCount - 1) { Output.TraceWarning(e.Message); Output.TraceWarning("Retrying..."); } else { if (_nRetryCount != _nCount) { Output.TraceWarning(_nRetryCount.ToString()); } } _nRetryCount--; Thread.Sleep(1000); //Output.TraceError(e.GetType().Name);//IOException _sErrror = e.Message; } } if (_sErrror != "") { Output.TraceError("Can't update cwc, please retry later..."); Thread.Sleep(3000); } else { Output.TraceGood("--- Done ----"); // Thread.Sleep(3000); } fRestart(_sBaseDest); //Cwc copy SysAPI.fQuit(); //Console.WriteLine("--- Done ----"); }
public void fGetCompilerList() { if (bGetCompilerList) { return; //Already done } bGetCompilerList = true; Output.TraceAction("Get: " + sName); //fGetCompilerData //Debug.fTrace("fGetCompilerList : " + sCurrFolder + "wType/"); aCompilerData = new List <CompilerData>(); aPlatformData = new Dictionary <string, CompilerData>(); string _sFoundPath = PathHelper.fFindFolder(sCurrFolder, "cwc", 5); if (_sFoundPath == "") //Default { _sFoundPath = sCurrFolder; } // Output.TraceAction("FOund?: " + _sFoundPath); String[] _aFiles = Directory.GetFiles(_sFoundPath, "*.cwcfg"); if (_aFiles.Length == 0) { Output.TraceError("Cannot find '*.cwcfg' file in " + sCurrFolder); Data.bDontExecute = true; Build.StopBuild(); return; } foreach (string _sCwcfg_File in _aFiles) { // Output.TraceGood("Found " + _sCwcfg_File); CompilerData _oCompilerData = new CompilerData(this, _sCwcfg_File); if (bIsCompiler)//It's a Compiler { aCompilerData.Add(_oCompilerData); //Output.TraceGood("Add: " + _oCompilerData.sSubName); aPlatformData.Add(_oCompilerData.sSubName, _oCompilerData); } else //It's a lib { oLibData = _oCompilerData; } } /* * * string _sCompilerPlatform = sCurrFolder+ "wType/"; * if(!Directory.Exists(_sCompilerPlatform)) {//backward compatibility * _sCompilerPlatform = sCurrFolder+ "_sPlatform/"; * } * if(Directory.Exists(_sCompilerPlatform)) { * * string[] _aFile = Directory.GetFiles( _sCompilerPlatform,"*.xml"); * foreach (string _sFile in _aFile){ * // Debug.fTrace("found: " + _sFile); * CompilerData _oCompilerData = new CompilerData(this, _sFile ); * aCompilerData.Add(_oCompilerData); * //Debug.fTrace("Add: " + _oCompilerData.sSubName); * aPlatformData.Add(_oCompilerData.sSubName,_oCompilerData ); * } * if(_aFile.Length == 0){ * Output.TraceError("Compiler " +sAutorName + " 'wType' forlder require xml data"); * Data.bDontExecute = true; * Build.StopBuild(); * } * //Debug.fTrace("---------------------: " ); * }else{ * Output.TraceError("Compiler " + sAutorName + " require '_sPlatform' forlder with xml data"); * Data.bDontExecute = true; * Build.StopBuild(); * } */ }
internal static string fSend2App(CppCmd _oCmd, string _sExplicite_Name, string _sExplicite_App, string _sExplicite_Call, bool _bWaitToFinish = false, List <CppCmd> aSubInputCmd = null) { bool _bFinished = false; if (_bWaitToFinish) { sProcOutputRetrun = ""; } string _sExe = fExtracQuote(_sExplicite_App); string _sArg = fExtracQuote_sArg + " " + _sExplicite_Call; //TODO merge with fSend2Compiler Output.TraceAction(_sExplicite_Name + " => " + _sExplicite_Call); uint _nMyTicket = 0; lock (oLockTicket) { _nMyTicket = nTotalTicket; nTotalTicket++; } if (bHasError || !Data.bNowBuilding) { return(""); } CheckAllThreadsHaveFinishedWorking(); if (bHasError || !Data.bNowBuilding) { return(""); } Interlocked.Increment(ref safeInstanceCount); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args){ if (bHasError || !Data.bNowBuilding) { Interlocked.Decrement(ref safeInstanceCount); return; } StringBuilder output = new StringBuilder(); StringBuilder error = new StringBuilder(); using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) { using (Process process = new Process()) { _oCmd.oCurrProcess = process; _oCmd.sLaunchCmdResult = ""; process.StartInfo.FileName = _sExe; process.StartInfo.Arguments = _sArg; process.StartInfo.CreateNoWindow = true; //process.StartInfo.CreateNoWindow = false; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; if (aSubInputCmd != null) { process.StartInfo.RedirectStandardInput = true; } process.StartInfo.WorkingDirectory = _oCmd.s_pProject; try { process.OutputDataReceived += (sender, e) => { if (e.Data != null) { fCompilerError(e.Data, _sExplicite_Name + " : " + _sExplicite_Call, _nMyTicket, false, _oCmd); } }; process.ErrorDataReceived += (sender, e) => { if (e.Data != null) { fCompilerError(e.Data, _sExplicite_Name + " : " + _sExplicite_Call, _nMyTicket, true, _oCmd); } }; Console.WriteLine("Start " + process.StartInfo.FileName); Console.WriteLine("arg " + process.StartInfo.Arguments); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); fLaunchInputApp(process, aSubInputCmd); process.WaitForExit(); /////////////////////////////////////// ///Wait for displaying in order ////////////////////////////////////////* while (Base.bAlive && Data.bNowBuilding) { Thread.CurrentThread.Join(1); lock (oLockTicket) { if (nCurrentTicket == _nMyTicket) { // Console.WriteLine("*** Process " + nCurrentTicket + " " + _oCmd == null ); fShowSendedCmd(_oCmd); fShowProcOutput(_oCmd); if (nErrorTicket == nCurrentTicket && (nError > 0)) { //Console.WriteLine(":: " + GuiForm.fIsChecked("afterFileErrorToolStripMenuItem")); //TODO TODOTODO fShowProcOutput(_oCmd); Build.StopBuild(); //Dont display other file errors break; } nCurrentTicket++; break; } } } /////////////////////////////////////////////// }catch (Exception e) { Output.TraceError("Error with " + process.StartInfo.FileName + "[" + process.StartInfo.Arguments + "]:" + e.Message); } finally {} try { while (!process.HasExited) { Thread.CurrentThread.Join(1); if (!Data.bNowBuilding) { break; } } }catch (Exception e) {} _bFinished = true; Interlocked.Decrement(ref safeInstanceCount); //safeInstanceCount never decremented if after fAddCommandLineVerificationToDepedancesFile?? on link time : exception? } } }); worker.RunWorkerAsync(); if (_oCmd.bRetryForInput) { while (!_bFinished) { Thread.CurrentThread.Join(1); } if (_oCmd.sLaunchCmdResult == "") { //Recursive call //Thread.Sleep(1); //Minimal wait return(fSend2App(_oCmd, _sExplicite_Name, _sExplicite_App, _sExplicite_Call, _bWaitToFinish, aSubInputCmd)); } return(_oCmd.sLaunchCmdResult); } if (_bWaitToFinish) { while (!_bFinished) { Thread.CurrentThread.Join(1); } return(sProcOutputRetrun.Trim()); } return(""); }
private string fLaunch() { string _sResult = ""; string _sError = ""; /* * if(!File.Exists(sExePath)){ * Output.TraceError("Unable to Launch: " + sExePath); * }*/ processStartInfo = new ProcessStartInfo(Path.GetFullPath(sExePath), sArg); processStartInfo.UseShellExecute = UseShellExecute; //bWaitEndForOutput = true; //Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; ExeProcess = new Process(); // ExeProcess.EnableRaisingEvents = true; // ExeProcess.Exited += new EventHandler(fExited); if (bOutput) { if (!bExterneLaunch) { //processStartInfo.UseShellExecute = false; processStartInfo.UseShellExecute = false; processStartInfo.CreateNoWindow = bHidden; // processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; // processStartInfo.CreateNoWindow = true; processStartInfo.RedirectStandardOutput = bRedirectOutput; processStartInfo.RedirectStandardError = true; processStartInfo.RedirectStandardInput = true; } /* * if(!bWaitEndForOutput) { * ExeProcess.OutputDataReceived += (sender, e) => { * if (e.Data != null) { * fAppOutput(this, e.Data); * } * }; * ExeProcess.ErrorDataReceived += (sender, e) => { * if (e.Data != null) { * fAppError(this, e.Data); * } * }; * }*/ } ExeProcess.StartInfo = processStartInfo; processStartInfo.WorkingDirectory = Path.GetDirectoryName(sWorkPath); bool processStarted = false; if (bStopAll) { bExeLaunched = true; bExeLaunch = false; return(""); } try { if (bHasError) { return(""); } Debug.fTrace("--------Launch: " + sExePath + " " + processStartInfo.Arguments); if (!File.Exists(sExePath)) { Output.TraceError("No executable file found to Launch: \"" + sExePath + "\" " + processStartInfo.Arguments); return(""); } //Debug.fTrace("Arguments: " + processStartInfo.Arguments ); // Debug.fTrace("WorkingDirectory***: " + processStartInfo.WorkingDirectory ); try{ fAddThisToList(); processStarted = ExeProcess.Start(); } catch (Exception e) { Output.TraceError("Unable to Launch: " + sExePath + " [" + sWorkPath + "] : " + e.Message); } if (bDontKill) { Data.nDontKillId = ExeProcess.Id; } bExeLaunched = true; if (!bExterneLaunch && !bWaitEndForOutput) { ProcessOutputHandler outputHandler = new ProcessOutputHandler(this); if (bRedirectOutput) { Thread stdOutReader = new Thread(new ThreadStart(outputHandler.ReadStdOut)); stdOutReader.Start(); } Thread stdErrReader = new Thread(new ThreadStart(outputHandler.ReadStdErr)); stdErrReader.Start(); //stdOutReader.Priority = ThreadPriority.AboveNormal; ExeProcess.WaitForExit(); //Stop here } // if(bWaitEndForOutput) { if (bRedirectOutput) { _sResult += ExeProcess.StandardOutput.ReadToEnd(); } _sError += ExeProcess.StandardError.ReadToEnd(); if (bWaitEndForOutput) { ExeProcess.WaitForExit(); } if (bRedirectOutput && dOut != null && _sResult != "") { dOut(this, _sResult); } if (dError != null && _sError != "") { dError(this, _sError); } /* * }else { * ExeProcess.WaitForExit(); * _sResult += ExeProcess.StandardOutput.ReadToEnd(); * _sError += ExeProcess.StandardError.ReadToEnd(); * if(dOut != null && _sResult != ""){ * dOut(this, _sResult); * } * if(dError != null && _sError != ""){ * dError(this, _sError); * }*/ /* * while(!ExeProcess.HasExited){ * // if (!ExeProcess.StandardOutput.EndOfStream){ * string _sOut = ExeProcess.StandardOutput.ReadLine(); * if(dOut != null && _sOut != ""){ * dOut(this, _sOut); * } * //} * //if (!ExeProcess.StandardOutput.EndOfStream){ * string _sErr = ExeProcess.StandardError.ReadLine(); * if(dError != null && _sErr != ""){ * dError(this, _sErr); * } * //} * Thread.Sleep(1); * } * _sResult += ExeProcess.StandardOutput.ReadToEnd(); * _sError += ExeProcess.StandardError.ReadToEnd(); * * ExeProcess.WaitForExit(); * if(dOut != null && _sResult != ""){ * dOut(this, _sResult); * } * if(dError != null && _sError != ""){ * dError(this, _sError); * }*/ /* * if(bOutput) { * ExeProcess.BeginOutputReadLine();///SLOWWW * ExeProcess.BeginErrorReadLine(); * }*/ // } ExeProcess.WaitForExit(); //important for geting last output! fRemoveThisFromList(); sResult = _sResult; sError = _sError; while (!ExeProcess.HasExited && Base.bAlive) { Thread.CurrentThread.Join(1); } if (dExit != null) { dExit(this); } if (bDontKill && ExeProcess.Id == Data.nDontKillId) { Data.nDontKillId = 0; } /* * if(oForm != null) { * oForm.fLaunchEnd(); * }*/ } catch (Exception ex) { Debug.fTrace(ex.Message); } bExeLaunch = false; // Debug.fTrace("--------------------------- 7z finish -------------------------"); if (bReturnBoth) { return(_sResult + "\n" + _sError); } else { if (!bReturnError) { return(_sResult); } else { return(_sError); } } }
public void fAppOut(LaunchTool _oTool, string _sOut) { //bRunning= false; if (_sOut == null || _sOut == "") { return; } // Output.Trace("Test> " +_sOut); oLaunchProject.bReceiveOutput = true; string _sColor = ""; string _sLetter = "O"; if (bCmdSend) { if (fTestEndOfCommand(_sOut)) { // fTestFrame(_sOut); return; } else { _sLetter = "C"; _sOut = sCurrentCmd; } } // if ( _sOut.StartsWith("Breakpoint") ) { if (_sOut.IndexOf("it Breakpoint ", 0) != -1) //Hit breakpoint { if (_sOut.IndexOf("GDB_Func_ExecuteCmds") != -1) //Special function { _sColor = Output.sGoodColorLite; Output.Trace(_sLetter + "> " + _sColor + _sOut); oProcess.fSend("Continue"); return; } _sColor = Output.sWarningColor; Output.Trace(_sLetter + "> " + _sColor + _sOut); fShowBacktrace(); return; } //Thread 1 received signal SIGSEGV, Segmentation fault. //Program received signal SIGSEGV, Segmentation fault if (_sOut.IndexOf("received signal", 0) != -1) { _sColor = Output.sErrorColor; Output.Trace(_sLetter + "> " + _sColor + _sOut); fShowBacktrace(); return; } Output.fPrjOut(_sLetter, _sColor + _sOut); if (nLimitNbOutput == -1) { Output.TraceError("Error: Output exceed Limit"); } // Output.Trace(_sLetter + "> " +_sColor +_sOut); }
public bool fLaunch(string _sPath, bool _bSanitize = false, string _sSubArg = "") { if (_sPath.Length > 1 && _sPath[_sPath.Length - 1] == '/') //Not a file { Output.TraceError("Path is not a File: " + _sPath); return(false); } // Output.TraceError("Try: " + _sPath); bool _bDebug = true;//Temp bool _bLaunchDebug = false; if (_bDebug) { _bLaunchDebug = true; } // Debug.fTrace("Launch: " + _sPath); // if (oCurLaunch == null) { //We can reLaunch !? => Run button if (File.Exists(_sPath)) { if (Data.oGuiConsole != null) { Data.oGuiConsole.fLaunchPrj(); } oCurLaunch = new LaunchTool(); //oCurLaunch.bWaitEndForOutput = true; // oCurLaunch.bRunInThread = false; oCurLaunch.bRedirectOutput = false; string _sArg = ""; string _sExePath = _sPath; if (Data.fGetGlobalVar("_sPlatform") == "Web_Emsc") { _bDebug = false; // No GDB oCurLaunch.bRedirectOutput = true; oCurLaunch.bHidden = true; oCurLaunch.UseShellExecute = true; // bWeb = true; // bSanitize = false; string _sBrowser = Data.fGetViewIn(); _sArg = "\"" + Data.fGetGlobalVar("vWebRT_Emsc") + "emrun\" "; //_sArg += "--serve_after_close "; //_sArg += "--serve_after_exit "; _sArg += "--browser \"" + _sBrowser + "\" "; //_sArg += "--kill_exit "; //sArg += "--kill_start "; _sArg += "\"" + _sExePath + "\" "; _sExePath = Data.fGetGlobalVar("vWebRT_Python") + "python.exe"; //_sWorkPath = _sExePath; // public } else { //Normal // oCurLaunch.bDontKill = true; //oCurLaunch.UseShellExecute = false; } _sArg += _sSubArg; _sArg = _sArg.Trim(); //Output.TraceWarning("_sSubArg " + _sSubArg); oCurLaunch.dError = new LaunchTool.dIError(fAppError); //Too much error in Emsc? oCurLaunch.dOut = new LaunchTool.dIOut(fAppOut); oCurLaunch.dExit = new LaunchTool.dIExit(fExit); string _sPrintArg = ""; if (_sArg != "") { _sPrintArg = " [" + _sExePath + " " + _sArg + "]"; } if (_bLaunchDebug) { Output.TraceAction("Debug: " + _sPath + _sPrintArg); } else { Output.TraceAction("Run: " + _sPath + _sPrintArg); } if (_bDebug) { //Better way? string _sCompiler = Data.fGetGlobalVar("_wToolchain"); string _sPlatform = Data.fGetGlobalVar("_sConfig_Type"); CompilerData _oCompiler = Finder.fUseCompiler(_sCompiler, _sPlatform); string _sDebugger = _oCompiler.oGblConfigType.fGetNode(null, new string[] { "Exe", "Debugger" }, ""); GDB _oGdb = new GDB(this, oCurLaunch, _sDebugger, _sExePath, _oCompiler, _sArg); //Create debugger proxy } else { oCurLaunch.fLaunchExe(_sExePath, _sArg); } //_oPreload.dExit = new LaunchTool.dIExit(fUrlRequestComplete); // Output.TraceWarning("------------------------"); /* * oCurLaunch.oForm = this; * oCurLaunch.bSanitize = _bSanitize; * oCurLaunch.fLaunchExe(_sPath); */ return(true); } else { Output.TraceError("Executable not found: " + _sPath); } // } return(false); }
public static void fSend2Compiler(string _sArg, bool _bLinkTime = false, bool _bCompileAndLink = false, CppCmd _oCmd = null, string _sAllFile = "") { //string _sPlatform = _oCmd.oParent.sPlatform; string _sPlatform = _oCmd.oParent.fGetVar("_sPlatform"); if (_oCmd.oCompiler == null) { //Debug.fTrace("Unknow Compiler"); Output.TraceError("Unknow Compiler"); return; } string _sInfo = ""; if (_oCmd != null && _bLinkTime) { if (_oCmd.bToStaticLib) { _sInfo = " [Static_Link]"; } else if (_oCmd.bToDynamicLib) { _sInfo = " [Dynamic_Link]"; } else { _sInfo = " [Link]"; } } string _sObjectList = ""; if (_sAllFile != "") { _sObjectList = "[\f1B" + _sAllFile + "\f1F]"; } string _sFinalArg = _sArg.Replace("\\\"", "\""); _sFinalArg = _sFinalArg.Replace("%%", "¶"); //A way to keep % _sFinalArg = _sFinalArg.Replace('%', '\\'); //Backslash special char % transform, we must have a ways to send backslash to compiler _sFinalArg = _sFinalArg.Replace('¶', '%'); //A way to keep % _oCmd.sCommandToShow = "\f1F (" + _oCmd.sExecutableName + _oCmd.sExecutableType + _sInfo + ")" + _sObjectList + " " + _sFinalArg; uint _nMyTicket = 0; lock (oLockTicket) { _nMyTicket = nTotalTicket; nTotalTicket++; } if (bHasError || !Data.bNowBuilding) { return; } CheckAllThreadsHaveFinishedWorking(); if (bHasError || !Data.bNowBuilding) { return; } Interlocked.Increment(ref safeInstanceCount); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args) { if (bHasError || !Data.bNowBuilding) { Interlocked.Decrement(ref safeInstanceCount); // Debug.fTrace("Dec " + safeInstanceCount); return; } StringBuilder output = new StringBuilder(); StringBuilder error = new StringBuilder(); using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) { using (Process process = new Process()) { process.StartInfo.FileName = _oCmd.sExecutable; process.StartInfo.Arguments = _sFinalArg; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.WorkingDirectory = _oCmd.s_pProject; try { if (process.StartInfo.FileName.Length + process.StartInfo.Arguments.Length >= 32700) // Command line size limitation, real 32768 //Todo verify for .wdat folder? { process.StartInfo.Arguments = "@.wdat/arg.wdat"; File.WriteAllText(@".wdat/arg.wdat", _sFinalArg); } process.OutputDataReceived += (sender, e) => { if (e.Data != null) { fCompilerError(e.Data, _sArg, _nMyTicket, false, _oCmd); } }; process.ErrorDataReceived += (sender, e) => { if (e.Data != null) { fCompilerError(e.Data, _sArg, _nMyTicket, true, _oCmd); } }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); /////////////////////////////////////// ///Wait for displaying in order ////////////////////////////////////// while (Base.bAlive && Data.bNowBuilding) { Thread.CurrentThread.Join(1); lock (oLockTicket) { if (nCurrentTicket == _nMyTicket) { fShowSendedCmd(_oCmd); fShowProcOutput(_oCmd); if (nErrorTicket == nCurrentTicket && (nError > 0)) //&& GuiForm.fIsChecked("afterFileErrorToolStripMenuItem") //TODO { fShowProcOutput(_oCmd); Build.StopBuild(); //Dont display other file errors break; } nCurrentTicket++; break; } } } //////////////////////////////////// }catch (Exception e) { Output.TraceError(e.Message); string _sSended = process.StartInfo.FileName + " " + process.StartInfo.Arguments; Output.TraceAction(_sSended); if (_sSended.Length >= 32768) { Output.TraceWarning("You may have exceeded the maximum command line size of 32768 characters: " + _sSended.Length + " chars"); } Interlocked.Decrement(ref safeInstanceCount); return; } while (!process.HasExited) { Thread.CurrentThread.Join(1); if (!Data.bNowBuilding) { break; } } Interlocked.Decrement(ref safeInstanceCount); //safeInstanceCount never decremented if after fAddCommandLineVerificationToDepedancesFile?? on link time : exception? if (_oCmd != null && !_bLinkTime) { _oCmd.fAddCommandLineVerificationToDepedancesFile(_oCmd); //TODO is infinite loop? } } } }); worker.RunWorkerAsync(); }
public void fExtractOut(LaunchTool _oThis, string _sMsg) { //Debug.fTrace(_sOut); if (!FileUtils.IsEmpty(_sMsg)) { string[] _aResult = _sMsg.Split('\n'); bool _bError = false; bool _bGood = false; if (_sMsg.IndexOf("Can not") >= 0 || _sMsg.IndexOf("Can't") >= 0 || _sMsg.IndexOf("Unexpected") >= 0 || _sMsg.IndexOf("ERROR") >= 0 || _sMsg.IndexOf("Error ") >= 0 || _sMsg.IndexOf("Error:") >= 0) { _bError = true; // Output.TraceError( "--- [" + _oThis.sArg + "] ---" ); } else if (_sMsg.IndexOf("Everything is Ok") >= 0) { _bGood = true; } foreach (string _sOutput in _aResult) { string _sOut = _sOutput.Trim(); if (_sOut == "") { continue; } Debug.fRPrint("Extract: " + _sOut + " "); if (_bGood) { Output.TraceGood(_sOut); } else if (_bError) { Output.TraceError(_sOut); } else { Output.TraceWarning("\rExtract[" + _oThis.oModule.sName + "]: " + _sOut); } if (_sOut.IndexOf("Extracting") != -1) { bExtracting = true; } else if (bExtracting) { string [] _aExtInfo = _sOut.Split('%'); if (_aExtInfo.Length >= 2) { string _sNumber = _aExtInfo[0].Trim(); int _nValue = 0; //Debug.fTrace("TryParce: " + _sNumber); if (Int32.TryParse(_sNumber, out _nValue)) { if (oForm != null) { oForm.fExtractProgress(_nValue, _aExtInfo[1]); } } } } } } }
public static void fCreateGUI() { // Console.WriteLine("fCreateGUI"); /* * if (SysAPI.bIsLoadedFromAnotherCwcInstance || Data.bModeIDE) { //Not GUI * return; * }*/ //if(Data.oMsgForm == null) { Empty.bHaveMsgForm = true; Thread winThread = new Thread(new ThreadStart(() => { try { Application.EnableVisualStyles(); // Application.SetCompatibleTextRenderingDefault(false); //Bug in W10 GuiConsole _oConsole = new GuiConsole(); Application.Run(_oConsole); }catch (Exception Ex) { // Console.WriteLine("Error: " + Ex.Message + " : " +Ex.Source + " : " +Ex.StackTrace); Output.TraceError("Error: " + Ex.Message + " : " + Ex.Source + " : " + Ex.StackTrace); } })); winThread.SetApartmentState(ApartmentState.STA); // winThread.IsBackground = true; winThread.Start(); Thread.CurrentThread.Join(1); while (Base.bAlive && Data.oGuiConsole == null) { Thread.CurrentThread.Join(1); } /* * while(Data.oMsgForm == null) { * Thread.Sleep(1); * } * * while( Data.oGuiForm== null) { * Thread.Sleep(1); * }*/ // fDebug("finish"); // fActivate(); /* * while(Data.oMsgForm == null) { //Null protection * Thread.Sleep(1); * }*/ /* * while(!oMainForm.bPositionSet) { //Wait initialise * Thread.Sleep(1); * }*/ /////////////////////////// // } }
public static void CopyFolderContents(string sourceFolder, string destinationFolder, string mask = "*.*", string _sExept = "", Boolean createFolders = true, Boolean recurseFolders = true) { Output.TraceAction("Copy: " + sourceFolder + " to " + destinationFolder); try { if (!(sourceFolder.EndsWith(@"\") || sourceFolder.EndsWith(@"/"))) { sourceFolder += @"\"; } sourceFolder = Path.GetFullPath(sourceFolder); string _sSingleFile = ""; bool _bSourceIsFile = false; if (!Directory.Exists(sourceFolder)) { if (File.Exists(sourceFolder)) //It's a file from source { _sSingleFile = sourceFolder.Substring(0, sourceFolder.Length - 1); sourceFolder = new FileInfo(_sSingleFile).Directory.FullName + "\\"; _bSourceIsFile = true; } else { return; //No source } } string _sDestFileName = ""; if (!_bSourceIsFile) { if (!(destinationFolder.EndsWith(@"\") || destinationFolder.EndsWith(@"/"))) { destinationFolder += @"\"; } } else //Source is a file { if ((destinationFolder.EndsWith(@"\") || destinationFolder.EndsWith(@"/"))) { destinationFolder += Path.GetFileName(sourceFolder); } else { //Debug.fTrace("destinationFolder " + destinationFolder); FileInfo _oFile = new FileInfo(destinationFolder); destinationFolder = _oFile.Directory.FullName + "\\"; //Debug.fTrace("----destinationFolder " + destinationFolder); _sDestFileName = _oFile.Name; } } destinationFolder = Path.GetFullPath(destinationFolder); var exDir = sourceFolder; var dir = new DirectoryInfo(exDir); string [] _aSourceFile; if (_bSourceIsFile) { _aSourceFile = new string[] { _sSingleFile }; } else { SearchOption so = (recurseFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); string _sDir = dir.ToString(); if (_sExept == "") { _aSourceFile = Directory.GetFiles(_sDir, mask, so); } else { _aSourceFile = Directory.GetFiles(_sDir, mask, so).Except(Directory.GetFiles(_sDir, _sExept, so)).ToArray(); } } // foreach (string sourceFile in Directory.GetFiles(dir.ToString(), mask, so).Where(file => Regex.IsMatch(file, @"^.+\.(cpp|hpp|hxx|gcpp|icpp|c|h)$")) ) foreach (string sourceFile in _aSourceFile) { FileInfo srcFile = new FileInfo(sourceFile); string srcFileName = srcFile.Name; // Create a destination that matches the source structure string _sFileRelPath = _sDestFileName; if (_sDestFileName == "") { _sFileRelPath = srcFile.FullName.Replace(sourceFolder, ""); } FileInfo destFile = new FileInfo(destinationFolder + _sFileRelPath); if (!Directory.Exists(destFile.DirectoryName) && createFolders) { Directory.CreateDirectory(destFile.DirectoryName); } if (!destFile.Exists || srcFile.LastWriteTime > destFile.LastWriteTime) { File.Copy(srcFile.FullName, destFile.FullName, true); Output.Trace("\f3FCopy: \f37 " + _sFileRelPath); } } } catch (Exception ex) { // System.Diagnostics.Debug.WriteLine(ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace); //Debug.fTrace("Error copy: " + ex.Message + " " + ex.StackTrace); Output.TraceError("Error copy: " + ex.Message + " " + ex.StackTrace); } }
public static string fExpand(string _sFullArg, int _nIndex) { // Debug.fTrace("---fExpand!!!!! " + _sFullArg); //List<string> _sList = new List<string> (); string _sResult = ""; int _nSartIndex = 0; int _nEndIndex = 0; int _nIndexOfA = _nIndex; ///////////////////////////////// Begin with @ while (_nIndexOfA != -1) { _sResult += _sFullArg.Substring(_nSartIndex, _nIndexOfA - _nSartIndex); _nEndIndex = fGetEndFile(_sFullArg, _nIndexOfA + 1); string _sFile = _sFullArg.Substring(_nIndexOfA + 1, _nEndIndex - (_nIndexOfA + 1)); //Debug.fTrace("-****************************!!!fExpand " + _sFile); if (_sFile == "wDeloc") //Special deloc command to quit //Debug.fTrace("!!!---DELOCATISE!!!!!"); { _sFullArg = _sFullArg.Replace("@wDeloc", ""); //remove all wDeloc Console.Error.WriteLine("wOut|" + _sFullArg); //Use special stream to resend args SysAPI.fQuit(true); } string _sPath; if (_sFile.Length > 2 && _sFile[1] == ':') //Absolute path { _sPath = _sFile; } else { _sPath = PathHelper.ExeWorkDir + _sFile; //Relative path } string _sText = ""; string _sExt = Path.GetExtension(_sPath).ToLower(); try { switch (_sExt) { case ".bat": case ".exe": _sText = Delocalise.fDelocalise(_sPath); break; default: _sText = File.ReadAllText(_sPath); break; } }catch (Exception Ex) { Output.TraceError("Error Expand File: " + Ex.Message + " : " + _sPath); }; _sResult += _sText; _nSartIndex = _nEndIndex; // _nSartIndex = _nEndIndex; _nIndexOfA = _sFullArg.IndexOf('@', _nEndIndex); } _sResult += _sFullArg.Substring(_nEndIndex, _sFullArg.Length - _nEndIndex); /* * string[] _aFiles = _sFullArg.Split('@'); * foreach(string _sFileArg in _aFiles) { * * int _nIndex = _sFileArg.IndexOf(' '); * if(_nIndex == -1) { * _nIndex = _sFileArg.IndexOf('\t'); //TODO make "OR" combinaison * } * if(_nIndex == -1) { * _nIndex = _sFileArg.IndexOf('\n'); * } * if(_nIndex == -1) { * _nIndex = _sFileArg.IndexOf('|'); * } * if(_nIndex == -1) { * _nIndex = _sFileArg.IndexOf('>'); * } * if(_nIndex == -1) { * _nIndex = _sFileArg.Length; * } * * string _sFile = _sFileArg.Substring(0, _nIndex); * * string _sPath = PathHelper.GetCurrentDirectory() + _sFile; * string _sText = ""; * try { * _sText = File.ReadAllText(_sPath); * }catch(Exception Ex) {}; * * string _sArg = _sFileArg.Substring(_nIndex); * _sResult += _sText + _sArg; * * * } */ // return _sResult.Replace('\n', ' '); // return _sResult.Replace('\n', ' ').Replace('\r', ' '); return(_sResult); }
public static void fHttpOutInfo(LaunchTool _oTool, string _sOut) { ParamHttp _oParam = (ParamHttp)_oTool.oCustom; //_oParam.sResult = _sOut; _oParam.sInfo += _sOut + "\n"; //_oParam //Debug.fTrace("E: " + _sOut); //"Length:" if (_oParam.bDownloadFile) { int _nLimit = -1; if (_sOut.Length > 7 && _sOut[0] == 'L' && _sOut[6] == ':') { string _sLength = _sOut.Substring(8); //Debug.fTrace("_sLength: " + _sLength); string _sSubLength = _sLength; int _nEnd = _sSubLength.IndexOf(' '); if (_nEnd != -1) { _sSubLength = _sSubLength.Substring(0, _nEnd); } int.TryParse(_sSubLength, out _nLimit); // Debug.fTrace("--Total!! " + _nLimit); } _oParam.nTotalBytes = _nLimit; // Debug.fTrace("--_sOut[_sOut.Length - 1 ]!! " + _sOut[_sOut.Length - 1 ]); if (_sOut[_sOut.Length - 1] == 's') { int _nEnd = _sOut.IndexOf('K'); if (_nEnd != -1) { string _sBytes = _sOut.Substring(0, _nEnd); int _nByte = -1; int.TryParse(_sBytes, out _nByte); _oParam.nBytes = _nByte * 1000; // Debug.fTrace("--nBytes!! " + _oParam.nBytes); fUrlProgress(_oParam); } } // if(Data.oGuiConsole != null){ Data.oGuiConsole.Fctb.RemoveLines(aLineToDelete); aLineToDelete.Clear();} _sOut = _sOut.Trim(); if (_sOut != "") { if (_sOut.IndexOf("Cannot") >= 0 || _sOut.IndexOf("Bad") >= 0) { Output.TraceError("\rDownload: " + _sOut); } else { Output.TraceAction("\rDownload: " + _sOut); } } // if(Data.oGuiConsole != null){ aLineToDelete.Add( Data.oGuiConsole.Fctb.LinesCount-1); } Debug.fRPrint("Download: " + _sOut + " "); } //// _oParam.oHeader = _response.Headers; }
public static bool fLoadModules(bool _bAutoStart = true) { bool _bFound = true; if (Data.oGuiConsole != null) { Data.bIWantGoToEnd = true; GuiConsole.sFormCmd = "GoEnd"; //fctbConsole.GoEnd(); } nLoadModuleIndex = 0; foreach (string _sModule in Data.aRequiredModule) { ModuleData _oModule = ModuleData.fFindModule(_sModule); _oModule.fGetLocalVersions(); // Http.fGetHttp( _oModule.sUrl_Project , fGetProjectData);//Get readme _oModule.fReadHttpModuleTags(); } //Wait to finish while (ModuleData.nRequestTag > 0) { Thread.CurrentThread.Join(1); } List <ModuleLink> _aLink = new List <ModuleLink>(); foreach (string _sModule in Data.aRequiredModule) { ModuleData _oModule = ModuleData.fFindModule(_sModule); if (_oModule.aLinkList.Count > 0) { foreach (string _sKeyLink in _oModule.aLinkList) { // Output.TraceWarning( "Recommended version:"); Output.TraceAction("Recommended version:" + _oModule.sName + " : " + _sKeyLink); _aLink.Add(_oModule.aLink[_sKeyLink]); break; } } else { Output.TraceError("Not found:" + _sModule); _bFound = false; } } if (_aLink.Count > 0) { // Output.TraceWarning( "Download? (yes / no)"); Output.TraceWarning("Starting Download ... (press 'n' to cancel)"); foreach (ModuleLink _oLink in _aLink) { _oLink.fDownload(); while (_oLink.bDl_InProgress) { Thread.CurrentThread.Join(1); } _oLink.fExtract(); while (_oLink.oModule.bExtact_InProgress) { Thread.CurrentThread.Join(1); } } Output.Trace(""); Output.TraceGood("---------------- All Required Module Completed ------------------"); foreach (ModuleLink _oLink in _aLink) { Output.TraceAction(_oLink.oModule.sCurrFolder); } Output.TraceGood("-----------------------------------------------------------------"); if (_bAutoStart) { Data.sCmd = "StartBuild"; } } return(_bFound); /* * foreach(ModuleLink _oLink in _aLink) { * _oLink.fExtract(); * } */ // Data.oMsgForm.fLoadNextModule(); }