You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Setup.dpr 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. {*
  2. * This application launches the dmdirc java-based installer.
  3. *
  4. * DMDirc - Open Source IRC Client
  5. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. *}
  25. program Setup;
  26. {$MODE Delphi}
  27. // Use this instead of {$APPTYPE XXX}
  28. // APP_XXX is the same as {$APPTYPE XXX}
  29. // Defaults to console
  30. // This is a work-around for a bug in FPC Cross Compiling to windows in delphi
  31. // mode (IsConsole is always true)
  32. {$DEFINE APP_GUI}
  33. // This block actually does the work for the above work-around
  34. {$IFDEF APP_GUI}
  35. {$APPTYPE GUI}
  36. {$ELSE}
  37. {$IFDEF APP_FS}
  38. {$APPTYPE FS}
  39. {$ELSE}
  40. {$IFDEF APP_TOOL}
  41. {$DEFINE APP_CONSOLE}
  42. {$APPTYPE TOOL}
  43. {$ELSE}
  44. {$DEFINE APP_CONSOLE}
  45. {$APPTYPE CONSOLE}
  46. {$ENDIF}
  47. {$ENDIF}
  48. {$ENDIF}
  49. uses Windows, SysUtils, classes, registry;
  50. // This is also part of the above work-around.
  51. {$IFDEF APP_CONSOLE}
  52. const
  53. IsConsole: boolean = true;
  54. {$ELSE}
  55. const
  56. IsConsole: boolean = false;
  57. {$ENDIF}
  58. // Run an application and wait for it to finish.
  59. function ExecAndWait(sProgramToRun: String): Longword;
  60. var
  61. StartupInfo: TStartupInfo;
  62. ProcessInfo: TProcessInformation;
  63. begin
  64. FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  65. with StartupInfo do begin
  66. cb := SizeOf(TStartupInfo);
  67. dwFlags := STARTF_USESHOWWINDOW;
  68. wShowWindow := SW_SHOWNORMAL;
  69. end;
  70. CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  71. getExitCodeProcess(ProcessInfo.hProcess, Result);
  72. while Result=STILL_ACTIVE do begin
  73. sleep(1000);
  74. GetExitCodeProcess(ProcessInfo.hProcess, Result);
  75. end;
  76. end;
  77. procedure dowriteln(line: String);
  78. begin
  79. if IsConsole then writeln(line);
  80. end;
  81. procedure dowrite(line: String);
  82. begin
  83. if IsConsole then write(line);
  84. end;
  85. procedure showError(ErrorMessage: String);
  86. begin
  87. if IsConsole then begin
  88. writeln('');
  89. writeln('-----------------------------------------------------------------------');
  90. writeln('Sorry, setup is unable to continue.!');
  91. writeln('-----------------------------------------------------------------------');
  92. writeln('Reason:');
  93. writeln('----------');
  94. writeln(ErrorMessage);
  95. writeln('-----------------------------------------------------------------------');
  96. writeln('If you feel this is incorrect, or you require some further assistance,');
  97. writeln('please feel free to contact us.');
  98. writeln('-----------------------------------------------------------------------');
  99. readln();
  100. end
  101. else begin
  102. ErrorMessage := ErrorMessage+#13#10;
  103. ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
  104. ErrorMessage := ErrorMessage+#13#10+'please feel free to contact us.';
  105. MessageBox(0, PChar(ErrorMessage), 'Sorry, setup is unable to continue', MB_OK + MB_ICONSTOP);
  106. end;
  107. end;
  108. var
  109. errorMessage: String;
  110. javaCommand: String = 'javaw.exe';
  111. params: String = '';
  112. dir: String = '';
  113. Reg: TRegistry;
  114. begin
  115. // Nice and simple
  116. if IsConsole then begin
  117. writeln('-----------------------------------------------------------------------');
  118. writeln('Welcome to the DMDirc installer.');
  119. writeln('-----------------------------------------------------------------------');
  120. writeln('This will install DMDirc on your computer.');
  121. writeln('');
  122. writeln('Please wait whilst the GUI part of the installer loads...');
  123. writeln('-----------------------------------------------------------------------');
  124. // end
  125. // else begin
  126. // errorMessage := 'This will install DMDirc on your computer, please click OK to continue, or Cancel to abort.';
  127. // if (MessageBox(0, PChar(errorMessage), 'DMDirc Installer', MB_OKCANCEL + MB_ICONINFORMATION) <> IDOK) then begin
  128. // exit;
  129. // end;
  130. end;
  131. errorMessage := '';
  132. dowrite('Checking for installer.jar.. ');
  133. if FileExists('installer.jar') then begin
  134. dowriteln('Success!');
  135. dowrite('Checking for JVM.. ');
  136. if (ExecAndWait(javaCommand+' -version') <> 0) then begin
  137. dowriteln('Failed!');
  138. errorMessage := errorMessage+'No JVM is currently installed.';
  139. errorMessage := errorMessage+#13#10;
  140. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  141. errorMessage := errorMessage+#13#10+'http://jdl.sun.com/webapps/getjava/BrowserRedirect';
  142. end
  143. else begin
  144. if IsConsole then begin
  145. writeln('Success!');
  146. write('Starting installer.jar.. ');
  147. javaCommand := 'java.exe';
  148. end;
  149. Reg := TRegistry.Create;
  150. Reg.RootKey := HKEY_LOCAL_MACHINE;
  151. if Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc', false) then begin
  152. dir := Reg.ReadString('InstallDir');
  153. if (dir <> '') then begin
  154. params := params+' --directory "'+dir+'"';
  155. end;
  156. end;
  157. Reg.CloseKey;
  158. Reg.Free;
  159. if (ExecAndWait(javaCommand+' -jar installer.jar'+params) <> 0) then begin
  160. dowriteln('Failed!');
  161. errorMessage := errorMessage+'The currently installed version of java is not compatible with DMDirc.';
  162. errorMessage := errorMessage+#13#10;
  163. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  164. errorMessage := errorMessage+#13#10+'http://jdl.sun.com/webapps/getjava/BrowserRedirect';
  165. showError(errorMessage);
  166. end;
  167. end;
  168. end
  169. else begin
  170. dowriteln('Failed!');
  171. errorMessage := errorMessage+'installer.jar was not found.';
  172. errorMessage := errorMessage+#13#10;
  173. errorMessage := errorMessage+#13#10+'This is likely because of a corrupt installer build.';
  174. errorMessage := errorMessage+#13#10+'Please check http://www.dmdirc.com/ for an updated build.';
  175. showError(errorMessage);
  176. end;
  177. if IsConsole then begin
  178. writeln('');
  179. writeln('-----------------------------------------------------------------------');
  180. writeln('Installation Completed. Thank you for choosing DMDirc');
  181. writeln('-----------------------------------------------------------------------');
  182. end;
  183. end.