aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/create_project/msvc.cpp26
-rw-r--r--tools/create_project/msvc10/create_project.vcxproj9
-rw-r--r--tools/create_project/msvc10/create_project.vcxproj.filters14
-rw-r--r--tools/create_project/msvc8/create_project.vcproj18
-rw-r--r--tools/create_project/msvc9/create_project.vcproj18
-rw-r--r--tools/create_project/scripts/postbuild.cmd6
-rw-r--r--tools/create_project/scripts/prebuild.cmd21
-rw-r--r--tools/create_project/scripts/revision.vbs445
8 files changed, 528 insertions, 29 deletions
diff --git a/tools/create_project/msvc.cpp b/tools/create_project/msvc.cpp
index c6174f7bd4..3d537b989d 100644
--- a/tools/create_project/msvc.cpp
+++ b/tools/create_project/msvc.cpp
@@ -873,10 +873,6 @@ void MSBuildProvider::createBuildProp(const BuildSetup &setup, bool isRelease, b
projectFile << "\t\t\t<Command Condition=\"'$(Configuration)|$(Platform)'=='" << config << "|Win32'\">nasm.exe -f win32 -g -o \"$(IntDir)" << (isDuplicate ? (*entry).prefix : "") << "%(Filename).obj\" \"%(FullPath)\"</Command>\n" \
"\t\t\t<Outputs Condition=\"'$(Configuration)|$(Platform)'=='" << config << "|Win32'\">$(IntDir)" << (isDuplicate ? (*entry).prefix : "") << "%(Filename).obj;%(Outputs)</Outputs>\n";
-#define OUPUT_OBJECT_FILENAME_MSBUILD(config, platform, prefix) \
- projectFile << "\t\t<ObjectFileName Condition=\"'$(Configuration)|$(Platform)'=='" << config << "|" << platform << "'\">$(IntDir)" << prefix << "%(Filename).obj</ObjectFileName>\n" \
- "\t\t<XMLDocumentationFileName Condition=\"'$(Configuration)|$(Platform)'=='" << config << "|" << platform << "'\">$(IntDir)" << prefix << "%(Filename).xdc</XMLDocumentationFileName>\n";
-
#define OUPUT_FILES_MSBUILD(files, action) \
if (!files.empty()) { \
projectFile << "\t<ItemGroup>\n"; \
@@ -886,6 +882,15 @@ void MSBuildProvider::createBuildProp(const BuildSetup &setup, bool isRelease, b
projectFile << "\t</ItemGroup>\n"; \
}
+bool hasEnding(std::string const &fullString, std::string const &ending) {
+ if (fullString.length() > ending.length()) {
+ return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
+ } else {
+ return false;
+ }
+}
+
+
void MSBuildProvider::writeFileListToProject(const FileNode &dir, std::ofstream &projectFile, const int, const StringList &duplicate,
const std::string &objPrefix, const std::string &filePrefix) {
// Reset lists
@@ -909,13 +914,12 @@ void MSBuildProvider::writeFileListToProject(const FileNode &dir, std::ofstream
// Deal with duplicated file names
if (isDuplicate) {
- projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\">\n";
- OUPUT_OBJECT_FILENAME_MSBUILD("Debug", "Win32", (*entry).prefix)
- OUPUT_OBJECT_FILENAME_MSBUILD("Debug", "x64", (*entry).prefix)
- OUPUT_OBJECT_FILENAME_MSBUILD("Analysis", "Win32", (*entry).prefix)
- OUPUT_OBJECT_FILENAME_MSBUILD("Analysis", "x64", (*entry).prefix)
- OUPUT_OBJECT_FILENAME_MSBUILD("Release", "Win32", (*entry).prefix)
- OUPUT_OBJECT_FILENAME_MSBUILD("Release", "x64", (*entry).prefix)
+ projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\">\n"
+ "\t\t\t<ObjectFileName>$(IntDir)" << (*entry).prefix << "%(Filename).obj</ObjectFileName>\n";
+
+ if (hasEnding((*entry).path, "base\\version.cpp"))
+ projectFile << "\t\t\t<PreprocessorDefinitions Condition=\"'$(Configuration)'=='Debug'\">SCUMMVM_SVN_REVISION#&quot; $(SCUMMVM_REVISION_STRING)&quot;;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n";
+
projectFile << "\t\t</ClCompile>\n";
} else {
projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\" />\n";
diff --git a/tools/create_project/msvc10/create_project.vcxproj b/tools/create_project/msvc10/create_project.vcxproj
index eb8c0417d3..305eadcf72 100644
--- a/tools/create_project/msvc10/create_project.vcxproj
+++ b/tools/create_project/msvc10/create_project.vcxproj
@@ -87,6 +87,10 @@ xcopy /Y $(TargetPath) $(SolutionDir)\..\..\..\dists\msvc9\
xcopy /Y $(TargetPath) $(SolutionDir)\..\..\..\dists\msvc8\
xcopy /Y $(TargetPath) $(SolutionDir)\..\..\..\dists\codeblocks\</Command>
</PostBuildEvent>
+ <PreBuildEvent>
+ <Command>
+ </Command>
+ </PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\codeblocks.cpp" />
@@ -98,6 +102,11 @@ xcopy /Y $(TargetPath) $(SolutionDir)\..\..\..\dists\codeblocks\</Command>
<ClInclude Include="..\create_project.h" />
<ClInclude Include="..\msvc.h" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="..\scripts\postbuild.cmd" />
+ <None Include="..\scripts\prebuild.cmd" />
+ <None Include="..\scripts\revision.vbs" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/tools/create_project/msvc10/create_project.vcxproj.filters b/tools/create_project/msvc10/create_project.vcxproj.filters
index 8dd77ba7e0..edf947d6e6 100644
--- a/tools/create_project/msvc10/create_project.vcxproj.filters
+++ b/tools/create_project/msvc10/create_project.vcxproj.filters
@@ -7,6 +7,9 @@
<Filter Include="Source Files">
<UniqueIdentifier>{31aaf58c-d3cb-4ed6-8eca-163b4a9b31a6}</UniqueIdentifier>
</Filter>
+ <Filter Include="scripts">
+ <UniqueIdentifier>{f980f6fb-41b6-4161-b035-58b200c85cad}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\codeblocks.h">
@@ -30,4 +33,15 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
+ <ItemGroup>
+ <None Include="..\scripts\prebuild.cmd">
+ <Filter>scripts</Filter>
+ </None>
+ <None Include="..\scripts\revision.vbs">
+ <Filter>scripts</Filter>
+ </None>
+ <None Include="..\scripts\postbuild.cmd">
+ <Filter>scripts</Filter>
+ </None>
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/tools/create_project/msvc8/create_project.vcproj b/tools/create_project/msvc8/create_project.vcproj
index f9692d444e..1e1a68d2ba 100644
--- a/tools/create_project/msvc8/create_project.vcproj
+++ b/tools/create_project/msvc8/create_project.vcproj
@@ -195,6 +195,24 @@
>
</File>
</Filter>
+ <Filter
+ Name="Scripts"
+ Filter="vbs;cmd"
+ UniqueIdentifier="{45B110C8-4C64-4677-8ED6-F9A93C6D55A0}"
+ >
+ <File
+ RelativePath="..\scripts\prebuild.cmd"
+ >
+ </File>
+ <File
+ RelativePath="..\scripts\postbuild.cmd"
+ >
+ </File>
+ <File
+ RelativePath="..\scripts\revision.vbs"
+ >
+ </File>
+ </Filter>
</Files>
<Globals>
</Globals>
diff --git a/tools/create_project/msvc9/create_project.vcproj b/tools/create_project/msvc9/create_project.vcproj
index c7c7e6c277..642bedcc80 100644
--- a/tools/create_project/msvc9/create_project.vcproj
+++ b/tools/create_project/msvc9/create_project.vcproj
@@ -196,6 +196,24 @@
>
</File>
</Filter>
+ <Filter
+ Name="Scripts"
+ Filter="vbs;cmd"
+ UniqueIdentifier="{45B110C8-4C64-4677-8ED6-F9A93C6D55A0}"
+ >
+ <File
+ RelativePath="..\scripts\prebuild.cmd"
+ >
+ </File>
+ <File
+ RelativePath="..\scripts\postbuild.cmd"
+ >
+ </File>
+ <File
+ RelativePath="..\scripts\revision.vbs"
+ >
+ </File>
+ </Filter>
</Files>
<Globals>
</Globals>
diff --git a/tools/create_project/scripts/postbuild.cmd b/tools/create_project/scripts/postbuild.cmd
index 89062de2de..5c2bd8a1ad 100644
--- a/tools/create_project/scripts/postbuild.cmd
+++ b/tools/create_project/scripts/postbuild.cmd
@@ -30,15 +30,15 @@ xcopy /F /Y "%SCUMMVM_LIBS%/lib/%~3/SDL.dll" %~2 > NUL 2>&1
goto done
:error_output
-@echo Invalid root folder (%~1)!
+echo Invalid root folder (%~1)!
goto done
:error_output
-@echo Invalid output folder (%~2)!
+echo Invalid output folder (%~2)!
goto done
:error_arch
-@echo Invalid arch parameter (was: %~3, allowed: x86, x64)!
+echo Invalid arch parameter (was: %~3, allowed: x86, x64)!
goto done
:done
diff --git a/tools/create_project/scripts/prebuild.cmd b/tools/create_project/scripts/prebuild.cmd
index 0e67b6f228..584e217c65 100644
--- a/tools/create_project/scripts/prebuild.cmd
+++ b/tools/create_project/scripts/prebuild.cmd
@@ -11,26 +11,17 @@ REM Root folder
if "%~1"=="" goto error_input
-if not exist "%~1/.svn/" GOTO error_working_copy
-
-echo Generating revision number
-
-SubWCRev.exe "%~1" "%~1/base/internal_version.h.tpl" "%~1/base/internal_version.h"
-
-if not %errorlevel% == 0 goto error_subwcrev
+REM Run the revision script
+@call cscript "%~1/tools/create_project/scripts/revision.vbs" %~1 1>NUL
+if not %errorlevel% == 0 goto error_script
goto done
:error_output
-@echo Invalid root folder (%~1)!
+echo Invalid root folder (%~1)!
goto done
-:error_working_copy
-echo Not a working copy, skipping...
-exit /B0
-
-:error_subwcrev
-echo SubWCRev not found or invalid command line, skipping...
-exit /B0
+:error_script:
+echo An error occured while running the revision script!
:done
exit /B0
diff --git a/tools/create_project/scripts/revision.vbs b/tools/create_project/scripts/revision.vbs
index e69de29bb2..ad6b2c6b2e 100644
--- a/tools/create_project/scripts/revision.vbs
+++ b/tools/create_project/scripts/revision.vbs
@@ -0,0 +1,445 @@
+'
+' ScummVM - Graphic Adventure Engine
+'
+' ScummVM is the legal property of its developers, whose names
+' are too numerous to list here. Please refer to the COPYRIGHT
+' file distributed with this source distribution.
+'
+' This program is free software; you can redistribute it and/or
+' modify it under the terms of the GNU General Public License
+' as published by the Free Software Foundation, version 2
+' of the License.
+'
+' This program is distributed in the hope that it will be useful,
+' but WITHOUT ANY WARRANTY; without even the implied warranty of
+' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+' GNU General Public License for more details.
+'
+' You should have received a copy of the GNU General Public License
+' along with this program; if not, write to the Free Software
+' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+'
+' Based off OpenTTD determineversion.vbs (released under GPL version 2)
+'
+'/
+
+Option Explicit
+
+' Working copy check priority:
+' True: TortoiseSVN -> SVN -> Git -> Hg
+' False: Git -> Hg -> TortoiseSVN -> SVN
+Dim prioritySVN: prioritySVN = True
+
+Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
+Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
+
+' Folders
+Dim rootFolder : rootFolder = ""
+
+' Info variables
+Dim tool : tool = ""
+Dim branch : branch = "trunk"
+Dim revision : revision = ""
+Dim modified : modified = False
+
+' Parse our command line arguments
+If ParseCommandLine() Then
+ ' Determine the revision and update the props file with the revision numbers
+ DetermineRevision()
+End If
+
+'////////////////////////////////////////////////////////////////
+'// Revision checking
+'////////////////////////////////////////////////////////////////
+Sub DetermineRevision()
+ Wscript.StdErr.WriteLine "Determining current revision:"
+
+ ' Set the current directory to the root folder
+ WshShell.CurrentDirectory = rootFolder
+
+ ' Try until we find a proper working copy
+ If (prioritySVN) Then
+ If Not DetermineTortoiseSVNVersion() Then
+ If Not DetermineSVNVersion() Then
+ If Not DetermineGitVersion() Then
+ If Not DetermineHgVersion() Then
+ Wscript.StdErr.WriteLine "Could not determine the current revision, skipping..."
+ Exit Sub
+ End If
+ End If
+ End If
+ End If
+ Else
+ If Not DetermineGitVersion() Then
+ If Not DetermineHgVersion() Then
+ If Not DetermineTortoiseSVNVersion() Then
+ If Not DetermineSVNVersion() Then
+ Wscript.StdErr.WriteLine "Could not determine the current revision, skipping..."
+ Exit Sub
+ End If
+ End If
+ End If
+ End If
+ End If
+
+ Wscript.StdErr.WriteLine "Found revision " & revision & " on branch " & branch & vbCrLf
+
+ ' Setup our revision string
+ Dim revisionString : revisionString = "r" & revision
+
+ If (modified) Then
+ revisionString = revisionString & " M"
+ End If
+
+ ' If we are not on trunk, add the branch name to the revision string
+ If (branch <> "trunk" And branch <> "") Then
+ revisionString = revisionString & " (" & branch & ")"
+ End If
+
+ ' Add the DVCS name at the end
+ revisionString = revisionString & " - " & tool
+
+ ' Setup an environment variable with the revision string
+ Dim Env: Set Env = WshShell.Environment("User")
+ Env.item("SCUMMVM_REVISION_STRING") = revisionString
+End Sub
+
+Function DetermineTortoiseSVNVersion()
+ Err.Clear
+ On Error Resume Next
+ DetermineTortoiseSVNVersion = False
+ Wscript.StdErr.Write " TortoiseSVN... "
+ tool = "svn"
+
+ ' Get the directory where TortoiseSVN (should) reside(s)
+ Dim sTortoise
+
+ ' First, try with 32-bit architecture
+ sTortoise = ReadRegistryKey("HKLM", "SOFTWARE\TortoiseSVN", "Directory", 32)
+
+ If sTortoise = "" Or IsNull(sTortoise) Then
+ ' No 32-bit version of TortoiseSVN installed, try 64-bit version (doesn't hurt on 32-bit machines, it returns nothing or is ignored)
+ sTortoise = ReadRegistryKey("HKLM", "SOFTWARE\TortoiseSVN", "Directory", 64)
+ End If
+
+ ' Check if Tortoise is present
+ If sTortoise = "" Then
+ Wscript.StdErr.WriteLine "TortoiseSVN not installed!"
+ Exit Function
+ End If
+
+ ' If TortoiseSVN is installed, try to get the revision number
+ Dim SubWCRev : Set SubWCRev = WScript.CreateObject("SubWCRev.object")
+ SubWCRev.GetWCInfo rootFolder, 0, 0
+
+ ' Check if this is a working copy
+ If Not SubWCRev.IsSvnItem Then
+ Wscript.StdErr.WriteLine "Not a working copy!"
+ Exit Function
+ End If
+
+ revision = SubWCRev.Revision
+
+ ' Check for modifications
+ If SubWCRev.HasModifications Then modified = True
+
+ If revision = "" Then
+ Wscript.StdErr.WriteLine "No revision found!"
+ Exit Function
+ End If
+
+ DetermineTortoiseSVNVersion = True
+End Function
+
+Function DetermineSVNVersion()
+ Err.Clear
+ On Error Resume Next
+ DetermineSVNVersion = False
+ Wscript.StdErr.Write " SVN... "
+ tool = "svn"
+
+ ' Set the environment to English
+ WshShell.Environment("PROCESS")("LANG") = "en"
+
+ ' Do we have subversion installed? Check immediately whether we've got a modified WC.
+ Dim oExec: Set oExec = WshShell.Exec("svnversion " & rootFolder)
+ If Err.Number <> 0 Then
+ Wscript.StdErr.WriteLine "SVN not installed!"
+ Exit Function
+ End If
+
+ ' Wait till the application is finished ...
+ Do While oExec.Status = 0
+ WScript.Sleep 100
+ Loop
+
+ Dim line: line = OExec.StdOut.ReadLine()
+ If line = "exported" Then
+ Wscript.StdErr.WriteLine "Not a working copy!"
+ Exit Function
+ End If
+
+ If InStr(line, "M") Then
+ modified = True
+ End If
+
+ ' And use svn info to get the correct revision and branch information.
+ Set oExec = WshShell.Exec("svn info " & rootFolder)
+
+ If Err.Number <> 0 Then
+ Wscript.StdErr.WriteLine "No revision found!"
+ Exit Function
+ End If
+
+ Do
+ line = OExec.StdOut.ReadLine()
+ If InStr(line, "Last Changed Rev") Then
+ revision = Mid(line, 19)
+ End If
+ Loop While Not OExec.StdOut.atEndOfStream
+
+ If revision = 0 Then
+ Wscript.StdErr.WriteLine "No revision found!"
+ Exit Function
+ End If
+
+ DetermineSVNVersion = True
+End Function
+
+Function DetermineGitVersion()
+ Err.Clear
+ On Error Resume Next
+ DetermineGitVersion = False
+ Wscript.StdErr.Write " Git... "
+ tool = "git"
+
+ ' First check if we have both a .git & .svn folders (in case hg-git has been set up to have the git folder at the working copy level)
+ If FSO.FolderExists(rootFolder & "/.git") And FSO.FolderExists(rootFolder & "/.hg") Then
+ Wscript.StdErr.WriteLine "Mercurial clone with git repository in tree!"
+ Exit Function
+ End If
+
+ ' Set the environment to English
+ WshShell.Environment("PROCESS")("LANG") = "en"
+
+ ' Detect if we are using msysgit that has a cmd script in the path instead of an exe...
+ Dim gitPath : gitPath = "git "
+ Dim oExec : Set oExec = WshShell.Exec("git")
+ If Err.Number <> 0 Then
+ gitPath = "git.cmd "
+ End If
+
+ Err.Clear
+ Set oExec = WshShell.Exec(gitPath & "rev-parse --verify HEAD")
+ If Err.Number <> 0 Then
+ Wscript.StdErr.WriteLine "Git not installed!"
+ Exit Function
+ End If
+
+ ' Wait till the application is finished ...
+ Do While oExec.Status = 0
+ WScript.Sleep 100
+ Loop
+
+ If oExec.ExitCode <> 0 Then
+ Wscript.StdErr.WriteLine "Error parsing git revision!"
+ Exit Function
+ End If
+
+ ' Get the version hash
+ Dim hash: hash = oExec.StdOut.ReadLine()
+
+ ' Make sure index is in sync with disk
+ Set oExec = WshShell.Exec(gitPath & "update-index --refresh")
+ If Err.Number = 0 Then
+ ' Wait till the application is finished ...
+ Do While oExec.Status = 0
+ WScript.Sleep 100
+ Loop
+ End If
+
+ Set oExec = WshShell.Exec(gitPath & "diff-index --exit-code --quiet HEAD " & rootFolder)
+ If oExec.ExitCode <> 0 Then
+ Wscript.StdErr.WriteLine "Error parsing git revision!"
+ Exit Function
+ End If
+
+ ' Wait till the application is finished ...
+ Do While oExec.Status = 0
+ WScript.Sleep 100
+ Loop
+
+ If oExec.ExitCode = 1 Then
+ modified = True
+ End If
+
+ ' Get branch name
+ Set oExec = WshShell.Exec(gitPath & "symbolic-ref HEAD")
+ If Err.Number = 0 Then
+ Dim line: line = oExec.StdOut.ReadLine()
+ line = Mid(line, InStrRev(line, "/") + 1)
+ If line <> "master" Then
+ branch = line
+ End If
+ End If
+
+ ' Check for svn clones
+ Set oExec = WshShell.Exec(gitPath & "log --pretty=format:%s --grep=" & Chr(34) & "^(svn r[0-9]*)" & Chr(34) & " -1 " & rootFolder)
+ if Err.Number = 0 Then
+ revision = Mid(oExec.StdOut.ReadLine(), 7)
+ revision = Mid(revision, 1, InStr(revision, ")") - 1)
+ tool = "svn-git"
+ End If
+
+ ' No revision? Maybe it is a custom git-svn clone
+ If revision = "" Then
+ Err.Clear
+ Set oExec = WshShell.Exec(gitPath & "log --pretty=format:%b --grep=" & Chr(34) & "git-svn-id:.*@[0-9]*" & Chr(34) & " -1 " & rootFolder)
+ If Err.Number = 0 Then
+ revision = oExec.StdOut.ReadLine()
+ revision = Mid(revision, InStr(revision, "@") + 1)
+ revision = Mid(revision, 1, InStr(revision, " ") - 1)
+ tool = "svn-git"
+ End If
+ End If
+
+ ' Fallback to abbreviated revision number
+ If revision = "" Then
+ revision = Mid(hash, 1, 8)
+ End If
+
+ DetermineGitVersion = True
+End Function
+
+Function DetermineHgVersion()
+ Err.Clear
+ On Error Resume Next
+ DetermineHgVersion = False
+ Wscript.StdErr.Write " Mercurial... "
+ tool = "hg"
+
+ Err.Clear
+ Dim oExec: Set oExec = WshShell.Exec("hg parents --template ""{rev}:{node|short}""")
+ If Err.Number <> 0 Then
+ Wscript.StdErr.WriteLine "Mercurial not installed!"
+ Exit Function
+ End If
+
+ ' Wait till the application is finished ...
+ Do While oExec.Status = 0
+ WScript.Sleep 100
+ Loop
+
+ If oExec.ExitCode <> 0 Then
+ Wscript.StdErr.WriteLine "Error parsing mercurial revision!"
+ Exit Function
+ End If
+
+ Dim info : info = Split(OExec.StdOut.ReadLine(), ":")
+ Dim version : version = info(0)
+ Dim hash : hash = info(1)
+
+ Set oExec = WshShell.Exec("hg status " & rootFolder)
+ If Err.Number <> 0 Then
+ Wscript.StdErr.WriteLine "Error parsing mercurial revision!"
+ Exit Function
+ End If
+
+ ' Check for modifications
+ Do
+ line = OExec.StdOut.ReadLine()
+ If Len(line) > 0 And Mid(line, 1, 1) <> "?" Then
+ modified = True
+ Exit Do
+ End If
+ Loop While Not OExec.StdOut.atEndOfStream
+
+ ' Check for branch
+ Set oExec = WshShell.Exec("hg branch")
+ If Err.Number = 0 Then
+ line = OExec.StdOut.ReadLine()
+ If line <> "default" Then
+ branch = line
+ End If
+ End If
+
+ ' Check for SVN clone
+ Set oExec = WshShell.Exec("hg log -f -l 1 --template ""{svnrev}\n"" --cwd " & rootFolder)
+ If Err.Number = 0 Then
+ revision = Mid(OExec.StdOut.ReadLine(), 7)
+ revision = Mid(revision, 1, InStr(revision, ")") - 1)
+ tool = "svn-hg"
+ End If
+
+ ' Fallback to abbreviated revision number
+ If revision = "" Then
+ revision = version & "(" & hash & ")"
+ End If
+
+ DetermineHgVersion = True
+End Function
+
+'////////////////////////////////////////////////////////////////
+'// Utilities
+'////////////////////////////////////////////////////////////////
+Function ParseCommandLine()
+ ParseCommandLine = True
+
+ If Wscript.Arguments.Count <> 1 Then
+ Wscript.StdErr.WriteLine "[Error] Invalid number of arguments (was: " & Wscript.Arguments.Count & ", expected: 1)"
+
+ ParseCommandLine = False
+ Exit Function
+ End If
+
+ ' Get our arguments
+ rootFolder = Wscript.Arguments.Item(0)
+
+ ' Check that the folders are valid
+ If Not FSO.FolderExists(rootFolder) Then
+ Wscript.StdErr.WriteLine "[Error] Invalid root folder (" & rootFolder & ")"
+
+ ParseCommandLine = False
+ Exit Function
+ End If
+
+ ' Set absolute path
+ rootFolder = FSO.GetAbsolutePathName(rootFolder)
+End Function
+
+Function ReadRegistryKey(shive, subkey, valuename, architecture)
+ Dim hiveKey, objCtx, objLocator, objServices, objReg, Inparams, Outparams
+
+ ' First, get the Registry Provider for the requested architecture
+ Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
+ objCtx.Add "__ProviderArchitecture", architecture ' Must be 64 of 32
+ Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
+ Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
+ Set objReg = objServices.Get("StdRegProv")
+
+ ' Check the hive and give it the right value
+ Select Case shive
+ Case "HKCR", "HKEY_CLASSES_ROOT"
+ hiveKey = &h80000000
+ Case "HKCU", "HKEY_CURRENT_USER"
+ hiveKey = &H80000001
+ Case "HKLM", "HKEY_LOCAL_MACHINE"
+ hiveKey = &h80000002
+ Case "HKU", "HKEY_USERS"
+ hiveKey = &h80000003
+ Case "HKCC", "HKEY_CURRENT_CONFIG"
+ hiveKey = &h80000005
+ Case "HKDD", "HKEY_DYN_DATA" ' Only valid for Windows 95/98
+ hiveKey = &h80000006
+ Case Else
+ MsgBox "Hive not valid (ReadRegistryKey)"
+ End Select
+
+ Set Inparams = objReg.Methods_("GetStringValue").Inparameters
+ Inparams.Hdefkey = hiveKey
+ Inparams.Ssubkeyname = subkey
+ Inparams.Svaluename = valuename
+ Set Outparams = objReg.ExecMethod_("GetStringValue", Inparams,,objCtx)
+
+ ReadRegistryKey = Outparams.SValue
+End Function