Skip to content

Commit

Permalink
Fix #1216 - remove create shortcut item task and move download llamac…
Browse files Browse the repository at this point in the history
…pp 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 <[email protected]>
  • Loading branch information
hiento09 and hientominh authored Sep 16, 2024
1 parent 7875eda commit efb426c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 117 deletions.
65 changes: 27 additions & 38 deletions engine/templates/windows/installer-beta.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
67 changes: 28 additions & 39 deletions engine/templates/windows/installer-nightly.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
69 changes: 29 additions & 40 deletions engine/templates/windows/installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit efb426c

Please sign in to comment.