//TH-Header //***************************************************************************************** // Copyright (c) 2005 KURANT Project // All rights reserved. // // $FileName : cSortArray.pkg // $ProjectName : The Hammer v 2.0 // $Author : Wil van Antwerpen // $Created : 03.12.2005 10:18 // $Type : OptionWare // // Contents: // For whatever stupid reason sorting the array using item_sort doesn't work // This was supposed to be fixed in VDF7 SP3, since this is just // for a little bit of data, implementing a sorting algorithm is // our quickest catch-it-all workaround that will work for ALL // vdf versions. // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Use cWorkspaceHandlerEx.pkg Use cSystemStrUtils.pkg Use vWin32fh.pkg // *WvA Oct 14, 2005 Renamed from cSortArray into cWorkspaceSortArray // in order to avoid a naming conflict with the sort array used in // filelist.vw Class cWorkspaceSortArray Is a Array Procedure Construct_Object Forward Send Construct_Object Property Boolean pbCheckRuntimeInstalled false End_Procedure // Construct_Object // Private // Used by bubblesort algo // Procedure DoSwapValues Integer iFirst Integer iSecond String sFirst String sSecond Get Value Item iFirst To sFirst Get Value Item iSecond To sSecond Set Value Item iFirst To sSecond Set Value Item iSecond To sFirst End_Procedure // DoSwapValues // Private // Use by bubblesort algo, fixed to sort on integer values // Function SortRequired Integer iFirst Integer iSecond Returns Boolean Integer iLeft Integer iRight Boolean bSort Get Value Item iFirst To iLeft Get Value Item iSecond To iRight Move (iLeft>iRight) To bSort Function_Return bSort End_Function // SortRequired Procedure BubbleSort Integer j Integer iCount Integer iLoop Boolean bSorted Boolean bSortRequired Move (False) To bSorted Move (Item_Count(Self)) To iCount Move iCount To iLoop While ((iLoop > 0) And (Not(bSorted))) Move (True) To bSorted For j From 0 To (iLoop-2) Get SortRequired j (j+1) To bSortRequired If (bSortRequired) Begin Send DoSwapValues j (j+1) Move (False) To bSorted End Loop Decrement iLoop Loop End_Procedure // BubbleSort Function VDFversion Integer iItem Returns String Integer iVersion Integer iMajor Integer iMinor String sVersion Get Value Item iItem To iVersion If (iVersion>=80) Begin Move (mod(iVersion,10)) To iMinor Move (iVersion/10) To iMajor Move (String(iMajor)+"."+String(iMinor)) To sVersion End Else Begin // Pre VDF8 versions are only denominated by // their main version number (no concurrent VDF7 versions can be running on the same system) Move (String(iVersion/10)) To sVersion End Function_Return sVersion End_Function // VDFversion Function IsStringNumeric String sData Returns Boolean Handle hoStr Boolean bIsNumeric Move False to bIsNumeric Get Create (RefClass(cSystemStrUtils)) To hoStr If (hoStr) Begin Get IsNumeric Of hoStr sData To bIsNumeric Send Destroy Of hoStr End Function_Return bIsNumeric End_Function // IsStringNumeric Function VirtualMachineName String sVersion Returns String String sBaseName String sSuffix String sVMName Number nVersion Integer iPos Get StringVdfVersionToNum Of ghoWorkspaceHandlerEx sVersion To nVersion If (nVersion>=8.0) Move "vdfvm" to sBaseName Else Move "dfrun" To sBaseName Move (Pos(".",sVersion)) To iPos If (iPos>0) Move (Left(sVersion,iPos-1)) To sSuffix Else Move sVersion To sSuffix Move (sBaseName+sSuffix+".dll") To sVMName Function_Return sVMName End_Function // VirtualMachineName // // Current VDF installers completely wipe the registry of their presence after an uninstall. // Older VDF setups did not do that, besides having a broken VDF setup listed as a "valid VDF" // is not that useful. // This check queries the VDF registry for the vdfrootdir and see if the // dfrunXX.dll/vdfvmXX.dll lives in that folder. // We only return "true" if that is the case. Function RuntimeVdfVersionInstalled String sVersion Returns Boolean Boolean bExists String sVdfRootFolder String sFileName Move False To bExists Get fsVdfRootFolder Of ghoWorkspaceHandlerEx sVersion To sVdfRootFolder If (sVdfRootFolder<>"\") Begin // Technically the above test is sufficient, the additional "runtime exists" test below // just confirms the install is OK as even the virtual machine is available. Get VirtualMachineName sVersion To sFileName Get vFilePathExists (sVdfRootFolder+"bin\"+sFileName) To bExists End Function_Return bExists End_Function // RuntimeVdfVersionInstalled Function RuntimeInstallPath String sVersion Returns String Boolean bExists Number nVersion String sVdfRootFolder Move (Cast(sVersion,Number)) To nVersion If (nVersion<8.0) Begin Move (String(Integer(nVersion))) To sVersion End Get fsVdfRootFolder Of ghoWorkspaceHandlerEx sVersion To sVdfRootFolder Get vFolderFormat sVdfRootFolder To sVdfRootFolder Function_Return sVdfRootFolder End_Function // RuntimeInstallPath // // Gets the folder name where the Virtual Machine for VDF lives for the version // of VDF that you pass on. Version passed is a number like 4, 7 (always without // SP number under 8), // or 8.0, 12.1 etc. starting from version 8. // Will also check if the folder exists. // // Returns the bin folder with ending "\" or simply "" if not found or not exists. // Function VdfVersionBinPath String sVersion Returns String Boolean bExists String sVdfRootFolder String sBinPath Move "" To sBinPath Get RuntimeInstallPath sVersion To sVdfRootFolder If (sVdfRootFolder<>"\") Begin Move (sVdfRootFolder+"bin\") To sBinPath Get vFilePathExists (sBinPath+"*") to bExists If (bExists=false) Move "" To sBinPath End Function_Return sBinPath End_Function // VdfVersionBinPath // // Returns the help folder with ending "\" or simply "" if not found or not exists. // // Based on VdfVersionBinPath Function VdfVersionHelpPath String sVersion Returns String Boolean bExists String sVdfRootFolder String sHelpPath Move "" To sHelpPath Get RuntimeInstallPath sVersion To sVdfRootFolder If (sVdfRootFolder<>"\") Begin Move (sVdfRootFolder+"Help\") To sHelpPath Get vFilePathExists (sHelpPath+"*") to bExists If (bExists=false) Move "" To sHelpPath End Function_Return sHelpPath End_Function // VdfVersionHelpPath Function NormalizeVersionNumber String sVersion Returns String Integer iVersion Boolean bIsNumeric Move (Replaces(".",sVersion,"")) To sVersion If (sVersion<>"") Begin Move 0 To iVersion Get IsStringNumeric sVersion To bIsNumeric // version number must be a number If (bIsNumeric) Begin Move (Replaces(",",sVersion,"")) To sVersion // comma's are ignored Move (Integer(sVersion)) To iVersion If (iVersion<40) Begin // DAW wasn't consistent in naming their .0 releases // in the regkey, so add a 0 if version 6.0 or 7.0 // so that we can sort our array properly Move (iVersion*10) To iVersion End End Move (Number(iVersion)) to sVersion End Function_Return sVersion End_Function // NormalizeVersionNumber Procedure EnumerateDataFlexRegistryKey String sBaseKey String sValue Boolean bOpen Boolean bExists Boolean bCheckRT Integer iKeyCount Integer iGetCount Integer iCount Integer iItem Handle hoRegistry Handle hoArray Get pbCheckRuntimeInstalled to bCheckRT Move True To bExists Get Create U_cRegistry To hoRegistry If (hoRegistry) Begin Set pfAccessRights Of hoRegistry To KEY_READ Set phRootKey Of hoRegistry To HKEY_LOCAL_MACHINE Get OpenKey Of hoRegistry sBaseKey To bOpen If (bOpen) Begin Get Create U_Array To hoArray Get CountOfSubkeys Of hoRegistry To iKeyCount Get GetSubkeys Of hoRegistry hoArray To iGetCount Get Item_Count Of hoArray To iCount For iItem From 0 To (iCount-1) Get Value Of hoArray Item iItem To sValue If (bCheckRT) Begin Get RuntimeVdfVersionInstalled sValue To bExists End If (bExists) Begin Get NormalizeVersionNumber sValue To sValue If (sValue<>"") Begin Set Value Item (Item_Count(Self)) To sValue End End Loop Send Destroy Of hoArray Send CloseKey Of hoRegistry End Send Destroy Of hoRegistry End End_Procedure // Procedure LoadArray String sKey Integer iCount // Add VDF4..VDF7 Move (CS_SWDACVDF) To sKey Move (Left(sKey,(Length(sKey)-1))) To sKey Send EnumerateDataFlexRegistryKey sKey // Read VDF8..VDF17.1 versions Move (CS_SWDAWVDF) To sKey Move (Left(sKey,(Length(sKey)-1))) To sKey Send EnumerateDataFlexRegistryKey sKey // Read DF versions Move (CS_SWDAWDF) To sKey Move (Left(sKey,(Length(sKey)-1))) To sKey Send EnumerateDataFlexRegistryKey sKey Get Item_Count to iCount If (iCount>0) Begin Send BubbleSort End End_Procedure // LoadArray End_Class // cWorkspaceSortArray