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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. program DMDirc;
  2. {$MODE Delphi}
  3. {$APPTYPE GUI}
  4. {$R icon.rc}
  5. {$R version.rc}
  6. uses Windows, SysUtils, classes;
  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. var
  41. errorMessage: String;
  42. javaCommand: String = 'javaw.exe';
  43. cliParams: String = '';
  44. directory: String = '';
  45. i: integer;
  46. hK32: THandle;
  47. jarName: String;
  48. begin
  49. jarName := ExtractFileDir(paramstr(0))+'\DMDirc.jar';
  50. directory := GetEnvironmentVariable('APPDATA')+'\DMDirc';
  51. if ParamCount > 0 then begin
  52. for i := 1 to ParamCount do begin
  53. cliParams := cliParams+' '+paramstr(i);
  54. if (paramstr(i) = '-d') or (paramstr(i) = '--directory') then begin
  55. if ParamCount > i then begin
  56. directory := paramstr(i+1);
  57. end;
  58. end
  59. end;
  60. end;
  61. // Update if needed.
  62. if FileExists(directory+'\.DMDirc.jar') then begin
  63. // Vista Sucks.
  64. hK32 := GetModuleHandle('kernel32');
  65. if GetProcAddress(hK32, 'GetLocaleInfoEx') <> nil then begin
  66. // Vista >.<
  67. // Try and delete the old file, if it fails then the user needs to give
  68. // us permission to delete the file (UAC), otherwise we can just go ahead
  69. // and run the updater.
  70. if not DeleteFile(pchar(jarName)) then begin
  71. errorMessage := 'An update to DMDirc has been previously downloaded.';
  72. errorMessage := errorMessage+#13#10;
  73. errorMessage := errorMessage+#13#10+'As you are running Windows Vista, DMDirc requires administer access to';
  74. errorMessage := errorMessage+#13#10+'complete the update.';
  75. errorMessage := errorMessage+#13#10;
  76. errorMessage := errorMessage+#13#10+'Please click ''Allow'' on the UAC prompt to complete the update, or click no';
  77. errorMessage := errorMessage+#13#10+'here to continue without updating.';
  78. if MessageBox(0, PChar(errorMessage), 'Windows Vista', MB_YESNO) = IDYES then begin
  79. ExecAndWait('DMDircUpdater.exe '+directory+'\.DMDirc.jar');
  80. end;
  81. end
  82. else ExecAndWait('DMDircUpdater.exe '+directory+'\.DMDirc.jar');
  83. end
  84. else ExecAndWait('DMDircUpdater.exe '+directory+'\.DMDirc.jar');
  85. end;
  86. // Check JVM
  87. if (ExecAndWait(javaCommand+' -version') <> 0) then begin
  88. errorMessage := 'No JVM is currently installed.';
  89. errorMessage := errorMessage+#13#10;
  90. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  91. errorMessage := errorMessage+#13#10+'http://jdl.sun.com/webapps/getjava/BrowserRedirect';
  92. errorMessage := errorMessage+#13#10;
  93. errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
  94. errorMessage := errorMessage+#13#10+'please feel free to contact us.';
  95. MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
  96. end
  97. // Else try and run client. (This only asks for help output to check that client
  98. // runs on this OS, otherwise later segfaults or so would cause the error to
  99. // appear
  100. else if FileExists(jarName) then begin
  101. if (ExecAndWait(javaCommand+' -jar "'+jarName+'" --help') <> 0) then begin
  102. errorMessage := 'The currently installed version of java is not compatible with DMDirc.';
  103. errorMessage := errorMessage+#13#10;
  104. errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
  105. errorMessage := errorMessage+#13#10+'http://jdl.sun.com/webapps/getjava/BrowserRedirect';
  106. errorMessage := errorMessage+#13#10;
  107. errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
  108. errorMessage := errorMessage+#13#10+'please feel free to contact us.';
  109. MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
  110. end
  111. else begin
  112. Launch(javaCommand+' -jar "'+jarName+'"'+cliParams)
  113. end;
  114. end
  115. else begin
  116. errorMessage := 'Your DMDirc installation has been broken. DMDirc.jar no longer exists.';
  117. MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
  118. end;
  119. end.