//***************************************************************************************** // Copyright (c) 2003 Wil van Antwerpen // All rights reserved. // // $FileName : D:\Entwicklung\SharedClasses\cApplicationEx.pkg // $ProjectName : // $Author : WvA / Mk // $Created : 10.03.2003 19:25 // // Contents: // Is a cWorkSpaceEx class which has some additional features such as: // // -Dynamic WorkSpaceName // if in the StartUpDirectory a file named "WorkSpace.Inf" exists the 1st line // is read and the WorkSpace name is set to this value. // // -CmdLine Support. (if piCmdLineSupport=true) // Function CmdLine_Count returns integer // Number of CmdLine Parameters // Function CmdLine_Value integer iNr returns string // Value of the CmdLineParameter // // Extended CommandLine abilities: (Register commandline commands) // send RegisterCommand "NAME1" Msg_XX1 iDestObject1 sDescription1 // send RegisterCommand "NAME2" Msg_XX2 iDestObject2 sDescription2 // ... // send RegisterCommand "NAMEX" Msg_XXX iDestObjectX sDescriptionX // // -? is also supported. // // // $Rev History // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Use cApplication.Pkg // The Std DF cApplication Class. Use cCmdLine_Mixin.Pkg // Some additional abilities with uding CommandLine parameters. Use mPointer.Pkg // For an easier Buffer Handling. #IF (!@ > 182) Use cConnectionManager.pkg //@ RRS Added: Managed Connection #ENDIF Use vWin32fh.pkg Use cSourceFilesList.pkg Struct tTH3DB Boolean bIsOpen // TH3 file is open Boolean bReOpen // non TH3 file should be reopened after close TH3 file End_Struct struct tPerfCounter Integer eOperation String sComment Boolean bStarted DateTime dtStart Boolean bStopped DateTime dtStop end_struct Define CPC_OpenFile For 1 // perfcounter on open file Define CPC_BuildCodeExplorer For 2 // perfcounter on the code explorer Define CPC_ChangeWorkspace For 3 // perfcounter on changing the workspace Define CPC_Reindent For 4 // reindent // Gets the startuppath from the VDF program. Function VDFStartUpPath Global Returns String Handle hModule Integer iRet String sFile sDir sTmp Pointer pFile Move (Repeat(Character(0),255)) To sFile Move (addressOf(sFile)) To pFile Move (GetModuleHandle(0)) To hModule Move (GetModuleFileName(hModule,pFile,255)) To iRet Move (CString(sFile)) To sFile Move (Lowercase(sFile)) to sFile // By SVN on 28/04/2017 // This does not work for any file except HAMMER.EXE //Move (Left(sFile,Length(sFile)-10)) To sFile While (sFile contains "\") Move (Left(sFile, Pos("\", sFile))) to sTmp Move (Replace(sTmp, sFile, "")) to sFile Move (sDir+sTmp) to sDir Loop Function_Return sDir //sFile End_Function Class cApplicationEx Is a cApplication Import_Class_Protocol cCmdLine_Mixin Procedure Construct_Object Forward Send Construct_Object String sPath // Controls if the CmdLine should be checked. Property Integer piCmdLineSupport False Property tTH3DB[] pTH3DB // The Path where the DFRUN is located. Move (VDFStartUpPath()) To sPath Property String psVDFStartUpPath (VDFStartUpPath()) Property tTHWorkspace pTHWorkspace Property tTHCompiler[] pTHCompilers // The Bitmap- and Programpath of TH itself // needed for Registering the File-Types with Windows Explorer // 2.1.2004 BP Property String psStartupProgramPath "" Property String psStartupBitmapPath "" Property tPerfCounter[] pPerfCounter Property Boolean pbWorkspaceChanged False // Create the cCmdLine_mixin memebers. Send Define_cCmdLine_Mixin // This is default so it _is_ set, but make it clear we are using it. Set pbUseWindowsFont To True End_Procedure // Looks in the current directory if a file "WorkSpace.Inf" exists and if so // reads the WorkSpaceName out of it. Procedure TryRenameWorkSpace String sWrkSpc Direct_Input (psVDFStartUpPath(Self)+"\Workspace.Inf") [seqeof] Direct_Input ".\Workspace.Inf" Readln sWrkSpc [Not seqeof] Begin Set psWorkSpaceName Of (phoWorkspace(Self)) To sWrkSpc End Close_Input End_Procedure // -Declares the standard commandline commands // -Runs the whole commandline Procedure End_Construct_Object Send TryRenameWorkSpace If (piCmdLineSupport(Self)) Begin Send RegisterStandardCommands Send RunCmdLine End Forward Send End_Construct_Object Set psStartupProgramPath to (psProgramPath(phoWorkspace(self))) Set psStartupBitmapPath to (psBitmapPath(phoWorkspace(self))) End_Procedure // // Some functionality to measure performance statistics // Function StartPerfCounter Integer eOperation String sComment Returns Integer DateTime dtStart Integer iCounter tPerfCounter[] PerfMon Get pPerfCounter to PerfMon Move (SizeOfArray(PerfMon)) To iCounter // counter to use Move (CurrentDateTime()) To dtStart Move True To PerfMon[iCounter].bStarted Move dtStart To PerfMon[iCounter].dtStart Move eOperation To PerfMon[iCounter].eOperation Move sComment To PerfMon[iCounter].sComment Set pPerfCounter to PerfMon Function_Return iCounter End_Function Procedure StopPerfCounter Integer iCounter DateTime dtStop tPerfCounter[] PerfMon Move (CurrentDateTime()) To dtStop Get pPerfCounter to PerfMon If (iCounter0) Begin For iCounter from 0 To (iSize-1) Get PerfOperationToString PerfMon[iCounter].eOperation to sOperation If (PerfMon[iCounter].bStarted and PerfMon[iCounter].bStopped) Begin Move (PerfMon[iCounter].dtStop - PerfMon[iCounter].dtStart) To tsTime Move (SFormat("%1:%2:%3.%4",SpanHours(tsTime), SpanMinutes(tsTime), SpanSeconds(tsTime), SpanMilliseconds(tsTime))) to sSpanTime End Else Move "?:?:?.???" To sSpanTime Showln sOperation " " PerfMon[iCounter].sComment " " sSpanTime Loop End End_Procedure Function FindFirstFileInTHWorkspaceFolder String sFile Returns String Integer iFolder Integer iFolders Integer iFile Integer iFiles String sPath String sSearchFile String sFileName String[] Files tTHWorkspace THWorkspace Move "" To sFileName Get pTHWorkspace of ghoApplication To THWorkspace Move (SizeOfArray(THWorkspace.saFolders)) to iFolders For iFolder from 0 to (iFolders-1) If (iFolder>0) Begin // iFolder=0 == [current workspace] so skip that one Move THWorkspace.saFolders[iFolder] To sPath Get vFolderFormat sPath to sPath Send SearchDirectory of oSourceFilesList (sPath+"*.*") True (&Files) End Loop Move (SizeOfArray(Files)) To iFiles If (iFiles>0) Begin For iFile From 0 To (iFiles-1) Get ParseFileName Files[iFile] to sSearchFile If (Lowercase(sFile)=Lowercase(sSearchFile)) Begin Move Files[iFile] To sFileName Move iFiles To iFile // stop loop End Loop End Function_Return sFileName End_Function End_Class