📄 install.vbs
字号:
Option Explicit ' Variables must be declared explicitly'******************************************************************************' Installer defaults.'******************************************************************************const AppName = "cc65"const Version = "2.11.0"const Installer = "cc65 Installer"const SpaceNeeded = 20 ' Free space needed on drive in MBconst Shortcut = true ' Create shortcut on desktop'******************************************************************************' Global constants'******************************************************************************const SysEnv = "HKLM\System\CurrentControlSet\Control\Session Manager\Environment"const SysPath = "HKLM\System\CurrentControlSet\Control\Session Manager\Environment\Path"'******************************************************************************' Global variables'******************************************************************************dim Tab, NewLine ' String constantsdim Shell, FSO ' Global objectsdim ProgArgs ' Program argumentsdim Dbg ' Output debugging stuffdim Language ' Program languagedim SystemDrive ' The system drivedim SystemRoot ' The windows directorydim UserName ' Name if the current userdim UserProfile ' User profile directorydim ProgramFiles ' Program files directorydim AppData ' Application data directorydim InstallSource ' Installation source directorydim InstallTarget ' Installation target directorydim UninstallCtrlFileName ' Name of the control file for the uninstallerdim UninstallCtrlFile ' Control file for the uninstallerdim Uninstaller ' Path to the uninstaller filedim UninstallerCmdLine ' Command line for the uninstallerdim Programs ' "Programs" menu folderdim Desktop ' "Desktop" menu folderdim RegUninstall ' Registry key for uninstall entriesdim BinDir ' Directory for binariesdim LibDir ' Library directorydim IncDir ' Include directorydim DocIndexFile ' Name of documentation index filedim AnnouncementFile ' Name of the announcement file'******************************************************************************' Display an error message window with an OK button'******************************************************************************sub ErrorMsg (Msg) call MsgBox (Msg, vbOkOnly + vbExclamation, Installer)end sub'******************************************************************************' Display an error message window and abort the installer'******************************************************************************sub Abort (Msg) call ErrorMsg (Msg) WScript.Quit (1)end sub'******************************************************************************' Display a message with an OK button'******************************************************************************sub Message (Msg) call MsgBox (Msg, vbOkOnly + vbInformation, Installer)end sub'******************************************************************************' Convert a number to a string'******************************************************************************function ToString (Num) ToString = FormatNumber (Num, vbFalse, vbTrue, vbFalse, vbFalse)end function'******************************************************************************' Return a message in the current language'******************************************************************************function GetMsg (Key) dim Msg ' Handle other languages here ' Default is english if IsEmpty (Msg) then ' No assignment, use english select case Key case "MSG_ABORTINFO" Msg = "Installation was aborted." case "MSG_ADMIN" Msg = "You must be Administrator to install %1." Msg = Msg & " Are you sure you want to continue?" case "MSG_COPYERR" Msg = "Cannot copy %1 to %2: " & NewLine & "%3" case "MSG_CREATEDIR" Msg = "%1 does not exist." & NewLine & "Create it?" case "MSG_CREATEERR" Msg = "Cannot create %1:" & NewLine & "%2" case "MSG_DELETEERR" Msg = "Cannot delete %1:" & NewLine & "%2" case "MSG_DRIVESPACE" Msg = "Not enough space left on drive %1" & NewLine Msg = Msg & "At least %2 MB are needed." case "MSG_INSTALLPATH" Msg = "The package will be installed in %1" case "MSG_DOCENTRY" Msg = "%1 Documentation" case "MSG_REGREADERR" Msg = "Installation failed: Cannot read the registry!" case "MSG_REGWRITEERR" Msg = "Installation failed: Cannot write to the registry!" case "MSG_REMOVEENTRY" Msg = "Remove %1" case "MSG_REMOVEDIR" Msg = "A folder with the name %1 does already exist." Msg = Msg & " Is it ok to remove the folder?" case "MSG_REMOVEOLD" Msg = "Found an old version. Remove it?" case "MSG_SUCCESS" Msg = "Installation was successful!" case "MSG_UNINSTALLERR" Msg = "There was a problem uninstalling the old version. Please" Msg = Msg & " uninstall the old program manually and restart" Msg = Msg & " the installation." case "MSG_ANNOUNCEMENT" Msg = "cc65 Announcement" case "MSG_INCOMPLETE" Msg = "The package seems to be incomplete and cannot be" Msg = Msg & " installed." case else Msg = Key end select end if GetMsg = Msgend function'******************************************************************************' Format a string replacing %n specifiers in the format string F'******************************************************************************function Fmt (F, Values) dim I, Count, Key, Val, Start, Pos Count = UBound (Values) ' How many values? for I = Count to 0 step -1 Key = "%" & ToString (I) select case VarType (Values (I)) case vbEmpty Val = "" case vbInteger Val = ToString (Values (I)) case vbLong Val = ToString (Values (I)) case vbNull Val = "" case vbSingle Val = ToString (Values (I)) case vbDouble Val = ToString (Values (I)) case vbString Val = Values (I) case else Abort ("Internal error: Invalid conversion in Format()") end select F = Replace (F, Key, Val) next Fmt = Fend function'******************************************************************************' Format a message replacing %n specifiers in the format string F'******************************************************************************function FmtMsg (Msg, Values) FmtMsg = Fmt (GetMsg (Msg), Values)end function'******************************************************************************' Return an environment string. Fix up Microsofts "innovative" ideas.'******************************************************************************function GetEnv (Key) dim Value Value = Shell.ExpandEnvironmentStrings (Key) if Value = Key then GetEnv = vbNullString else GetEnv = Value end ifend function'******************************************************************************' Build a path from two components'******************************************************************************function BuildPath (Path, Name) BuildPath = FSO.BuildPath (Path, Name)end function'******************************************************************************' Return true if the file with the given name exists'******************************************************************************function FileExists (Name) On Error Resume Next FileExists = FSO.FileExists (Name)end function'******************************************************************************' Return true if the folder with the given name exists'******************************************************************************function FolderExists (Name) On Error Resume Next FolderExists = FSO.FolderExists (Name)end function'******************************************************************************' Copy a file and return an error message (empty string if no error)'******************************************************************************function CopyFile (Source, Target) if Right (Target, 1) <> "\" and FolderExists (Target) then Target = Target & "\" end if On Error Resume Next call FSO.CopyFile (Source, Target) on error goto 0 CopyFile = Err.Descriptionend function'******************************************************************************' Create a folder and all parent folders and return an error string'******************************************************************************function CreateFolder (Path) ' If the parent folder does not exist, try to create it dim ParentFolder ParentFolder = FSO.GetParentFolderName (Path) if ParentFolder <> "" and not FolderExists (ParentFolder) then CreateFolder (ParentFolder) end if ' Now try to create the actual folder On Error Resume Next FSO.CreateFolder (Path) CreateFolder = Err.Descriptionend function'******************************************************************************' Delete a file and return an error string'******************************************************************************function DeleteFile (Name) On Error Resume Next call FSO.DeleteFile (Name, true) DeleteFile = Err.Descriptionend function'******************************************************************************' Delete a folder and return an error string'******************************************************************************function DeleteFolder (Path) On Error Resume Next call FSO.DeleteFolder (Path, true) DeleteFolder = Err.Descriptionend function'******************************************************************************' Return the type of a registry entry'******************************************************************************function RegType (Value) dim Result ' Determine the type of the registry value. If the string contains percent ' signs, use REG_EXPAND_SZ, otherwise use REG_SZ. This isn't always safe, ' but there is no way to determine the type, and VBS itself is too stupid ' to choose the correct type itself. Add the usual curse over Microsoft ' here... Result = InStr (1, Value, "%") if Result = 0 then RegType = "REG_SZ" else RegType = "REG_EXPAND_SZ" end ifend function'******************************************************************************' Read a string from the registry. Return an empty string if nothing was found.'******************************************************************************function RegReadStr (Key) On Error Resume Next RegReadStr = Shell.RegRead (Key) if Err.Number <> 0 then RegReadStr = "" end ifend function'******************************************************************************' Write a binary value to the registry, return an error description'******************************************************************************function RegWriteBin (Key, Value) on error resume next Shell.RegWrite Key, Value, "REG_BINARY" RegWriteBin = Err.Description on error goto 0 WriteUninstallCtrlFile ("R " & Key)end function'******************************************************************************' Write a string value to the registry, return an error description'******************************************************************************function RegWriteStr (Key, Value) on error resume next Shell.RegWrite Key, Value, "REG_SZ" RegWriteStr = Err.Description on error goto 0 WriteUninstallCtrlFile ("R " & Key)end function'******************************************************************************' Run a program, wait for its termination and return an error code.'******************************************************************************function Run (Cmd, WinState) dim ErrCode On Error Resume Next ErrCode = Shell.Run (Cmd, WinState, true) if Err.Number <> 0 then ErrCode = Err.Number end if Run = ErrCodeend function'******************************************************************************' Display a progress bar using the internet exploder'******************************************************************************dim PBDoc ' Progress bar document objectdim PBVal ' Current progress bar settingdim IEApp ' Internet exploder application objectset PBDoc = nothingset IEApp = nothingPBVal = -1sub ProgressBar (Percent) ' Remember the last setting PBVal = Percent 'Create the progress bar window if PBDoc is nothing then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -