inno.nimf 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #? stdtmpl | standard
  2. #proc generateInnoSetup(c: ConfigData): string =
  3. # result = ""
  4. ; Default Template for NimInst
  5. [Setup]
  6. AppName=$c.displayName
  7. AppVerName=$c.displayName $c.version
  8. DefaultDirName={code:GiveMeAPath|$c.displayName}
  9. DefaultGroupName=$c.displayName
  10. AllowNoIcons=yes
  11. LicenseFile=${expandFilename(c.license)}
  12. OutputBaseFilename=${c.name}_${c.version}
  13. Compression=lzma
  14. SolidCompression=yes
  15. PrivilegesRequired=none
  16. ChangesEnvironment=yes
  17. [Languages]
  18. Name: english; MessagesFile: compiler:Default.isl
  19. [Files]
  20. #for i in low(FileCategory)..fcWindows:
  21. # for f in items(c.cat[i]):
  22. Source: ${expandFilename(f).toWin}; DestDir: {app}\${splitFile(f).dir.toWin}; Flags: ignoreversion
  23. # end for
  24. #end for
  25. [Icons]
  26. #if c.app == appConsole:
  27. Name: {group}\Console for $c.displayName; Filename: {cmd}
  28. #else:
  29. Name: {group}\$c.displayName; Filename: {app}\${c.name}.exe
  30. #end if
  31. #for f in items(c.cat[fcDocStart]):
  32. Name: {group}\Documentation; Filename: {app}\${f.toWin}
  33. #end for
  34. Name: {group}\{cm:UninstallProgram,$c.displayName}; Filename: {uninstallexe}
  35. #if c.binPaths.len > 0:
  36. [Tasks]
  37. Name: modifypath; Description: &Add $c.displayName to your system path (if not in path already);
  38. #end if
  39. [Code]
  40. function GiveMeAPath(const DefaultPathName: string): string;
  41. begin
  42. if IsAdminLoggedOn then result := ExpandConstant('{pf}')
  43. else result := ExpandConstant('{userdocs}');
  44. result := result + '\' + DefaultPathName;
  45. end;
  46. #if c.binPaths.len > 0:
  47. // ----------------------------------------------------------------------------
  48. //
  49. // Inno Setup Ver: 5.2.1
  50. // Script Version: 1.3.1
  51. // Author: Jared Breland <jbreland@legroom.net>
  52. // Homepage: http://www.legroom.net/software
  53. //
  54. // Script Function:
  55. // Enable modification of system path directly from Inno Setup installers
  56. function ModPathDir(): TArrayOfString;
  57. begin
  58. setArrayLength(result, $c.binPaths.len);
  59. #var i = 0
  60. #for b in items(c.binPaths):
  61. result[$i] := ExpandConstant('{app}') + '\${b.toWin}';
  62. #inc(i)
  63. #end for
  64. end;
  65. procedure ModPath();
  66. var
  67. oldpath, newpath, aExecFile: String;
  68. pathArr, aExecArr, pathdir: TArrayOfString;
  69. i, d: Integer;
  70. begin
  71. // Get array of new directories and act on each individually
  72. pathdir := ModPathDir();
  73. for d := 0 to GetArrayLength(pathdir)-1 do begin
  74. // Modify WinNT path
  75. if UsingWinNT() then begin
  76. // Get current path, split into an array
  77. RegQueryStringValue(HKEY_LOCAL_MACHINE,
  78. 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
  79. 'Path', oldpath);
  80. oldpath := oldpath + ';';
  81. i := 0;
  82. while (Pos(';', oldpath) > 0) do begin
  83. SetArrayLength(pathArr, i+1);
  84. pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);
  85. oldpath := Copy(oldpath, Pos(';', oldpath)+1, Length(oldpath));
  86. i := i + 1;
  87. // Check if current directory matches app dir
  88. if pathdir[d] = pathArr[i-1] then begin
  89. // if uninstalling, remove dir from path
  90. if IsUninstaller() then continue
  91. // if installing, abort because dir was already in path
  92. else abort;
  93. end;
  94. // Add current directory to new path
  95. if i = 1 then newpath := pathArr[i-1]
  96. else newpath := newpath + ';' + pathArr[i-1];
  97. end;
  98. // Append app dir to path if not already included
  99. if not IsUninstaller() then
  100. newpath := newpath + ';' + pathdir[d];
  101. // Write new path
  102. RegWriteStringValue(HKEY_LOCAL_MACHINE,
  103. 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
  104. 'Path', newpath);
  105. end
  106. else begin
  107. // Modify Win9x path
  108. // Convert to shortened dirname
  109. pathdir[d] := GetShortName(pathdir[d]);
  110. // If autoexec.bat exists, check if app dir already exists in path
  111. aExecFile := 'C:\AUTOEXEC.BAT';
  112. if FileExists(aExecFile) then begin
  113. LoadStringsFromFile(aExecFile, aExecArr);
  114. for i := 0 to GetArrayLength(aExecArr)-1 do begin
  115. if not IsUninstaller() then begin
  116. // If app dir already exists while installing, abort add
  117. if (Pos(pathdir[d], aExecArr[i]) > 0) then
  118. abort;
  119. end
  120. else begin
  121. // If app dir exists and = what we originally set,
  122. // then delete at uninstall
  123. if aExecArr[i] = 'SET PATH=%PATH%;' + pathdir[d] then
  124. aExecArr[i] := '';
  125. end;
  126. end;
  127. end;
  128. // If app dir not found, or autoexec.bat didn't exist, then
  129. // (create and) append to current path
  130. if not IsUninstaller() then begin
  131. SaveStringToFile(aExecFile, #13#10 + 'SET PATH=%PATH%;' + pathdir[d],
  132. True);
  133. end
  134. else begin
  135. // If uninstalling, write the full autoexec out
  136. SaveStringsToFile(aExecFile, aExecArr, False);
  137. end;
  138. end;
  139. // Write file to flag modifypath was selected
  140. // Workaround since IsTaskSelected() cannot be called at uninstall and
  141. // AppName and AppId cannot be "read" in Code section
  142. if not IsUninstaller() then
  143. SaveStringToFile(ExpandConstant('{app}') + '\uninsTasks.txt',
  144. WizardSelectedTasks(False), False);
  145. end;
  146. end;
  147. procedure CurStepChanged(CurStep: TSetupStep);
  148. begin
  149. if CurStep = ssPostInstall then begin
  150. if IsTaskSelected('modifypath') then
  151. ModPath();
  152. end
  153. end;
  154. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  155. var
  156. appdir, selectedTasks: String;
  157. begin
  158. appdir := ExpandConstant('{app}');
  159. if CurUninstallStep = usUninstall then begin
  160. if LoadStringFromFile(appdir + '\uninsTasks.txt', selectedTasks) then
  161. if Pos('modifypath', selectedTasks) > 0 then
  162. ModPath();
  163. DeleteFile(appdir + '\uninsTasks.txt')
  164. end;
  165. end;
  166. function NeedRestart(): Boolean;
  167. begin
  168. result := IsTaskSelected('modifypath') and not UsingWinNT()
  169. end;
  170. #end if