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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. {*
  2. * This application launches the dmdirc java-based installer.
  3. *
  4. * DMDirc - Open Source IRC Client
  5. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. *}
  25. program Launcher;
  26. {$MODE Delphi}
  27. {$APPTYPE GUI}
  28. uses Windows, SysUtils, classes, MD5;
  29. procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
  30. //{$R files.res}
  31. //{$R version.res}
  32. //{$R icon.res}
  33. {$R all.res}
  34. {$I consts.inc}
  35. function GetTempDirectory(): String;
  36. var
  37. buf: array[0..MAX_PATH] of Char;
  38. wintemp, temp: String;
  39. begin
  40. GetTempPath(SizeOf(buf)-1, buf);
  41. wintemp := StrPas(buf);
  42. Randomize;
  43. temp := '\DMDirc-installer-'+inttostr(1000 + Random(1000));
  44. while (DirectoryExists(wintemp+temp+'\')) do begin
  45. temp := temp+'-'+inttostr(1+Random(1000));
  46. end;
  47. MkDir(wintemp+temp+'\');
  48. result := wintemp+temp+'\';
  49. end;
  50. procedure ExtractResource(name: string; filename: string; dir: string = '');
  51. var
  52. rStream: TResourceStream;
  53. fStream: TFileStream;
  54. fname: string;
  55. begin
  56. if (dir = '') or (not DirectoryExists(dir)) then dir := IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)));
  57. fname := dir+filename;
  58. if FileExists(fname) then DeleteFile(fname);
  59. rStream := TResourceStream.Create(hInstance, name, RT_RCDATA);
  60. try
  61. fStream := TFileStream.Create(fname, fmCreate);
  62. try
  63. fStream.CopyFrom(rStream, 0);
  64. finally
  65. fStream.Free;
  66. end;
  67. finally
  68. rStream.Free;
  69. end;
  70. end;
  71. procedure Launch(sProgramToRun: String);
  72. var
  73. StartupInfo: TStartupInfo;
  74. ProcessInfo: TProcessInformation;
  75. begin
  76. FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  77. with StartupInfo do begin
  78. cb := SizeOf(TStartupInfo);
  79. dwFlags := STARTF_USESHOWWINDOW;
  80. wShowWindow := SW_SHOWNORMAL;
  81. end;
  82. CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  83. end;
  84. function checkMD5(filename: String): boolean;
  85. var
  86. hash: String;
  87. begin
  88. hash := MD5Print(MD5File(filename));
  89. result := (hash = MD5SUM);
  90. // if not result then begin
  91. // MessageBox(0, PChar('MD5Hash Result:'+#10+'Got: '+hash+#10+'Exp: '+MD5SUM+#10+'Res:'+booltostr(hash = MD5SUM)), 'Test', MB_OK + MB_ICONSTOP);
  92. // end;
  93. // Uncomment this to disable MD5 Check
  94. // result := true;
  95. end;
  96. var
  97. ErrorMessage: String;
  98. TempDir: String;
  99. begin
  100. InitCommonControls;
  101. TempDir := GetTempDirectory;
  102. ErrorMessage := '';
  103. {$I ExtractCode.inc}
  104. end.