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 4.8KB

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