Skip to content
This repository
Browse code

Rewrote the gow.vbs file to accept multiple commands like a true comm…

…and-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.
  • Loading branch information...
commit 2026078b54ea74dbbc97e2ec1f3f508c2a0df167 1 parent 932a8b5
Brent Matzelle authored

Showing 2 changed files with 96 additions and 28 deletions. Show diff stats Hide diff stats

  1. +49 22 bin/gow.vbs
  2. +47 6 setup/Gow.nsi
71 bin/gow.vbs
... ... @@ -1,18 +1,21 @@
1 1 '------------------------------------------------
2   -' Gow
3   -' Prints out all of the executables.
  2 +' Gow - The lightweight alternative to Cygwin
  3 +' Handles all tasks for the Gow project.
4 4 ' Author: Brent R. Matzelle
5 5 '------------------------------------------------
6 6 Option Explicit
7 7
8   -'------------------------------------------------
9 8 ' 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
12 11
13 12 line = " "
14 13 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 ""
16 19
17 20 For Each file In folder.Files
18 21 If IsExecutable(file) Then
@@ -27,7 +30,6 @@ Sub ExecutablesList(path)
27 30 WScript.Echo Left(line, Len(line) - 2)
28 31 End Sub
29 32
30   -'------------------------------------------------
31 33 ' Returns true if the file is an executable.
32 34 Function IsExecutable(file)
33 35 Dim result
@@ -44,30 +46,55 @@ Function IsExecutable(file)
44 46 IsExecutable = result
45 47 End Function
46 48
47   -'------------------------------------------------
48 49 ' Main sub-routine
49 50 Sub Main()
50 51 If Wscript.Arguments.Count < 1 Then
51   - Call PrintUsage("")
  52 + PrintUsage
52 53 Exit Sub
53 54 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
58 68 End Sub
59 69
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
68 74
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"
70 84 End Sub
71 85
  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 +'------------------------------------------------
72 98 ' Start program here
73 99 Call Main()
  100 +
53 setup/Gow.nsi
@@ -16,6 +16,7 @@
16 16 Name "${PRODUCT}"
17 17 SetCompressor zlib
18 18 BrandingText "${PRODUCT} ${VERSION} Installer - powered by NSIS"
  19 + RequestExecutionLevel admin
19 20
20 21 !include "MUI.nsh" ; Include Modern UI
21 22
@@ -48,8 +49,8 @@
48 49 !insertmacro MUI_LANGUAGE "English"
49 50
50 51 OutFile "${PRODUCT}-${VERSION}.exe" ; Installer file name
51   - ShowInstDetails nevershow
52   - ShowUninstDetails nevershow
  52 + ShowInstDetails hide
  53 + ShowUninstDetails hide
53 54
54 55 ;--------------------------------
55 56 ; Descriptions
@@ -85,13 +86,18 @@ SectionEnd
85 86
86 87 ; Configures the installation
87 88 Function Configure
  89 + DetailPrint "Configuring the installation..."
  90 +
88 91 StrCpy $R0 "cscript //NoLogo"
89 92 nsExec::Exec '$R0 "$INSTDIR\setup\PathSetup.vbs" --path-add "$INSTDIR\bin"'
90 93
91   - IfErrors done
  94 + SetOutPath $INSTDIR
  95 +
  96 + ClearErrors
92 97 FileOpen $R1 "$INSTDIR\bin\gow.bat" w
  98 + IfErrors done
93 99 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'
95 101 FileClose $R1
96 102
97 103 done:
@@ -99,6 +105,8 @@ FunctionEnd
99 105
100 106 ; Installs all files
101 107 Function Files
  108 + DetailPrint "Installing all files..."
  109 +
102 110 ; Copy Readme files
103 111 SetOutPath "$INSTDIR"
104 112 File "${SRC_DIR}\*.txt"
@@ -110,6 +118,7 @@ Function Files
110 118 ; Executables
111 119 SetOutPath "$INSTDIR\bin"
112 120 File "${SRC_DIR}\bin\*.exe"
  121 + File "${SRC_DIR}\bin\*.dll"
113 122 File "${SRC_DIR}\bin\*.bat"
114 123 File "${SRC_DIR}\bin\*.vbs"
115 124
@@ -132,6 +141,8 @@ FunctionEnd
132 141
133 142 ; Create the necessary registry entries
134 143 Function Registry
  144 + DetailPrint "Installing registry keys..."
  145 +
135 146 ; Write Registry settings for Add/Remove
136 147 WriteRegStr HKLM "SOFTWARE\${PRODUCT}" "" "$INSTDIR"
137 148 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" \
@@ -142,13 +153,41 @@ FunctionEnd
142 153
143 154 ; Add the Command Prompt Here entry
144 155 Function RegistryCommandPrompt
  156 + DetailPrint "Installing Command Prompt registry keys"
  157 +
145 158 StrCpy $R0 'Folder\shell\Command Prompt Here ${PRODUCT}'
146 159 WriteRegStr HKCR $R0 "" "Command Prompt &Here"
147 160 WriteRegExpandStr HKCR "$R0\command" "" '"%SystemRoot%\system32\cmd.exe" /k cd /d "%1"'
148 161 FunctionEnd
149 162
  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 +
150 187 ; Set the shortcuts
151 188 Function Shortcuts
  189 + DetailPrint "Installing Windows shortcuts..."
  190 +
152 191 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
153 192
154 193 ; License shortcuts
@@ -164,8 +203,6 @@ Function Shortcuts
164 203
165 204 ; General shortcuts
166 205 SetOutPath "$SMPROGRAMS\$STARTMENU_FOLDER"
167   - CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\ChangeLog.lnk" \
168   - "$INSTDIR\ChangeLog.txt"
169 206 CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\ReadMe.lnk" \
170 207 "$INSTDIR\ReadMe.txt"
171 208 CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall ${PRODUCT} ${VERSION}.lnk" \
@@ -178,6 +215,10 @@ FunctionEnd
178 215 ;--------------------------------
179 216 ; Post installation methods
180 217
  218 +Function .onInit
  219 + Call RemoveOldInstallation
  220 +FunctionEnd
  221 +
181 222 Function .onInstSuccess
182 223 Delete "$INSTDIR\Uninstall.exe" ; Delete old uninstaller first
183 224 WriteUninstaller "$INSTDIR\Uninstall.exe"

0 comments on commit 2026078

Please sign in to comment.
Something went wrong with that request. Please try again.