Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Launcher.dpr 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. {*
  2. * This application launches the dmdirc java-based installer.
  3. *
  4. * DMDirc - Open Source IRC Client
  5. * Copyright (c) 2006-2008 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. //{$R files.res}
  30. //{$R version.res}
  31. //{$R icon.res}
  32. {$R all.res}
  33. {$I consts.inc}
  34. function GetTempDirectory(): String;
  35. var
  36. buf: array[0..MAX_PATH] of Char;
  37. wintemp, temp: String;
  38. begin
  39. GetTempPath(SizeOf(buf)-1, buf);
  40. wintemp := StrPas(buf);
  41. Randomize;
  42. temp := '\DMDirc-installer-'+inttostr(1000 + Random(1000));
  43. while (DirectoryExists(wintemp+temp+'\')) do begin
  44. temp := temp+'-'+inttostr(1+Random(1000));
  45. end;
  46. MkDir(wintemp+temp+'\');
  47. result := wintemp+temp+'\';
  48. end;
  49. procedure ExtractResource(name: string; filename: string; dir: string = '');
  50. var
  51. rStream: TResourceStream;
  52. fStream: TFileStream;
  53. fname: string;
  54. begin
  55. if (dir = '') or (not DirectoryExists(dir)) then dir := IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)));
  56. fname := dir+filename;
  57. if FileExists(fname) then DeleteFile(fname);
  58. rStream := TResourceStream.Create(hInstance, name, RT_RCDATA);
  59. try
  60. fStream := TFileStream.Create(fname, fmCreate);
  61. try
  62. fStream.CopyFrom(rStream, 0);
  63. finally
  64. fStream.Free;
  65. end;
  66. finally
  67. rStream.Free;
  68. end;
  69. end;
  70. procedure Launch(sProgramToRun: String);
  71. var
  72. StartupInfo: TStartupInfo;
  73. ProcessInfo: TProcessInformation;
  74. begin
  75. FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  76. with StartupInfo do begin
  77. cb := SizeOf(TStartupInfo);
  78. dwFlags := STARTF_USESHOWWINDOW;
  79. wShowWindow := SW_SHOWNORMAL;
  80. end;
  81. CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  82. end;
  83. function checkMD5(filename: String): boolean;
  84. var
  85. hash: String;
  86. begin
  87. hash := MD5Print(MD5File(filename));
  88. result := (hash = MD5SUM);
  89. // if not result then begin
  90. // MessageBox(0, PChar('MD5Hash Result:'+#10+'Got: '+hash+#10+'Exp: '+MD5SUM+#10+'Res:'+booltostr(hash = MD5SUM)), 'Test', MB_OK + MB_ICONSTOP);
  91. // end;
  92. // Uncomment this to disable MD5 Check
  93. // result := true;
  94. end;
  95. var
  96. ErrorMessage: String;
  97. TempDir: String;
  98. begin
  99. TempDir := GetTempDirectory;
  100. ErrorMessage := '';
  101. {$I ExtractCode.inc}
  102. end.