Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Script generated by the Inno Setup Script Wizard.
- ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
- #define MyAppName "Stable Projectorz"
- #define MyAppVersion "1.1.2"
- #define MyAppPublisher "Igor Aherne"
- #define MyAppURL "https://stableprojectorz.com"
- #define MyAppExeName "Stable Projectorz.exe"
- #define MyAppAssocName MyAppName + " File"
- #define MyAppAssocExt ".strz"
- #define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt
- [Setup]
- ; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
- ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
- AppId=COMMENTED OUT FOR REDDIT
- AppName={#MyAppName}
- AppVersion={#MyAppVersion}
- SetupIconFile=icon.ico
- ;AppVerName={#MyAppName} {#MyAppVersion}
- AppPublisher={#MyAppPublisher}
- AppPublisherURL={#MyAppURL}
- AppSupportURL={#MyAppURL}
- AppUpdatesURL={#MyAppURL}
- ; NOTE: THIS WON'T WORK: DefaultDirName={autopf}\{#MyAppName} Because our 'webui-user.bat' won't be able to run inside Program Files (due to UAC on user computers). Therefore using {userdocs}
- DefaultDirName={userdocs}\{#MyAppName}
- ChangesAssociations=yes
- ; commented out because if AppId (see above) is already found on user machine, we need to update it into the same dir,
- ; rather than letting them install it elsewhere. (would need user to re-donwload webui nets). Also, new users will need to select dir anyway.
- ; This is important becuse DisableDirPage=no forces users to pick dir even if updating. And DisableDirPage=yes will install into into incompatible dir for the new users (Program Files) where StableProjectorz can't run.
- ;DisableDirPage=no
- DisableWelcomePage=no
- WizardImageFile=InstallerIllustration.bmp
- WizardStyle=modern
- DisableProgramGroupPage=yes
- ; Remove the following line to run in administrative install mode (install for all users.);
- PrivilegesRequired=admin
- PrivilegesRequiredOverridesAllowed=commandline
- OutputDir=C:\_myDrive\repos\StableDiffusion_unity\InnoSetup
- ; Will be compiling into StableProjectorz_v1_(Installer).exe
- OutputBaseFilename=StableProjectorz_v1_1_2(Installer)
- Compression=lzma
- SolidCompression=yes
- LicenseFile=License.rtf
- InfoBeforeFile=CurrentVersionFeatures.rtf
- ; IMPORTANT!!! Otherwise cmd prompt isn't restarted. And git (that was just installed) wont't avaialble in any child cmd prompts that are initiated after/by the installer.
- AlwaysRestart=yes
- [Languages]
- Name: "english"; MessagesFile: "compiler:Default.isl"
- [Tasks]
- Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
- [Files]
- Source: "C:\_myDrive\repos\StableDiffusion_unity\Builds\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
- Source: "C:\_myDrive\repos\StableDiffusion_unity\Builds\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
- Source: "Dependencies\TEST MESHES\*"; DestDir: "{app}\TEST MESHES"; Flags: ignoreversion recursesubdirs createallsubdirs
- Source: "Dependencies\python-3.10.6-amd64.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
- Source: "Dependencies\stable-diffusion-webui-master.zip"; DestDir: "{tmp}"; Flags: deleteafterinstall
- ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
- [Registry]
- Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
- Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
- Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
- Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
- Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""
- [Icons]
- Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
- Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
- [Run]
- Filename: "{tmp}\python-3.10.6-amd64.exe"; Parameters: "/quiet InstallAllUsers=1 PrependPath=1"; WorkingDir: "{tmp}"; Flags: runhidden waituntilterminated; Check: not PythonIsAlreadyInstalled; AfterInstall: GetPythonInstallPath; StatusMsg: "Installing Python 3.10.6, please wait..."
- Filename: "{tmp}\Git-2.43.0-64-bit.exe"; Parameters: "/SILENT"; Check: not IsGitInstalled; StatusMsg: "Downloading + Installing Git, please wait...";
- Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent; StatusMsg: "Finalizing installation..."
- ; NOTE: Check: not isWebUINotNeeded ensures we won't unpack nor update the webui repo, if it already exists in the destination folder. User might have large neural nets there. Also, the order of parameters isn't important, don't worry that 'Check:' is last in that line:
- Filename: "powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -Command ""Expand-Archive -LiteralPath '{tmp}\stable-diffusion-webui-master.zip' -DestinationPath '{app}'"""; Flags: runhidden; StatusMsg: "Extracting stable-diffusion-webui..."; AfterInstall: UpdateWebUIUserBatFile; Check: not IsWebUINotNeeded
- [Code]
- function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
- begin
- Result := True;
- end;
- var
- ProgramFiles32Dir: string;
- ProgramFiles64Dir: string;
- DownloadPage: TDownloadWizardPage;
- function InitializeSetup(): Boolean;
- begin
- // Expand constants for directory checking
- ProgramFiles32Dir := ExpandConstant('{pf32}');
- ProgramFiles64Dir := ExpandConstant('{pf64}');
- Result := True;
- end;
- // InitializeWizard() is a special event function that is automatically called by the Inno Setup engine
- // during the installation process. You don't need to explicitly invoke it yourself.
- // Shows a custom page at the start of the installation with the illustration. Makes it look professional:)
- procedure InitializeWizard;
- begin
- // Initialize the download page for Git
- DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);
- // Hide the default welcome labels
- WizardForm.WelcomeLabel2.Visible := True;
- WizardForm.WelcomeLabel2.Caption := 'This will install Stable Projectorz version 1.1.2 on your computer.' + #13#10
- + 'Will also install dependencies: Github (Git) and Python 3.10.6' + #13#10 + #13#10 + 'It is recommended that you close all other applications before continuing.'
- + #13#10 + #13#10 + #13#10 + 'Stable Projectorz is a free tool for texturing 3d models using AI, on your own computer.' + #13#10 + #13#10 +
- 'It runs Stable Diffusion on your computer (via Automatic1111 webui) to generate images.' + #13#10 + #13#10 +
- 'See https://stableprojectorz.com for tutorials, tips and our Discord community.'+ #13#10 + #13#10 + 'Version 1.1.2 (Jan 2024)';
- end;
- function IsGitInstalled: Boolean;
- var
- ErrorCode: Integer;
- begin
- // Check if 'git --version' command can be executed successfully
- Result := Exec('git', '--version', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode) and (ErrorCode = 0);
- end;
- function NextButtonClick(CurPageID: Integer): Boolean;
- var
- SelectedDir: string;
- ErrorCode: Integer;
- begin
- Result := True;
- // Check for directory selection
- if CurPageID = wpSelectDir then
- begin
- SelectedDir := WizardDirValue(); // Get the selected directory
- // Prevent user from selecting destination to be `Program Files` or `Program Files (x86)`.
- // This will allow our webui to correctly run, and download torch, stablediffusion etc.
- // Check if the selected directory is under Program Files.
- if (Pos(ProgramFiles32Dir, SelectedDir) = 1) or
- (Pos(ProgramFiles64Dir, SelectedDir) = 1) then
- begin
- MsgBox('Installing Stable Projectorz in the Program Files directory may be restrictive. Please select a different destination directory that Windows won''t worry about. For example, C:\Users\Yourname\Documents\', mbError, MB_OK);
- Result := False; // Prevent moving to the next page
- Exit;
- end;
- end;
- // Check for ready to install page and download/install Git if needed
- if (CurPageID = wpReady) then
- begin
- if not IsGitInstalled then
- begin
- DownloadPage.Clear;
- DownloadPage.Add('https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/Git-2.43.0-64-bit.exe', 'Git-2.43.0-64-bit.exe', '');
- DownloadPage.Show;
- try
- try
- DownloadPage.Download;
- if not Exec(ExpandConstant('{tmp}\Git-2.43.0-64-bit.exe'), '/SILENT', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
- begin
- // Handle the error if Git installer fails
- MsgBox('Failed to install Git: ' + SysErrorMessage(ErrorCode), mbError, MB_OK);
- end;
- except
- SuppressibleMsgBox('Failed to download Git Installer: ' + GetExceptionMessage, mbCriticalError, MB_OK, IDOK);
- Result := False;
- end;
- finally
- DownloadPage.Hide;
- end;
- end;
- end;
- end;
- function IsWebUINotNeeded: Boolean;
- var
- WebUIDir: string;
- FindRec: TFindRec;
- begin
- WebUIDir := ExpandConstant('{app}\stable-diffusion-webui-master');
- // Check if the directory exists
- Result := DirExists(WebUIDir);
- // If the directory exists, check for files/subdirectories
- if Result then
- begin
- if FindFirst(WebUIDir + '\*', FindRec) then
- begin
- // Found files or subdirectories, so no need to unpack
- Result := True;
- FindClose(FindRec);
- end
- else
- begin
- // No files or subdirectories found, need to unpack
- Result := False;
- end;
- end;
- end;
- var
- PythonInstallPath: string;// a global variable to store the Python path
- procedure LogMessage(Message: string);
- begin
- MsgBox(Message, mbInformation, MB_OK);
- end;
- //will run after the Python installer (AfterInstall: GetPythonInstallPath).
- //It attempts to find the installation path from the registry.
- //If it's not found, you can either fall back to a default path or handle the error as needed.
- procedure GetPythonInstallPath;
- var
- InstallPath, PythonExe: string;
- begin
- // First, try to get the full path to the Python executable
- if not RegQueryStringValue(HKLM64, 'Software\Python\PythonCore\3.10\InstallPath', 'ExecutablePath', InstallPath) and
- not RegQueryStringValue(HKLM, 'Software\Python\PythonCore\3.10\InstallPath', 'ExecutablePath', InstallPath) and
- not RegQueryStringValue(HKCU64, 'Software\Python\PythonCore\3.10\InstallPath', 'ExecutablePath', InstallPath) and
- not RegQueryStringValue(HKCU, 'Software\Python\PythonCore\3.10\InstallPath', 'ExecutablePath', InstallPath) then
- begin
- // If ExecutablePath is not found, try to use the default InstallPath and append python.exe
- if RegQueryStringValue(HKLM64, 'Software\Python\PythonCore\3.10\InstallPath', '', InstallPath) or
- RegQueryStringValue(HKLM, 'Software\Python\PythonCore\3.10\InstallPath', '', InstallPath) or
- RegQueryStringValue(HKCU64, 'Software\Python\PythonCore\3.10\InstallPath', '', InstallPath) or
- RegQueryStringValue(HKCU, 'Software\Python\PythonCore\3.10\InstallPath', '', InstallPath) then
- begin
- InstallPath := AddBackslash(InstallPath) + 'python.exe';
- end
- else
- begin
- InstallPath := '';
- end;
- end;
- PythonInstallPath := InstallPath;
- end;
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
- // CHECKING IF USER HAS 3.10 (any path will do)
- // and installing our python otherwise (included into the installer)
- // This will be needed for the Automatic1111 StableDiffusion web-ui
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
- function ParseVersion(const VersionString: string; out Major, Minor, Patch: Integer): Boolean;
- var
- DotPos: Integer;
- Remaining: string;
- begin
- Result := False;
- DotPos := Pos('.', VersionString);
- if DotPos = 0 then exit;
- Major := StrToIntDef(Copy(VersionString, 1, DotPos - 1), 0);
- Remaining := Copy(VersionString, DotPos + 1, Length(VersionString));
- DotPos := Pos('.', Remaining);
- if DotPos > 0 then
- begin
- Minor := StrToIntDef(Copy(Remaining, 1, DotPos - 1), 0);
- Patch := StrToIntDef(Copy(Remaining, DotPos + 1, Length(Remaining)), 0);
- end
- else
- begin
- Minor := StrToIntDef(Remaining, 0);
- Patch := 0;
- end;
- Result := True;
- end;
- //does not check for an exact version match, but rather checks if the installed version
- // meets my criteria (major version 3, minor version 10, and patch version 6 or higher)
- // It will also return the Python installation path
- function checkKey(RegPart: Integer; const KeyBase: string; ReqMajor, ReqMinor, ReqPatch: Integer; var InstallPath: string): Boolean;
- var
- SubKeys: TArrayOfString;
- I: Integer;
- Key, InstalledVersion: string;
- Major, Minor, Patch: Integer;
- begin
- Result := False;
- InstallPath := '';
- if RegGetSubkeyNames(RegPart, KeyBase, SubKeys) then
- begin
- for I := 0 to GetArrayLength(SubKeys) - 1 do
- begin
- Key := KeyBase + '\' + SubKeys[I];
- if RegQueryStringValue(RegPart, Key, 'Version', InstalledVersion) and
- ParseVersion(InstalledVersion, Major, Minor, Patch) then
- begin
- if (Major = ReqMajor) and (Minor = ReqMinor) and (Patch >= ReqPatch) then
- begin
- if RegQueryStringValue(RegPart, Key, 'InstallPath', InstallPath) then
- begin
- Result := True;
- Break;
- end;
- end;
- end;
- end;
- end;
- end;
- function PythonIsAlreadyInstalled: Boolean;
- var
- InstallPath: string;
- begin
- // Check for both 32-bit and 64-bit installations, for all users and current user.
- Result := checkKey(HKEY_LOCAL_MACHINE, 'Software\Python\PythonCore\3.10', 3, 10, 6, InstallPath) or
- checkKey(HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Python\PythonCore\3.10', 3, 10, 6, InstallPath) or
- checkKey(HKEY_CURRENT_USER, 'Software\Python\PythonCore\3.10', 3, 10, 6, InstallPath) or
- checkKey(HKEY_CURRENT_USER, 'Software\Wow6432Node\Python\PythonCore\3.10', 3, 10, 6, InstallPath);
- // Store the installation path in a global variable if Python is found
- if Result then
- PythonInstallPath := InstallPath;
- end;
- function IsPythonVersionSuitable(Major, Minor, Patch: Integer): Boolean;
- begin
- // Accept 3.10.x where x >= 6. Does not accept 3.11 and above
- Result := (Major = 3) and (Minor = 10) and (Patch >= 6);
- end;
- function IsPythonVersionSuitableFromStr(const VersionString: string; ReqMajor, ReqMinor, ReqPatch: Integer): Boolean;
- var
- Major, Minor, Patch: Integer;
- begin
- if not ParseVersion(VersionString, Major, Minor, Patch) then
- Result := False
- else
- Result := IsPythonVersionSuitable(Major, Minor, Patch);
- end;
- // After the webui.zip is unpacked we need to modify its .bat file contents.
- // This will make use of the python-path variable (PythonInstallPath) that we've located earlier.
- //we will also add extra arguments in there, such as --ap and --xformers
- // And I want that path to be assigned inside the webui.bat correctly.
- // For example `C:\Program Files (x86)\StableProjectorz\stable-diffusion-webui-master\webui-user.bat`it looks as this by default (but might have some values already.
- procedure UpdatePythonPathInBatchFile(var Lines: TStringList; const PythonInstallPath: string);
- var
- I: Integer;
- UpdatedPath, PythonExe: string;
- begin
- PythonExe := '\python.exe';
- UpdatedPath := PythonInstallPath;
- // Ensure the path ends with \python.exe
- if (Length(UpdatedPath) < Length(PythonExe)) or
- (Copy(UpdatedPath, Length(UpdatedPath) - Length(PythonExe) + 1, Length(PythonExe)) <> PythonExe) then
- begin
- UpdatedPath := UpdatedPath + PythonExe;
- end;
- // Enclose the path in double quotes to avoid issues if it contains spaces.
- UpdatedPath := '"' + UpdatedPath + '"';
- // Update or add the PYTHON path line
- for I := 0 to Lines.Count - 1 do
- begin
- if Pos('set PYTHON=', Lines[I]) = 1 then
- begin
- Lines[I] := 'set PYTHON=' + UpdatedPath;
- Exit;
- end;
- end;
- // If PYTHON line is not found, add it
- Lines.Add('set PYTHON=' + UpdatedPath);
- end;
- procedure UpdateWebUIUserBatFile;
- var
- FileName: String;
- Lines: TStringList;
- begin
- FileName := ExpandConstant('{app}\stable-diffusion-webui-master\webui-user.bat');
- if not FileExists(FileName) then
- Exit;
- Lines := TStringList.Create;
- try
- Lines.LoadFromFile(FileName);
- UpdatePythonPathInBatchFile(Lines, PythonInstallPath);
- Lines.SaveToFile(FileName);
- finally
- Lines.Free;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement