選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DMDirc.dpr 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. program DMDirc;
  2. {$MODE Delphi}
  3. {$APPTYPE GUI}
  4. {$R comctl.rc}
  5. {$R icon.rc}
  6. {$R version.rc}
  7. uses Windows, SysUtils, classes, StrUtils, Vista;
  8. function askQuestion(Question: String): boolean;
  9. begin
  10. Result := TaskDialog(0, 'DMDirc', 'Question', Question, TD_ICON_QUESTION, TD_BUTTON_YES + TD_BUTTON_NO) = mrYes;
  11. end;
  12. procedure showError(ErrorMessage: String; addFooter: boolean = true);
  13. begin
  14. if addFooter then begin
  15. ErrorMessage := ErrorMessage+#13#10;
  16. ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
  17. ErrorMessage := ErrorMessage+#13#10+'please feel free to contact us.';
  18. end;
  19. TaskDialog(0, 'DMDirc', 'There was an error starting DMDirc', ErrorMessage, TD_ICON_ERROR, TD_BUTTON_OK, false, false);
  20. end;
  21. procedure showmessage(message: String; context:String = 'Information');
  22. begin
  23. TaskDialog(0, 'DMDirc', context, message, TD_ICON_INFORMATION, TD_BUTTON_OK);
  24. end;
  25. // Run an application and wait for it to finish.
  26. function ExecAndWait(sProgramToRun: String): Longword;
  27. var
  28. StartupInfo: TStartupInfo;
  29. ProcessInfo: TProcessInformation;
  30. begin
  31. FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  32. with StartupInfo do begin
  33. cb := SizeOf(TStartupInfo);
  34. dwFlags := STARTF_USESHOWWINDOW;
  35. wShowWindow := SW_SHOWNORMAL;
  36. end;
  37. CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  38. getExitCodeProcess(ProcessInfo.hProcess, Result);
  39. while Result=STILL_ACTIVE do begin
  40. sleep(1000);
  41. GetExitCodeProcess(ProcessInfo.hProcess, Result);
  42. end;
  43. end;
  44. // Run an application and don't wait for it to finish.
  45. procedure Launch(sProgramToRun: String);
  46. var
  47. StartupInfo: TStartupInfo;
  48. ProcessInfo: TProcessInformation;
  49. begin
  50. FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  51. with StartupInfo do begin
  52. cb := SizeOf(TStartupInfo);
  53. dwFlags := STARTF_USESHOWWINDOW;
  54. wShowWindow := SW_SHOWNORMAL;
  55. end;
  56. CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  57. end;
  58. procedure RunProgram(sProgramToRun: String; wait: boolean);
  59. begin
  60. if wait then ExecAndWait(sProgramToRun)
  61. else Launch(sProgramToRun);
  62. end;
  63. const
  64. launcherVersion: String = '2';
  65. var
  66. errorMessage: String;
  67. javaCommand: String = 'javaw.exe';
  68. cliParams: String = '';
  69. directory: String = '';
  70. i: integer;
  71. jarName: String;
  72. launcherUpdate: boolean = false;
  73. begin
  74. jarName := ExtractFileDir(paramstr(0))+'\DMDirc.jar';
  75. directory := GetEnvironmentVariable('APPDATA')+'\DMDirc';
  76. if ParamCount > 0 then begin
  77. for i := 1 to ParamCount do begin
  78. if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
  79. else cliParams := cliParams+' '+paramstr(i);
  80. if (paramstr(i) = '-d') or (paramstr(i) = '--directory') then begin
  81. if ParamCount > i then begin
  82. directory := paramstr(i+1);
  83. end;
  84. end
  85. end;
  86. end;
  87. // Update if needed.
  88. launcherUpdate := FileExists(directory+'\.DMDirc.exe') and FileExists(directory+'\.DMDircUpdater.exe');
  89. if FileExists(directory+'\.DMDirc.jar') or launcherUpdate then begin
  90. // Vista Sucks.
  91. if IsWindowsVista then begin
  92. // Vista >.<
  93. // Try and delete the old file, if it fails then the user needs to give
  94. // us permission to delete the file (UAC), otherwise we can just go ahead
  95. // and run the updater.
  96. if not DeleteFile(pchar(jarName)) then begin
  97. errorMessage := 'An update to DMDirc has been previously downloaded.';
  98. errorMessage := errorMessage+#13#10;
  99. errorMessage := errorMessage+#13#10+'As you are running Windows Vista, DMDirc requires administer access to';
  100. errorMessage := errorMessage+#13#10+'complete the update.';
  101. errorMessage := errorMessage+#13#10;
  102. errorMessage := errorMessage+#13#10+'Please click ''Allow'' on the UAC prompt to complete the update, or click no';
  103. errorMessage := errorMessage+#13#10+'here to continue without updating.';
  104. if askQuestion(errorMessage) then begin
  105. RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
  106. end;
  107. end
  108. else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
  109. end
  110. else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
  111. end;
  112. if not launcherUpdate then begin
  113. // Check JVM
  114. if (ExecAndWait(javaCommand+' -version') <> 0) then begin
  115. errorMessage := 'No JVM is currently installed.';
  116. errorMessage := errorMessage+#13#10;
  117. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  118. errorMessage := errorMessage+#13#10+'http://java.com/';
  119. errorMessage := errorMessage+#13#10;
  120. errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
  121. errorMessage := errorMessage+#13#10+'please feel free to contact us.';
  122. showError(errorMessage);
  123. end
  124. // Else try and run client. (This only asks for help output to check that client
  125. // runs on this OS, otherwise later segfaults or so would cause the error to
  126. // appear
  127. else if FileExists(jarName) then begin
  128. if (ExecAndWait(javaCommand+' -jar "'+jarName+'" --help') <> 0) then begin
  129. errorMessage := 'The currently installed version of java is not compatible with DMDirc.';
  130. errorMessage := errorMessage+#13#10;
  131. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  132. errorMessage := errorMessage+#13#10+'http://java.com/';
  133. errorMessage := errorMessage+#13#10;
  134. errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
  135. errorMessage := errorMessage+#13#10+'please feel free to contact us.';
  136. showError(errorMessage);
  137. end
  138. else begin
  139. Launch(javaCommand+' -ea -jar "'+jarName+'"'+' -l windows-'+launcherVersion+' '+cliParams)
  140. end;
  141. end
  142. else begin
  143. errorMessage := 'Your DMDirc installation has been broken. DMDirc.jar no longer exists.';
  144. showError(errorMessage);
  145. end;
  146. end;
  147. end.