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.

Launcher.dpr 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. program Launcher;
  2. {$MODE Delphi}
  3. {$APPTYPE GUI}
  4. uses Windows, SysUtils, classes, MD5;
  5. //{$R files.res}
  6. //{$R version.res}
  7. //{$R icon.res}
  8. {$R all.res}
  9. {$I consts.inc}
  10. function GetTempDirectory(): String;
  11. var
  12. buf: array[0..MAX_PATH] of Char;
  13. wintemp, temp: String;
  14. begin
  15. GetTempPath(SizeOf(buf)-1, buf);
  16. wintemp := StrPas(buf);
  17. Randomize;
  18. temp := '\DMDirc-installer-'+inttostr(1000 + Random(1000));
  19. while (DirectoryExists(wintemp+temp+'\')) do begin
  20. temp := temp+'-'+inttostr(1+Random(1000));
  21. end;
  22. MkDir(wintemp+temp+'\');
  23. result := wintemp+temp+'\';
  24. end;
  25. procedure ExtractResource(name: string; filename: string; dir: string = '');
  26. var
  27. rStream: TResourceStream;
  28. fStream: TFileStream;
  29. fname: string;
  30. begin
  31. if (dir = '') or (not DirectoryExists(dir)) then dir := IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)));
  32. fname := dir+filename;
  33. if FileExists(fname) then DeleteFile(fname);
  34. rStream := TResourceStream.Create(hInstance, name, RT_RCDATA);
  35. try
  36. fStream := TFileStream.Create(fname, fmCreate);
  37. try
  38. fStream.CopyFrom(rStream, 0);
  39. finally
  40. fStream.Free;
  41. end;
  42. finally
  43. rStream.Free;
  44. end;
  45. end;
  46. procedure Launch(sProgramToRun: String);
  47. var
  48. StartupInfo: TStartupInfo;
  49. ProcessInfo: TProcessInformation;
  50. begin
  51. FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  52. with StartupInfo do begin
  53. cb := SizeOf(TStartupInfo);
  54. dwFlags := STARTF_USESHOWWINDOW;
  55. wShowWindow := SW_SHOWNORMAL;
  56. end;
  57. CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  58. end;
  59. function checkMD5(filename: String): boolean;
  60. var
  61. hash: String;
  62. begin
  63. hash := MD5Print(MD5File(filename));
  64. result := (hash = MD5SUM);
  65. // if not result then begin
  66. // MessageBox(0, PChar('MD5Hash Result:'+#10+'Got: '+hash+#10+'Exp: '+MD5SUM+#10+'Res:'+booltostr(hash = MD5SUM)), 'Test', MB_OK + MB_ICONSTOP);
  67. // end;
  68. // Uncomment this to disable MD5 Check
  69. // result := true;
  70. end;
  71. var
  72. ErrorMessage: String;
  73. TempDir: String;
  74. begin
  75. TempDir := GetTempDirectory;
  76. ErrorMessage := '';
  77. {$I ExtractCode.inc}
  78. end.