Skip to content

Commit 2026078

Browse files
committed
Rewrote the gow.vbs file to accept multiple commands like a true command-line application. Added to the installer the capability to remove the older installations, added better debugging, added a feature which should allow Windows 7 installers to function and a couple more small tweaks.
Modified bin/gow.vbs * Main: Takes the first argument and looks for the command-line switches. Prints out a message if there are errors. * PrintUsage: Prints out the full program usage. * Print: Prints out a command to the console. * Version: Returns the version number of the application. * ScriptPath: Returns the path of the gow.vbs VBS script. * ExecutablesList: Now uses the ScriptPath method to get the folder path to list. Modified setup/Gow.nsi * Added RequestExecutionLevel of 'admin' so that it works with Windows 7 installers. * Set all show details commands to "hide" so that you can look at the commands if you wish. * Added DetailPrint messages to most functions so that people will know what step caused an error if any come up. * Configure: Now clears all errors so that the gow.bat file is written out correctly. * Files: Installs all .dll files since there is one now. * RemoveOldInstallation: New function that checks for previously installed Gow products and if it finds one it will prompt to uninstall the previous version. * Shortcuts: Removed the antiquated Change Log message since this is now posted on GitHub. * .onInit: Calls the RemoveOldInstallation function before the installer begins.
1 parent 932a8b5 commit 2026078

File tree

2 files changed

+96
-28
lines changed

2 files changed

+96
-28
lines changed

bin/gow.vbs

+49-22
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
'------------------------------------------------
2-
' Gow
3-
' Prints out all of the executables.
2+
' Gow - The lightweight alternative to Cygwin
3+
' Handles all tasks for the Gow project.
44
' Author: Brent R. Matzelle
55
'------------------------------------------------
66
Option Explicit
77

8-
'------------------------------------------------
98
' Adds a path to the environment variable.
10-
Sub ExecutablesList(path)
11-
Dim fileSys, folder, file, index, line
9+
Sub ExecutablesList()
10+
Dim fileSys, folder, file, index, shell, line
1211

1312
line = " "
1413
Set fileSys = CreateObject("Scripting.FileSystemObject")
15-
Set folder = filesys.GetFolder(path)
14+
15+
Set folder = filesys.GetFolder(ScriptPath())
16+
17+
Print "Available executables:"
18+
Print ""
1619

1720
For Each file In folder.Files
1821
If IsExecutable(file) Then
@@ -27,7 +30,6 @@ Sub ExecutablesList(path)
2730
WScript.Echo Left(line, Len(line) - 2)
2831
End Sub
2932

30-
'------------------------------------------------
3133
' Returns true if the file is an executable.
3234
Function IsExecutable(file)
3335
Dim result
@@ -44,30 +46,55 @@ Function IsExecutable(file)
4446
IsExecutable = result
4547
End Function
4648

47-
'------------------------------------------------
4849
' Main sub-routine
4950
Sub Main()
5051
If Wscript.Arguments.Count < 1 Then
51-
Call PrintUsage("")
52+
PrintUsage
5253
Exit Sub
5354
End If
54-
55-
WScript.Echo "Available executables:"
56-
WScript.Echo ""
57-
ExecutablesList(Wscript.Arguments(0))
55+
56+
Select Case Wscript.Arguments(0)
57+
Case "-l", "--list"
58+
Call ExecutablesList()
59+
Case "-V", "--version"
60+
Print("Gow " & Version())
61+
Case "-h", "--help"
62+
Call PrintUsage
63+
Case Else
64+
Print "UNKNOWN COMMAND: [" & WScript.Arguments(0) & "]"
65+
Print ""
66+
PrintUsage
67+
End Select
5868
End Sub
5969

60-
'------------------------------------------------
61-
' Prints out the normal program usage parameters
62-
Sub PrintUsage(message)
63-
Dim usage
64-
65-
If Len(message) > 0 Then
66-
usage = message & Chr(10)
67-
End If
70+
' Prints out a message.
71+
Sub Print(message)
72+
Wscript.Echo message
73+
End Sub
6874

69-
Wscript.Echo usage
75+
' Prints out the normal program usage parameters
76+
Sub PrintUsage()
77+
Print "Gow " & Version() & " - The lightweight alternative to Cygwin"
78+
Print "Usage: gow OPTION"
79+
Print ""
80+
Print "Options:"
81+
Print " -l, --list Lists all executables"
82+
Print " -V, --version Prints the version"
83+
Print " -h, --help Show this message"
7084
End Sub
7185

