From efb426c5173492d28967de53a46564ad66dd98dd Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Mon, 16 Sep 2024 09:28:32 +0700 Subject: [PATCH] Fix #1216 - remove create shortcut item task and move download llamacpp engine to install dialog (#1219) * Fix #1216 - remove create shortcut item task and move download llamacpp engine to install dialog * Resolved comment typo llama.cpp --------- Co-authored-by: Hien To --- engine/templates/windows/installer-beta.iss | 65 ++++++++--------- .../templates/windows/installer-nightly.iss | 67 ++++++++---------- engine/templates/windows/installer.iss | 69 ++++++++----------- 3 files changed, 84 insertions(+), 117 deletions(-) diff --git a/engine/templates/windows/installer-beta.iss b/engine/templates/windows/installer-beta.iss index b514abeac..56feecd6e 100644 --- a/engine/templates/windows/installer-beta.iss +++ b/engine/templates/windows/installer-beta.iss @@ -26,56 +26,37 @@ Source: "vcruntime140_1.dll"; DestDir: "{app}"; Flags: ignoreversion [Icons] Name: "{group}\cortexcpp-beta"; Filename: "{app}\cortex-beta.exe" -; Define the run section to execute the application after installation -[Run] -Filename: "{app}\cortex-beta.exe"; Parameters: "engines install cortex.llamacpp"; WorkingDir: "{app}"; StatusMsg: "Initializing cortex configuration..."; Flags: nowait postinstall +; Define the uninstall run section to execute commands before uninstallation +[UninstallRun] +Filename: "{app}\cortex-beta.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp-beta service..."; Flags: runhidden + +; Combine all Pascal scripting code in one [Code] section [Code] -procedure AddToUserPath; +procedure AddToUserPathAndInstallEngines; var ExpandedAppDir: String; - CmdLine: String; + CmdLine, CortexInstallCmd: String; ResultCode: Integer; begin ExpandedAppDir := ExpandConstant('{app}'); + // Add {app} to PATH CmdLine := Format('setx PATH "%s;%%PATH%%"', [ExpandedAppDir]); - - if Exec('cmd.exe', '/C ' + CmdLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then - begin - if ResultCode = 0 then - MsgBox('Successfully added to user PATH.', mbInformation, MB_OK) - else - MsgBox('Failed to update user PATH. Error code: ' + IntToStr(ResultCode), mbError, MB_OK); - end - else - begin - MsgBox('Failed to execute setx command.', mbError, MB_OK); - end; -end; + Exec('cmd.exe', '/C ' + CmdLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); -procedure CurStepChanged(CurStep: TSetupStep); -begin - if CurStep = ssPostInstall then - begin - AddToUserPath; - end; -end; + // Update status message for downloading llamacpp engine + WizardForm.StatusLabel.Caption := 'Downloading llama.cpp engine and dependencies ...'; + WizardForm.StatusLabel.Update; -[Tasks] -Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; Flags: unchecked -Name: "quicklaunchicon"; Description: "Create a &Quick Launch icon"; GroupDescription: "Additional icons:"; Flags: unchecked + // Download llamacpp engine by default + CortexInstallCmd := Format('"%s\cortex-beta.exe" engines install cortex.llamacpp', [ExpandedAppDir]); + Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); -; Define icons for the additional tasks -[Icons] -Name: "{commondesktop}\cortexcpp-beta"; Filename: "{app}\cortex-beta.exe"; Tasks: desktopicon -Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\cortexcpp-beta"; Filename: "{app}\cortex-beta.exe"; Tasks: quicklaunchicon - -; Define the uninstall run section to execute commands before uninstallation -[UninstallRun] -Filename: "{app}\cortex-beta.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp-beta service..."; Flags: runhidden + // Clear the status message after completion + WizardForm.StatusLabel.Caption := ''; + WizardForm.StatusLabel.Update; +end; -; Use Pascal scripting to ask user if they want to delete the cortexcpp-beta folder and .cortexrc-beta file -[Code] procedure DeleteCurrentUserCortexFolderAndConfig; var UserCortexFolder: String; @@ -104,6 +85,14 @@ begin end; end; +procedure CurStepChanged(CurStep: TSetupStep); +begin + if CurStep = ssPostInstall then + begin + AddToUserPathAndInstallEngines; + end; +end; + procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if CurUninstallStep = usPostUninstall then diff --git a/engine/templates/windows/installer-nightly.iss b/engine/templates/windows/installer-nightly.iss index e72e71c56..9e5ce68d0 100644 --- a/engine/templates/windows/installer-nightly.iss +++ b/engine/templates/windows/installer-nightly.iss @@ -26,56 +26,37 @@ Source: "vcruntime140_1.dll"; DestDir: "{app}"; Flags: ignoreversion [Icons] Name: "{group}\cortexcpp-nightly"; Filename: "{app}\cortex-nightly.exe" -; Define the run section to execute the application after installation -[Run] -Filename: "{app}\cortex-nightly.exe"; Parameters: "engines install cortex.llamacpp"; WorkingDir: "{app}"; StatusMsg: "Initializing cortex configuration..."; Flags: nowait postinstall +; Define the uninstall run section to execute commands before uninstallation +[UninstallRun] +Filename: "{app}\cortex-nightly.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp-nightly service..."; Flags: runhidden + +; Combine all Pascal scripting code in one [Code] section [Code] -procedure AddToUserPath; +procedure AddToUserPathAndInstallEngines; var ExpandedAppDir: String; - CmdLine: String; + CmdLine, CortexInstallCmd: String; ResultCode: Integer; begin ExpandedAppDir := ExpandConstant('{app}'); + // Add {app} to PATH CmdLine := Format('setx PATH "%s;%%PATH%%"', [ExpandedAppDir]); - - if Exec('cmd.exe', '/C ' + CmdLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then - begin - if ResultCode = 0 then - MsgBox('Successfully added to user PATH.', mbInformation, MB_OK) - else - MsgBox('Failed to update user PATH. Error code: ' + IntToStr(ResultCode), mbError, MB_OK); - end - else - begin - MsgBox('Failed to execute setx command.', mbError, MB_OK); - end; -end; - -procedure CurStepChanged(CurStep: TSetupStep); -begin - if CurStep = ssPostInstall then - begin - AddToUserPath; - end; -end; + Exec('cmd.exe', '/C ' + CmdLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); -[Tasks] -Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; Flags: unchecked -Name: "quicklaunchicon"; Description: "Create a &Quick Launch icon"; GroupDescription: "Additional icons:"; Flags: unchecked + // Update status message for downloading llamacpp engine + WizardForm.StatusLabel.Caption := 'Downloading llama.cpp engine and dependencies ...'; + WizardForm.StatusLabel.Update; -; Define icons for the additional tasks -[Icons] -Name: "{commondesktop}\cortexcpp-nightly"; Filename: "{app}\cortex-nightly.exe"; Tasks: desktopicon -Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\cortexcpp-nightly"; Filename: "{app}\cortex-nightly.exe"; Tasks: quicklaunchicon + // Download llamacpp engine by default + CortexInstallCmd := Format('"%s\cortex-nightly.exe" engines install cortex.llamacpp', [ExpandedAppDir]); + Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); -; Define the uninstall run section to execute commands before uninstallation -[UninstallRun] -Filename: "{app}\cortex-nightly.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp-nightly service..."; Flags: runhidden + // Clear the status message after completion + WizardForm.StatusLabel.Caption := ''; + WizardForm.StatusLabel.Update; +end; -; Use Pascal scripting to ask user if they want to delete the cortexcpp-nightly folder and .cortexrc-nightly file -[Code] procedure DeleteCurrentUserCortexFolderAndConfig; var UserCortexFolder: String; @@ -104,10 +85,18 @@ begin end; end; +procedure CurStepChanged(CurStep: TSetupStep); +begin + if CurStep = ssPostInstall then + begin + AddToUserPathAndInstallEngines; + end; +end; + procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if CurUninstallStep = usPostUninstall then begin DeleteCurrentUserCortexFolderAndConfig; end; -end; +end; \ No newline at end of file diff --git a/engine/templates/windows/installer.iss b/engine/templates/windows/installer.iss index ff6c7fe0b..32a0dfe09 100644 --- a/engine/templates/windows/installer.iss +++ b/engine/templates/windows/installer.iss @@ -26,68 +26,49 @@ Source: "vcruntime140_1.dll"; DestDir: "{app}"; Flags: ignoreversion [Icons] Name: "{group}\cortexcpp"; Filename: "{app}\cortex.exe" -; Define the run section to execute the application after installation -[Run] -Filename: "{app}\cortex.exe"; Parameters: "engines install cortex.llamacpp"; WorkingDir: "{app}"; StatusMsg: "Initializing cortex configuration..."; Flags: nowait postinstall +; Define the uninstall run section to execute commands before uninstallation +[UninstallRun] +Filename: "{app}\cortex.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp service..."; Flags: runhidden + +; Combine all Pascal scripting code in one [Code] section [Code] -procedure AddToUserPath; +procedure AddToUserPathAndInstallEngines; var ExpandedAppDir: String; - CmdLine: String; + CmdLine, CortexInstallCmd: String; ResultCode: Integer; begin ExpandedAppDir := ExpandConstant('{app}'); + // Add {app} to PATH CmdLine := Format('setx PATH "%s;%%PATH%%"', [ExpandedAppDir]); - - if Exec('cmd.exe', '/C ' + CmdLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then - begin - if ResultCode = 0 then - MsgBox('Successfully added to user PATH.', mbInformation, MB_OK) - else - MsgBox('Failed to update user PATH. Error code: ' + IntToStr(ResultCode), mbError, MB_OK); - end - else - begin - MsgBox('Failed to execute setx command.', mbError, MB_OK); - end; -end; + Exec('cmd.exe', '/C ' + CmdLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); -procedure CurStepChanged(CurStep: TSetupStep); -begin - if CurStep = ssPostInstall then - begin - AddToUserPath; - end; -end; + // Update status message for downloading llamacpp engine + WizardForm.StatusLabel.Caption := 'Downloading llama.cpp engine and dependencies ...'; + WizardForm.StatusLabel.Update; -[Tasks] -Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; Flags: unchecked -Name: "quicklaunchicon"; Description: "Create a &Quick Launch icon"; GroupDescription: "Additional icons:"; Flags: unchecked + // Download llamacpp engine by default + CortexInstallCmd := Format('"%s\cortex.exe" engines install cortex.llamacpp', [ExpandedAppDir]); + Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); -; Define icons for the additional tasks -[Icons] -Name: "{commondesktop}\cortexcpp"; Filename: "{app}\cortex.exe"; Tasks: desktopicon -Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\cortexcpp"; Filename: "{app}\cortex.exe"; Tasks: quicklaunchicon - -; Define the uninstall run section to execute commands before uninstallation -[UninstallRun] -Filename: "{app}\cortex.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp service..."; Flags: runhidden + // Clear the status message after completion + WizardForm.StatusLabel.Caption := ''; + WizardForm.StatusLabel.Update; +end; -; Use Pascal scripting to ask user if they want to delete the .cortex folder and .cortexrc file -[Code] procedure DeleteCurrentUserCortexFolderAndConfig; var UserCortexFolder: String; UserCortexConfig: String; ShouldDelete: Integer; begin - UserCortexFolder := ExpandConstant('{%USERPROFILE}\.cortex'); + UserCortexFolder := ExpandConstant('{%USERPROFILE}\cortexcpp'); UserCortexConfig := ExpandConstant('{%USERPROFILE}\.cortexrc'); if DirExists(UserCortexFolder) or FileExists(UserCortexConfig) then begin - ShouldDelete := MsgBox('Do you want to delete the application data in .cortex and the .cortexrc config file (this will remove all user data)?', mbConfirmation, MB_YESNO); + ShouldDelete := MsgBox('Do you want to delete the application data in cortexcpp and the .cortexrc config file (this will remove all user data)?', mbConfirmation, MB_YESNO); if ShouldDelete = idYes then begin @@ -104,6 +85,14 @@ begin end; end; +procedure CurStepChanged(CurStep: TSetupStep); +begin + if CurStep = ssPostInstall then + begin + AddToUserPathAndInstallEngines; + end; +end; + procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if CurUninstallStep = usPostUninstall then