Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Basic Installer w/ GUI by Noahc3
- ;HTTP File Downloader by Bruttosozialprodukt
- ;Built with Autohotkey 1.1.22.09
- ;Installer Version 2.0
- ;Source Code available at http://pastebin.com/xBbCPhtP
- ;Instruction Set Codes:
- ;mkdir: Makes new directory at ~workingdir~/[Given Directory] unless it already exists
- ;rmdir: Removes directory at ~workingdir~/[Given Directory] unless it contains files (aka the folder must be empty otherwise it wont be deleted)
- ;rmdirF: Removes directory at ~workingdir~/[Given Directory] even if it has files in it
- ;del: Deletes file at ~workingdir~/[Given Directory]
- ;ver: This will display the version number before installing. Make instructionDir the version number in the instruction set. Only use once, and put it at the top of the instruction set! (1.2+)
- ;
- ;Otherwise, you can leave a literal URL for it to be downloaded.
- ;PreInit
- #NoEnv
- SendMode Input
- SetWorkingDir %A_ScriptDir%
- ; Bundle title image when compiled, and extract image on launch if ran as an EXE
- FileInstall, brunchExpansion.png, %A_ScriptDir%\brunchExpansion.png, 0
- ;Download instruction set (1.1+)
- DownloadFile("https://s3-us-west-2.amazonaws.com/worldofgrinding/Breakfast+Special%3A+Brunch+Files/brunchDownloads.txt", "brunchDownloads.txt")
- ;Set default radio selection
- directorySelected = 1
- ;Default text for custom directory edit
- selectedCustomDirectory = Breakfast Special Install Directory
- ;Build GUI
- Gui, Show , w480 h300, Breakfast Special: Brunch Expansion Installer
- Gui, Add, Text, x20 y270 w250,Installer Version 2.0
- Gui, Add, Edit, w300 h19 x50 y140 vCustomDirectory, %selectedCustomDirectory%
- Gui, Add, Edit, w375 h19 x50 y90 vCurrentDirectory ReadOnly, %A_ScriptDir%
- Gui, Add, Button, x50 y200 w375 h50 gINSTALL vINSTALL,Install
- Gui, Add, Button, x350 y139 w75 h21 gBROWSE vBROWSEBUTTON,Browse
- Gui, Add, Radio, x50 y70 gDirectorySelect1 vDirectorySelect1 checked, Use This Directory
- Gui, Add, Radio, x50 y120 gDirectorySelect2 vDirectorySelect2, Use Custom Directory
- Gui, Add, Picture, x70 y10 w325 h-1, brunchExpansion.png
- ;Create but instantly hide the install complete message
- Gui, Add, Text, x10 y90 w460 Center vInstallComplete,Installation Complete. The mods and configs were added to your game.
- Gui, Add, Button, x365 y270 w100 h21 gFINISH vFINISH,Finish
- GuiControl, hide, InstallComplete
- GuiControl, hide, FINISH
- ;Disable the Custom Directory edit and the browse button by default
- GuiControl, disable, CustomDirectory
- GuiControl, disable, BROWSEBUTTON
- ;Instantly delete extracted logo once loaded into memory
- FileDelete, brunchExpansion.png
- ;Loop for developer commands, blank in public releases
- Loop
- {
- }
- return
- ;When Radio 1 is selected, enable Current Directory text box and set selected directory to 1, disable Custom Directory options
- DirectorySelect1:
- {
- Gui, Submit, NoHide
- GuiControl, disable, CustomDirectory
- GuiControl, disable, BROWSEBUTTON
- GuiControl, enable, CurrentDirectory
- directorySelected = 1
- }
- return
- ;When Radio 2 is selected, enable the Custom Directory edit and browse button and set selected directory to 2, disable Current Directory options
- DirectorySelect2:
- {
- Gui, Submit, NoHide
- GuiControl, enable, CustomDirectory
- GuiControl, enable, BROWSEBUTTON
- GuiControl, disable, CurrentDirectory
- directorySelected = 2
- }
- return
- ;When browse is pressed, handle folder selection
- BROWSE:
- {
- Gui, Submit, NoHide
- FileSelectFolder, vFolderSelected, C:, 3, Select Breakfast Special Installation Folder
- GuiControl, Text, CustomDirectory, %vFolderSelected%
- Gui, Submit, NoHide
- }
- return
- ;When install is pressed, begin installation
- INSTALL:
- {
- IfNotExist, brunchDownloads.txt
- {
- MsgBox, 52, Error, The instruction set was deleted or malformed. Would you like to redownload the instruction set?
- IfMsgBox Yes
- DownloadFile("https://s3-us-west-2.amazonaws.com/worldofgrinding/Breakfast+Special%3A+Brunch+Files/brunchDownloads.txt", "brunchDownloads.txt")
- IfNotExist, brunchDownloads.txt
- {
- MsgBox, 0, Error, The instruction set is still missing or malformed. Please check your internet connection and rerun the installer.
- IfMsgBox OK
- {
- FileDelete, brunchExpansion.png
- FileDelete, brunchDownloads.txt
- ExitApp
- }
- }
- else
- {
- FileDelete, brunchDownloads.txt
- FileDelete, brunchExpansion.png
- ExitApp
- return
- }
- }
- ;Set error count to 0
- errors = 0
- ;Check which radio was selected and set install directory based on that.
- if directorySelected = 1
- {
- downloadTo = %A_ScriptDir%
- }
- else if directorySelected = 2
- {
- downloadTo = %vFolderSelected%
- }
- ;Make sure that the directory the user selected exists, and that it contains a mods and config folder. If any errors occur, send user back to installer.
- IfNotExist, %downloadTo%
- {
- MsgBox, 0, Error, The install folder you selected does not exist.
- errors = errors + 1
- }
- if errors > 0
- {
- return
- }
- IfNotExist, %downloadTo%\mods
- {
- MsgBox, 0, Error, The mods folder is missing. Please make sure you have installed the pack before running this and have selected the correct install directory.
- errors = errors + 1
- }
- if errors > 0
- {
- return
- }
- IfNotExist, %downloadTo%\config
- {
- MsgBox, 0, Error, The config folder is missing. Please make sure you have installed the pack before running this and have selected the correct install directory.
- errors = errors + 1
- }
- if errors > 0
- {
- return
- }
- ;If no errors are detected, hide installer GUI components;
- GuiControl, Hide, CustomDirectory
- GuiControl, Hide, CurrentDirectory
- GuiControl, Hide, BROWSEBUTTON
- GuiControl, Hide, INSTALL
- GuiControl, Hide, DirectorySelect1
- GuiControl, Hide, DirectorySelect2
- instruction =
- instructionDir =
- readLine = 0
- downloadsFinished = 0
- while downloadsFinished = 0
- {
- IfNotExist, brunchDownloads.txt
- {
- MsgBox, 52, Error, The instruction set was deleted or malformed. Would you like to redownload the instruction set?
- IfMsgBox Yes
- DownloadFile("https://s3-us-west-2.amazonaws.com/worldofgrinding/Breakfast+Special%3A+Brunch+Files/brunchDownloads.txt", "brunchDownloads.txt")
- IfNotExist, brunchDownloads.txt
- {
- MsgBox, 0, Error, The instruction set is still missing or malformed. Please check your internet connection and rerun the installer.
- IfMsgBox OK
- {
- FileDelete, brunchExpansion.png
- FileDelete, brunchDownloads.txt
- ExitApp
- }
- }
- else
- FileDelete, brunchDownloads.txt
- FileDelete, brunchExpansion.png
- ExitApp
- return
- }
- ;Check instructions from downloaded instruction set
- readLine += 1
- FileReadLine, instruction, brunchDownloads.txt, %readLine%
- readLine += 1
- FileReadLine, instructionDir, brunchDownloads.txt, %readLine%
- ;Handle current instructions using instruction codes
- if instruction = end
- {
- downloadsFinished = 1
- EndInstallation()
- break
- }
- else if instruction = del
- {
- FileDelete, %downloadTo%%instructionDir%
- }
- else if instruction = mkdir
- {
- IfNotExist, %downloadTo%%instructionDir%
- {
- FileCreateDir, %downloadTo%%instructionDir%
- }
- }
- else if instruction = rmdir
- {
- FileRemoveDir, %downloadTo%%instructionDir%, 0
- }
- else if instruction = rmdirF
- {
- FileRemoveDir, %downloadTo%%instructionDir%, 1
- }
- else if instruction = ver
- {
- MsgBox, 68, Confirm Install, This will install version %instructionDir% of the Brunch Expansion. Are you sure you want to continue?
- IfMsgBox No
- {
- FileDelete, brunchDownloads.txt
- FileDelete, brunchExpansion.png
- ExitApp
- return
- }
- }
- else
- {
- DownloadFile(instruction, downloadTo . instructionDir)
- }
- }
- }
- return
- EndInstallation()
- {
- ;When installation finishes, show install complete message and finish button.
- GuiControl, show, InstallComplete
- GuiControl, show, FINISH
- return
- }
- ;File Downloader by Bruttosozialprodukt
- DownloadFile(UrlToFile, SaveFileAs, Overwrite := True, UseProgressBar := True) {
- ;Check if the file already exists and if we must not overwrite it
- If (!Overwrite && FileExist(SaveFileAs))
- Return
- ;Check if the user wants a progressbar
- If (UseProgressBar) {
- ;Initialize the WinHttpRequest Object
- WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
- ;Download the headers
- WebRequest.Open("HEAD", UrlToFile)
- WebRequest.Send()
- ;Store the header which holds the file size in a variable:
- FinalSize := WebRequest.GetResponseHeader("Content-Length")
- ;Create the progressbar and the timer
- Progress, H80, , Downloading..., %UrlToFile%
- SetTimer, __UpdateProgressBar, 100
- }
- ;Download the file
- UrlDownloadToFile, %UrlToFile%, %SaveFileAs%
- ;Remove the timer and the progressbar because the download has finished
- If (UseProgressBar) {
- Progress, Off
- SetTimer, __UpdateProgressBar, Off
- }
- Return
- ;The label that updates the progressbar
- __UpdateProgressBar:
- ;Get the current filesize and tick
- CurrentSize := FileOpen(SaveFileAs, "r").Length ;FileGetSize wouldn't return reliable results
- CurrentSizeTick := A_TickCount
- ;Calculate the downloadspeed
- Speed := Round((CurrentSize/1024-LastSize/1024)/((CurrentSizeTick-LastSizeTick)/1000)) . " Kb/s"
- ;Save the current filesize and tick for the next time
- LastSizeTick := CurrentSizeTick
- LastSize := FileOpen(SaveFileAs, "r").Length
- ;Calculate percent done
- PercentDone := Round(CurrentSize/FinalSize*100)
- ;Update the ProgressBar
- Progress, %PercentDone%, %PercentDone%`% Done, Downloading... (%Speed%), Downloading %SaveFileAs% (%PercentDone%`%)
- Return
- }
- <^<!l::
- ;Debug enabler
- InputBox, vDebug, Debug Password, Enter Debug Password, HIDE, 300, 150,
- if vDebug = rainbows
- {
- debugEnabled = 1
- MsgBox, 0, Debug Enabled, Debug Hotkeys Enabled,
- }
- else
- {
- MsgBox, 0, Incorrect, Specified Password was Incorrect,
- }
- return
- ;Handle close of installer if the user closes the GUI or presses finish.
- FINISH:
- FileDelete, brunchExpansion.png
- FileDelete, brunchDownloads.txt
- ExitApp
- GuiClose:
- FileDelete, brunchExpansion.png
- FileDelete, brunchDownloads.txt
- ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement