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); }
internal static void fLaunchInputApp(Process _oToInputProcess, List <CppCmd> aSubInputCmd) { foreach (CppCmd _oCmd in aSubInputCmd) { _oCmd.oToInputProcess = _oToInputProcess; Output.TraceWarning("Launch Input App: " + _oCmd.sExplicite_App + ":" + _oCmd.sExplicite_Call); _oCmd.fExecute(); } }
public void fShowBacktrace() { if (!bShowedBacktrace) { bShowedBacktrace = true; // fSendCmd("GlobalVar", "info variables"); //Too heavy? Output.TraceWarning("--- Backtrace ---"); fSendCmd("backtrace", "bt full", false, 0);//1500, give time to reveive stdout before TODO find a better way } }
public static void fShowResult(OutToken _oOut) { string _sOut = _oOut.sOut; CppCmd _oCmd = _oOut.oFrom; if (Data.bNowBuilding) { if (fManageMessages(_oCmd, _sOut)) { return; } if (_oOut.eType == OutType.Undefined) { Output.TraceUndefined(_sOut); return; } if (_oOut.eType == OutType.Warning) { Output.TraceWarningLite(_sOut); return; } if (_oOut.eType == OutType.Error) { Output.TraceErrorLite(_sOut); return; } //Add color manually if (_sOut.Length > 8) { if (_sOut[7] == ':') //no color by default { bool bFound = false; string _sCmd = _sOut.Substring(0, 7).ToLower(); switch (_sCmd) { case "warning": bFound = true; Output.TraceWarning(_sOut); break; } } } string _sResult = Output.Trace(_sOut, true); /* * if( Data.oMainForm != null) { * Data.oMainForm.fAddItem(_sResult); * }*/ } }
public static CompilerData fGetCompiler(string _sVar, string _sType = "", bool _bIsSubCompiler = false) { if (_sType == "") { _sType = "Default"; } // Output.TraceWarning("fGetCompiler _sVar " +_sVar); //Extract Square subtype ex:LibRT[Clang] if not already done if (_sVar.Length > 3 && _sVar[_sVar.Length - 1] == ']') { int _nIndex = _sVar.IndexOf('['); if (_nIndex > 0) { _sType = _sVar.Substring(_nIndex + 1, _sVar.Length - 1 - (_nIndex + 1)); _sVar = _sVar.Substring(0, _nIndex); } } if (!_bIsSubCompiler) { Data.fSetGlobalVar("_sConfig_Type", _sType); } if (Data.aCompilerData.ContainsKey(_sVar)) { // CompilerData _oCompiler = aCompilerData[_sVar]; ModuleData _oCompiler = Data.aCompilerData[_sVar]; // Output.TraceWarning("_oCompiler " + _oCompiler.sAutorName + " : " + _sType + " : " +_oCompiler.aPlatformData.Count ); if (_oCompiler.aPlatformData.ContainsKey(_sType)) { CompilerData _oPlatform = _oCompiler.aPlatformData[_sType]; return(_oPlatform); } else { Output.TraceWarning("Compiler Type not exist: " + _sVar + " (" + _sType + "), switch to Default..."); _sType = "Default"; if (_oCompiler.aPlatformData.ContainsKey(_sType)) { CompilerData _oPlatform = _oCompiler.aPlatformData[_sType]; return(_oPlatform); } return(null); } } // Output.TraceWarning("Compiler not found " +_sVar); //Output.TraceError("Compiler not exist: " + _sVar + " (" + _sPlatform + ")"); return(null); }
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 static void fDelocaliseCmd() { //Reset all -> Already clear in Data.fClearData() /* * Data.aVarGlobal.Clear(); * Data.fSetDefaultVar(); * if(Data.oGuiConsole != null) { * Data.oGuiConsole.fLoadData(); * }*/ Output.TraceWarning("Launch " + sDelocaliseCmd); string _sText = Delocalise.fDelocalise(sDelocaliseCmd); Data.sArgExpand = ArgProcess.fExpandAll(_sText); Data.sCmd = "StartBuild"; Data.bForceTestNextCmd = true; }
public bool fCheckForAutoExtractFiles(LaunchTool _oTool) { if (_oTool.oCustom == null) //Not for sub extract items (Only master extact get auto sub extract) //Master! // Debug.fTrace("Target: " + _oTool.sTarget ); { aFileAutoExtract = Directory.GetFiles(_oTool.sTarget, "*.-ex", SearchOption.AllDirectories); //**TODO _oTool.sTarget contain all libs version, todo optimise to the current extraction ** nTotalExtract = aFileAutoExtract.Length; nExtracted = 0; Output.TraceWarning("SubFile to extract: " + nTotalExtract + ""); // foreach (string _sFile in _aFileAutoExtract) { // } } else { nExtracted++; Output.TraceWarning("----- Complete " + _oTool.sSourceFile + " (" + nExtracted + "/" + nTotalExtract + ")"); } if (nExtracted != nTotalExtract) { bSubExtract = true; string _sFile = aFileAutoExtract[nExtracted]; string _sFileDirectory = Path.GetDirectoryName(_sFile); sCurrentExtractFile = Path.GetFileName(_sFile); fExtractSevenZip(_sFile, _sFileDirectory, _sFileDirectory, _oTool.oModule, true); } // bool bLastOne = false; if (nExtracted == nTotalExtract) { return(false); } return(true); }
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 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(); }
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 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(); }