Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DMDirc.dpr 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. {*
  2. * This application launches DMDirc on windows and passes control to the
  3. * update engine as necessary.
  4. *
  5. * DMDirc - Open Source IRC Client
  6. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes,
  7. * Michael Nixon
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *}
  27. program DMDirc;
  28. {$MODE Delphi}
  29. {$APPTYPE GUI}
  30. {$R comctl.rc}
  31. {$R icon.rc}
  32. {$R version.rc}
  33. uses Vista, shared, Windows, SysUtils, classes, StrUtils;
  34. procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
  35. { ---------------------------------------------------------------------------- }
  36. { ----------------------------------------------------------------------------
  37. MAIN PROGRAM
  38. ---------------------------------------------------------------------------- }
  39. const
  40. launcherVersion: String = '4';
  41. var
  42. errorMessage: String;
  43. cliParams: String = '';
  44. directory: String = '';
  45. i: integer;
  46. jarName: String;
  47. launcherUpdate: boolean = false;
  48. result: integer;
  49. s: string;
  50. handle: thandle;
  51. begin
  52. InitCommonControls;
  53. { Check for a mutex created by the DMDirc update process. Wait until it no
  54. longer exists before we continue. This prevents us from proceeding if any
  55. previous instance of the launcher is shutting down. }
  56. handle := OpenMutex(SYNCHRONIZE, False, 'DMDirc_Launcher_Restart_Wait');
  57. if handle <> 0 then begin
  58. { The mutex exists. Wait for it for up to 5 seconds. }
  59. if WaitForSingleObject(handle, 5000) = WAIT_TIMEOUT then begin
  60. { Timed out - we cannot continue, there is some kind of serious issue? }
  61. showError('Internal error: Timed out waiting for previous instance of launcher to stop during restart upgrade', 'DMDirc', true, true);
  62. exit;
  63. end;
  64. { If we get to here, the mutex has been released and we can continue }
  65. CloseHandle(handle);
  66. end;
  67. jarName := ExtractFileDir(paramstr(0))+'\DMDirc.jar';
  68. directory := GetEnvironmentVariable('APPDATA')+'\DMDirc';
  69. if ParamCount > 0 then begin
  70. for i := 1 to ParamCount do begin
  71. if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
  72. else cliParams := cliParams+' '+paramstr(i);
  73. if (paramstr(i) = '-d') or (paramstr(i) = '--directory') then begin
  74. if ParamCount > i then begin
  75. directory := paramstr(i+1);
  76. end;
  77. end
  78. end;
  79. end;
  80. // Update if needed.
  81. launcherUpdate := FileExists(directory+'\.DMDirc.exe') and FileExists(directory+'\.DMDircUpdater.exe');
  82. if FileExists(directory+'\.DMDirc.jar') or launcherUpdate then begin
  83. // Vista Sucks.
  84. if IsWindowsVista then begin
  85. // Vista >.<
  86. // Try and delete the old file, if it fails then the user needs to give
  87. // us permission to delete the file (UAC), otherwise we can just go ahead
  88. // and run the updater.
  89. if not DeleteFile(pchar(jarName)) then begin
  90. errorMessage := 'An update to DMDirc has been previously downloaded. ';
  91. errorMessage := errorMessage+#13#10;
  92. errorMessage := errorMessage+#13#10+'As you are running Windows Vista, DMDirc requires administrator access to ';
  93. errorMessage := errorMessage+#13#10+'complete the update. ';
  94. errorMessage := errorMessage+#13#10;
  95. errorMessage := errorMessage+#13#10+'Please click ''Allow'' on the UAC prompt to complete the update, or click no ';
  96. errorMessage := errorMessage+#13#10+'here to continue without updating. ';
  97. if askQuestion(errorMessage, 'DMDirc') then begin
  98. RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
  99. end;
  100. end
  101. else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
  102. end
  103. else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
  104. end;
  105. if not launcherUpdate then begin
  106. // Check JVM
  107. if (RunJava('-version') <> 0) then begin
  108. errorMessage := 'No JVM is currently installed.';
  109. errorMessage := errorMessage+#13#10;
  110. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  111. errorMessage := errorMessage+#13#10+'http://java.com/';
  112. showError(errorMessage, 'DMDirc', true);
  113. end
  114. // Else try and run client. (This only asks for help output to check that client
  115. // runs on this OS, otherwise later segfaults or so would cause the error to
  116. // appear
  117. else if FileExists(jarName) then begin
  118. if (RunJava('-jar "'+jarName+'" --help') <> 0) then begin
  119. errorMessage := 'The currently installed version of java is not compatible with DMDirc.';
  120. errorMessage := errorMessage+#13#10;
  121. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  122. errorMessage := errorMessage+#13#10+'http://java.com/';
  123. showError(errorMessage, 'DMDirc', True);
  124. end
  125. else begin
  126. { Need to wait so we can deal with exit code 42 to restart }
  127. result := RunJava('-ea -jar "'+jarName+'"'+' -l windows-'+launcherVersion+' '+cliParams);
  128. if result = 42 then begin
  129. { Need to restart DMDirc launcher
  130. We can't just rerun the EXE because it is possible for the new
  131. process to launch the updater and try to replace this EXE before
  132. the current thread ends - remote but possible. We deal with this
  133. case by creating a mutex that this program will spin on when it
  134. restarts until this instance ends. }
  135. handle := CreateMutex(nil, True, 'DMDirc_Launcher_Restart_Wait');
  136. if handle = 0 then begin
  137. showError('Internal error: Failed to create restart mutex', 'DMDirc', true, true);
  138. exit;
  139. end;
  140. { Build new command line }
  141. s := '';
  142. for i := 1 to paramcount do begin
  143. if pos(' ', paramstr(i)) <> 0 then s := s + '"' + paramstr(i) + '"' else
  144. s := s + paramstr(i);
  145. if i < paramcount then s := s + ' ';
  146. end;
  147. { Launch self }
  148. Launch('"' + paramstr(0)+ '" ' + s);
  149. end;
  150. end;
  151. end
  152. else begin
  153. errorMessage := 'A file required to start DMDirc is missing. Please re-install DMDirc to rectify the problem.';
  154. errorMessage := errorMessage+#13#10;
  155. errorMessage := errorMessage+#13#10 + 'File: DMDirc.jar';
  156. showError(errorMessage, 'DMDirc');
  157. end;
  158. end;
  159. end.