1- ; Inno Setup Script
21; Define the application name, version, and other details
32[Setup]
4- AppName = Cortexso
3+ AppName = cortexcpp
54AppVersion = 1.0
6- DefaultDirName = {pf} \Cortexso
7- DefaultGroupName = Cortexso
5+ DefaultDirName = {localappdata} \cortexcpp
6+ DefaultGroupName = cortexcpp
87OutputDir = .
98OutputBaseFilename = setup
109Compression = lzma
1110SolidCompression = yes
12- PrivilegesRequired = admin
11+ PrivilegesRequired = lowest
12+ AllowNoIcons = yes
1313
1414; Define the languages section
1515[Languages]
@@ -18,61 +18,88 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
1818; Define the files to be installed
1919[Files]
2020Source : " cortex.exe" ; DestDir : " {app} " ; Flags : ignoreversion
21+ Source : " msvcp140.dll" ; DestDir : " {app} " ; Flags : ignoreversion
22+ Source : " vcruntime140.dll" ; DestDir : " {app} " ; Flags : ignoreversion
23+ Source : " vcruntime140_1.dll" ; DestDir : " {app} " ; Flags : ignoreversion
2124
2225; Define the icons to be created
2326[Icons]
24- Name : " {group} \Cortexso " ; Filename : " {app} \cortex.exe"
27+ Name : " {group} \cortexcpp " ; Filename : " {app} \cortex.exe"
2528
2629; Define the run section to execute the application after installation
2730[Run]
28- Filename : " cmd" ; Parameters : " /c setx PATH " " %PATH %;{app} " " " ; StatusMsg : " Updating system PATH environment variable..." ; Flags : runhidden
29- Filename : " {app} \cortex.exe" ; Description : " {cm:LaunchProgram,Cortexso}" ; Flags : nowait postinstall skipifsilent
31+ Filename : " {app} \cortex.exe" ; Parameters : " --help" ; WorkingDir : " {app} " ; StatusMsg : " Initializing cortex configuration..." ; Flags : nowait postinstall
32+ [Code]
33+ procedure AddToUserPath ;
34+ var
35+ ExpandedAppDir: String;
36+ CmdLine: String;
37+ ResultCode: Integer;
38+ begin
39+ ExpandedAppDir := ExpandConstant(' {app}' );
40+
41+ CmdLine := Format(' setx PATH "%s;%%PATH%%"' , [ExpandedAppDir]);
42+
43+ if Exec(' cmd.exe' , ' /C ' + CmdLine, ' ' , SW_HIDE, ewWaitUntilTerminated, ResultCode) then
44+ begin
45+ if ResultCode = 0 then
46+ MsgBox(' Successfully added to user PATH.' , mbInformation, MB_OK)
47+ else
48+ MsgBox(' Failed to update user PATH. Error code: ' + IntToStr(ResultCode), mbError, MB_OK);
49+ end
50+ else
51+ begin
52+ MsgBox(' Failed to execute setx command.' , mbError, MB_OK);
53+ end ;
54+ end ;
55+
56+ procedure CurStepChanged (CurStep: TSetupStep);
57+ begin
58+ if CurStep = ssPostInstall then
59+ begin
60+ AddToUserPath;
61+ end ;
62+ end ;
3063
31- ; Define the tasks section (optional, for additional tasks like creating desktop icons)
3264[Tasks]
3365Name : " desktopicon" ; Description : " Create a &desktop icon" ; GroupDescription: " Additional icons:" ; Flags : unchecked
3466Name : " quicklaunchicon" ; Description : " Create a &Quick Launch icon" ; GroupDescription: " Additional icons:" ; Flags : unchecked
3567
3668; Define icons for the additional tasks
3769[Icons]
38- Name : " {commondesktop}\Cortexso " ; Filename : " {app} \cortex.exe" ; Tasks: desktopicon
39- Name : " {userappdata}\Microsoft\Internet Explorer\Quick Launch\Cortexso " ; Filename : " {app} \cortex.exe" ; Tasks: quicklaunchicon
70+ Name : " {commondesktop}\cortexcpp " ; Filename : " {app} \cortex.exe" ; Tasks: desktopicon
71+ Name : " {userappdata}\Microsoft\Internet Explorer\Quick Launch\cortexcpp " ; Filename : " {app} \cortex.exe" ; Tasks: quicklaunchicon
4072
4173; Define the uninstall run section to execute commands before uninstallation
4274[UninstallRun]
43- Filename : " {app} \cortex.exe" ; Parameters : " stop" ; StatusMsg : " Stopping Cortexso service..." ; Flags : runhidden
75+ Filename : " {app} \cortex.exe" ; Parameters : " stop" ; StatusMsg : " Stopping cortexcpp service..." ; Flags : runhidden
4476
45- ; Use Pascal scripting to delete the directory for all users
77+ ; Use Pascal scripting to ask user if they want to delete the .cortex folder and .cortexrc file
4678[Code]
47- function GetUsersFolder : String;
48- var
49- WinDir: String;
50- begin
51- WinDir := ExpandConstant(' {win}' );
52- Result := Copy(WinDir, 1 , Pos(' \Windows' , WinDir) - 1 ) + ' \Users' ;
53- end ;
54-
55- procedure DeleteUserCortexFolder ;
79+ procedure DeleteCurrentUserCortexFolderAndConfig ;
5680var
57- UsersFolder: String;
58- FindRec: TFindRec;
81+ UserCortexFolder: String;
82+ UserCortexConfig: String;
83+ ShouldDelete: Integer;
5984begin
60- UsersFolder := GetUsersFolder;
61- if FindFirst(UsersFolder + ' \*' , FindRec) then
85+ UserCortexFolder := ExpandConstant(' {%USERPROFILE}\.cortex' );
86+ UserCortexConfig := ExpandConstant(' {%USERPROFILE}\.cortexrc' );
87+
88+ if DirExists(UserCortexFolder) or FileExists(UserCortexConfig) then
6289 begin
63- try
64- repeat
65- if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 ) and
66- (FindRec. Name <> ' . ' ) and (FindRec. Name <> ' .. ' ) then
67- begin
68- if DirExists(UsersFolder + ' \ ' + FindRec. Name + ' \cortex ' ) then
69- begin
70- DelTree(UsersFolder + ' \ ' + FindRec. Name + ' \cortex ' , True, True, True) ;
71- end ;
72- end ;
73- until not FindNext(FindRec);
74- finally
75- FindClose(FindRec) ;
90+ 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);
91+
92+ if ShouldDelete = idYes then
93+ begin
94+ if DirExists(UserCortexFolder) then
95+ begin
96+ DelTree(UserCortexFolder, True, True, True);
97+ end ;
98+
99+ if FileExists(UserCortexConfig) then
100+ begin
101+ DeleteFile(UserCortexConfig);
102+ end ;
76103 end ;
77104 end ;
78105end ;
@@ -81,6 +108,6 @@ procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
81108begin
82109 if CurUninstallStep = usPostUninstall then
83110 begin
84- DeleteUserCortexFolder ;
111+ DeleteCurrentUserCortexFolderAndConfig ;
85112 end ;
86113end ;
0 commit comments