86+
' Returns the path of the VBS script.
87+
Function ScriptPath
88+
ScriptPath = Replace(WScript.ScriptFullName, "\" & WScript.ScriptName, "")
89+
End Function
90+
91+
' Prints out the version of Gow.
92+
Function Version()
93+
Version = "0.4.0"
94+
End Function
95+
96+
97+
'------------------------------------------------
7298
' Start program here
7399
Call Main()
100+

setup/Gow.nsi

+47-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Name "${PRODUCT}"
1717
SetCompressor zlib
1818
BrandingText "${PRODUCT} ${VERSION} Installer - powered by NSIS"
19+
RequestExecutionLevel admin
1920

2021
!include "MUI.nsh" ; Include Modern UI
2122

@@ -48,8 +49,8 @@
4849
!insertmacro MUI_LANGUAGE "English"
4950

5051
OutFile "${PRODUCT}-${VERSION}.exe" ; Installer file name
51-
ShowInstDetails nevershow
52-
ShowUninstDetails nevershow
52+
ShowInstDetails hide
53+
ShowUninstDetails hide
5354

5455
;--------------------------------
5556
; Descriptions
@@ -85,20 +86,27 @@ SectionEnd
8586

8687
; Configures the installation
8788
Function Configure
89+
DetailPrint "Configuring the installation..."
90+
8891
StrCpy $R0 "cscript //NoLogo"
8992
nsExec::Exec '$R0 "$INSTDIR\setup\PathSetup.vbs" --path-add "$INSTDIR\bin"'
9093

91-
IfErrors done
94+
SetOutPath $INSTDIR
95+
96+
ClearErrors
9297
FileOpen $R1 "$INSTDIR\bin\gow.bat" w
98+
IfErrors done
9399
FileWrite $R1 "@echo off $\r$\n"
94-
FileWrite $R1 '$R0 "$INSTDIR\bin\gow.vbs" "$INSTDIR\bin" %1'
100+
FileWrite $R1 '$R0 "$INSTDIR\bin\gow.vbs" %1'
95101
FileClose $R1
96102

97103
done:
98104
FunctionEnd
99105

100106
; Installs all files
101107
Function Files
108+
DetailPrint "Installing all files..."
109+
102110
; Copy Readme files
103111
SetOutPath "$INSTDIR"
104112
File "${SRC_DIR}\*.txt"
@@ -110,6 +118,7 @@ Function Files
110118
; Executables
111119
SetOutPath "$INSTDIR\bin"
112120
File "${SRC_DIR}\bin\*.exe"
121+
File "${SRC_DIR}\bin\*.dll"
113122
File "${SRC_DIR}\bin\*.bat"
114123
File "${SRC_DIR}\bin\*.vbs"
115124

@@ -132,6 +141,8 @@ FunctionEnd
132141

133142
; Create the necessary registry entries
134143
Function Registry
144+
DetailPrint "Installing registry keys..."
145+
135146
; Write Registry settings for Add/Remove
136147
WriteRegStr HKLM "SOFTWARE\${PRODUCT}" "" "$INSTDIR"
137148
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" \
@@ -142,13 +153,41 @@ FunctionEnd
142153

143154
; Add the Command Prompt Here entry
144155
Function RegistryCommandPrompt
156+
DetailPrint "Installing Command Prompt registry keys"
157+
145158
StrCpy $R0 'Folder\shell\Command Prompt Here ${PRODUCT}'
146159
WriteRegStr HKCR $R0 "" "Command Prompt &Here"
147160
WriteRegExpandStr HKCR "$R0\command" "" '"%SystemRoot%\system32\cmd.exe" /k cd /d "%1"'
148161
FunctionEnd
149162

163+
; Removes any old installations of Gow on the system.
164+
Function RemoveOldInstallation
165+
DetailPrint "Checking for old Gow installation..."
166+
167+
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" \
168+
"UninstallString"
169+
StrCmp $R0 "" EndFunction 0
170+
171+
MessageBox MB_OKCANCEL \
172+
"${PRODUCT} is already installed. $\n$\nClick OK to remove the \
173+
previous version or Cancel to cancel this upgrade." \
174+
IDOK uninstall
175+
Abort
176+
177+
uninstall:
178+
; Do not copy the uninstaller to a temp file
179+
ExecWait '$R0 _?=$INSTDIR'
180+
181+
IfErrors 0 EndFunction
182+
; TODO: Perform error checking here
183+
184+
EndFunction:
185+
FunctionEnd
186+
150187
; Set the shortcuts
151188
Function Shortcuts
189+
DetailPrint "Installing Windows shortcuts..."
190+
152191
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
153192

154193
; License shortcuts
@@ -164,8 +203,6 @@ Function Shortcuts
164203

165204
; General shortcuts
166205
SetOutPath "$SMPROGRAMS\$STARTMENU_FOLDER"
167-
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\ChangeLog.lnk" \
168-
"$INSTDIR\ChangeLog.txt"
169206
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\ReadMe.lnk" \
170207
"$INSTDIR\ReadMe.txt"
171208
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall ${PRODUCT} ${VERSION}.lnk" \
@@ -178,6 +215,10 @@ FunctionEnd
178215
;--------------------------------
179216
; Post installation methods
180217

218+
Function .onInit
219+
Call RemoveOldInstallation
220+
FunctionEnd
221+
181222
Function .onInstSuccess
182223
Delete "$INSTDIR\Uninstall.exe" ; Delete old uninstaller first
183224
WriteUninstaller "$INSTDIR\Uninstall.exe"

0 commit comments

Comments
 (0)