Skip to content

Commit

Permalink
Rewrote the gow.vbs file to accept multiple commands like a true comm…
Browse files Browse the repository at this point in the history
…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
bmatzelle committed Jul 25, 2010
1 parent 932a8b5 commit 2026078
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 28 deletions.
71 changes: 49 additions & 22 deletions bin/gow.vbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
'------------------------------------------------
' Gow
' Prints out all of the executables.
' Gow - The lightweight alternative to Cygwin
' Handles all tasks for the Gow project.
' Author: Brent R. Matzelle
'------------------------------------------------
Option Explicit

'------------------------------------------------
' Adds a path to the environment variable.
Sub ExecutablesList(path)
Dim fileSys, folder, file, index, line
Sub ExecutablesList()
Dim fileSys, folder, file, index, shell, line

line = " "
Set fileSys = CreateObject("Scripting.FileSystemObject")
Set folder = filesys.GetFolder(path)

Set folder = filesys.GetFolder(ScriptPath())

Print "Available executables:"
Print ""

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

'------------------------------------------------
' Returns true if the file is an executable.
Function IsExecutable(file)
Dim result
Expand All @@ -44,30 +46,55 @@ Function IsExecutable(file)
IsExecutable = result
End Function

'------------------------------------------------
' Main sub-routine
Sub Main()
If Wscript.Arguments.Count < 1 Then
Call PrintUsage("")
PrintUsage
Exit Sub
End If

WScript.Echo "Available executables:"
WScript.Echo ""
ExecutablesList(Wscript.Arguments(0))

Select Case Wscript.Arguments(0)
Case "-l", "--list"
Call ExecutablesList()
Case "-V", "--version"
Print("Gow " & Version())
Case "-h", "--help"
Call PrintUsage
Case Else
Print "UNKNOWN COMMAND: [" & WScript.Arguments(0) & "]"
Print ""
PrintUsage
End Select
End Sub

'------------------------------------------------
' Prints out the normal program usage parameters
Sub PrintUsage(message)
Dim usage

If Len(message) > 0 Then
usage = message & Chr(10)
End If
' Prints out a message.
Sub Print(message)
Wscript.Echo message
End Sub

Wscript.Echo usage
' Prints out the normal program usage parameters
Sub PrintUsage()
Print "Gow " & Version() & " - The lightweight alternative to Cygwin"
Print "Usage: gow OPTION"
Print ""
Print "Options:"
Print " -l, --list Lists all executables"
Print " -V, --version Prints the version"
Print " -h, --help Show this message"
End Sub

' Returns the path of the VBS script.
Function ScriptPath
ScriptPath = Replace(WScript.ScriptFullName, "\" & WScript.ScriptName, "")
End Function

' Prints out the version of Gow.
Function Version()
Version = "0.4.0"
End Function


'------------------------------------------------
' Start program here
Call Main()

53 changes: 47 additions & 6 deletions setup/Gow.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Name "${PRODUCT}"
SetCompressor zlib
BrandingText "${PRODUCT} ${VERSION} Installer - powered by NSIS"
RequestExecutionLevel admin

!include "MUI.nsh" ; Include Modern UI

Expand Down Expand Up @@ -48,8 +49,8 @@
!insertmacro MUI_LANGUAGE "English"

OutFile "${PRODUCT}-${VERSION}.exe" ; Installer file name
ShowInstDetails nevershow
ShowUninstDetails nevershow
ShowInstDetails hide
ShowUninstDetails hide

;--------------------------------
; Descriptions
Expand Down Expand Up @@ -85,20 +86,27 @@ SectionEnd

; Configures the installation
Function Configure
DetailPrint "Configuring the installation..."

StrCpy $R0 "cscript //NoLogo"
nsExec::Exec '$R0 "$INSTDIR\setup\PathSetup.vbs" --path-add "$INSTDIR\bin"'

IfErrors done
SetOutPath $INSTDIR

ClearErrors
FileOpen $R1 "$INSTDIR\bin\gow.bat" w
IfErrors done
FileWrite $R1 "@echo off $\r$\n"
FileWrite $R1 '$R0 "$INSTDIR\bin\gow.vbs" "$INSTDIR\bin" %1'
FileWrite $R1 '$R0 "$INSTDIR\bin\gow.vbs" %1'
FileClose $R1

done:
FunctionEnd

; Installs all files
Function Files
DetailPrint "Installing all files..."

; Copy Readme files
SetOutPath "$INSTDIR"
File "${SRC_DIR}\*.txt"
Expand All @@ -110,6 +118,7 @@ Function Files
; Executables
SetOutPath "$INSTDIR\bin"
File "${SRC_DIR}\bin\*.exe"
File "${SRC_DIR}\bin\*.dll"
File "${SRC_DIR}\bin\*.bat"
File "${SRC_DIR}\bin\*.vbs"

Expand All @@ -132,6 +141,8 @@ FunctionEnd

; Create the necessary registry entries
Function Registry
DetailPrint "Installing registry keys..."

; Write Registry settings for Add/Remove
WriteRegStr HKLM "SOFTWARE\${PRODUCT}" "" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" \
Expand All @@ -142,13 +153,41 @@ FunctionEnd

; Add the Command Prompt Here entry
Function RegistryCommandPrompt
DetailPrint "Installing Command Prompt registry keys"

StrCpy $R0 'Folder\shell\Command Prompt Here ${PRODUCT}'
WriteRegStr HKCR $R0 "" "Command Prompt &Here"
WriteRegExpandStr HKCR "$R0\command" "" '"%SystemRoot%\system32\cmd.exe" /k cd /d "%1"'
FunctionEnd

; Removes any old installations of Gow on the system.
Function RemoveOldInstallation
DetailPrint "Checking for old Gow installation..."

ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" \
"UninstallString"
StrCmp $R0 "" EndFunction 0

MessageBox MB_OKCANCEL \
"${PRODUCT} is already installed. $\n$\nClick OK to remove the \
previous version or Cancel to cancel this upgrade." \
IDOK uninstall
Abort

uninstall:
; Do not copy the uninstaller to a temp file
ExecWait '$R0 _?=$INSTDIR'

IfErrors 0 EndFunction
; TODO: Perform error checking here

EndFunction:
FunctionEnd

; Set the shortcuts
Function Shortcuts
DetailPrint "Installing Windows shortcuts..."

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application

; License shortcuts
Expand All @@ -164,8 +203,6 @@ Function Shortcuts

; General shortcuts
SetOutPath "$SMPROGRAMS\$STARTMENU_FOLDER"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\ChangeLog.lnk" \
"$INSTDIR\ChangeLog.txt"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\ReadMe.lnk" \
"$INSTDIR\ReadMe.txt"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall ${PRODUCT} ${VERSION}.lnk" \
Expand All @@ -178,6 +215,10 @@ FunctionEnd
;--------------------------------
; Post installation methods

Function .onInit
Call RemoveOldInstallation
FunctionEnd

Function .onInstSuccess
Delete "$INSTDIR\Uninstall.exe" ; Delete old uninstaller first
WriteUninstaller "$INSTDIR\Uninstall.exe"
Expand Down

0 comments on commit 2026078

Please sign in to comment.