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.

DMDirc.dpr 5.6KB

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