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.

DMDircUpdater.dpr 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {*
  2. * Updates DMDirc windows components
  3. *
  4. * DMDirc - Open Source IRC Client
  5. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes,
  6. * Michael Nixon
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. *}
  26. program DMDircUpdater;
  27. {$MODE Delphi}
  28. {$APPTYPE GUI}
  29. {$R UAC.rc}
  30. uses Vista, shared, Windows, SysUtils, classes, StrUtils;
  31. procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
  32. { ---------------------------------------------------------------------------- }
  33. { ----------------------------------------------------------------------------
  34. MAIN PROGRAM
  35. ---------------------------------------------------------------------------- }
  36. var
  37. sourceDir: String = '';
  38. thisDir: String;
  39. cliParams: String = '';
  40. i: integer;
  41. jarName: String;
  42. launcherUpdate: boolean = false;
  43. myName: String;
  44. canDoMore: boolean = true;
  45. begin
  46. InitCommonControls;
  47. myName := ExtractFileName(paramstr(0));
  48. thisDir := ExtractFileDir(paramstr(0));
  49. jarName := thisDir+'\DMDirc.jar';
  50. if ParamCount > 0 then begin
  51. for i := 1 to ParamCount do begin
  52. if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
  53. else cliParams := cliParams+' '+paramstr(i);
  54. if (paramstr(i) = '--UpdateSourceDir') then begin // Source Directory
  55. if ParamCount > i then begin
  56. sourceDir := paramstr(i+1);
  57. end;
  58. end
  59. end;
  60. // Look for a launcher update.
  61. if FileExists(pchar(sourceDir+'\.DMDirc.exe')) and FileExists(pchar(sourceDir+'\.DMDircUpdater.exe')) then begin
  62. if myName = 'DMDircUpdater.exe' then begin
  63. // Windows won't let us overwrite ourself, so we need to copy ourself
  64. // to another name, and run the new us.
  65. if CopyFile(pchar(thisDir+'\DMDircUpdater.exe'), pchar(thisDir+'\DMDircLauncherUpdater.exe'), False) then begin
  66. canDoMore := false;
  67. Launch('"'+thisDir+'\DMDircLauncherUpdater.exe" '+cliParams);
  68. end
  69. else begin
  70. showmessage('Unable to overwrite launcher', 'DMDirc', 'Update Failed');
  71. end;
  72. end
  73. else begin
  74. launcherUpdate := true;
  75. if FileExists(pchar(thisDir+'\DMDirc.exe')) then begin
  76. if not DeleteFile(pchar(thisDir+'\DMDirc.exe')) then begin
  77. showmessage('Unable to delete DMDirc.exe', 'DMDirc', 'Launcher Update Failed');
  78. end;
  79. end;
  80. if not FileExists(pchar(thisDir+'\DMDirc.exe')) and MoveFile(pchar(sourceDir+'\.DMDirc.exe'), pchar(thisDir+'\DMDirc.exe')) then begin
  81. if FileExists(pchar(thisDir+'\DMDircUpdater.exe')) then begin
  82. if not DeleteFile(pchar(thisDir+'\DMDircUpdater.exe')) then begin
  83. showmessage('Unable to delete DMDircUpdater.exe', 'DMDirc', 'Launcher Update Failed');
  84. end;
  85. end;
  86. if not FileExists(pchar(thisDir+'\DMDircUpdater.exe')) and MoveFile(pchar(sourceDir+'\.DMDircUpdater.exe'), pchar(thisDir+'\DMDircUpdater.exe')) then begin
  87. showmessage('Launcher update was successful', 'DMDirc');
  88. end
  89. else begin
  90. showmessage('Unable to update DMDircUpdater.exe', 'DMDirc', 'Launcher Update Failed');
  91. end;
  92. end
  93. else begin
  94. showmessage('Unable to update DMDirc.exe', 'DMDirc', 'Launcher Update Failed');
  95. end;
  96. end;
  97. end;
  98. // Look for client update
  99. if canDoMore then begin
  100. if FileExists(pchar(sourceDir+'\.DMDirc.jar')) then begin
  101. if FileExists(pchar(jarName)) then begin
  102. if not DeleteFile(pchar(jarName)) then begin
  103. showmessage('Unable to update DMDirc.jar', 'DMDirc', 'Launcher Update Failed');
  104. end;
  105. end;
  106. if MoveFile(pchar(sourceDir+'\.DMDirc.jar'), pchar(jarName)) then begin
  107. showmessage('Client update was successful', 'DMDirc');
  108. end
  109. else begin
  110. showmessage('Unable to move '''+sourceDir+'\.DMDirc.jar'' to '+jarName, 'DMDirc', 'Update Failed');
  111. end;
  112. end;
  113. if launcherUpdate then begin
  114. showmessage('The DMDirc launcher has been updated, to complete the update please relaunch DMDirc.', 'DMDirc', 'Restart Required');
  115. end;
  116. end;
  117. end
  118. else begin
  119. showError('This program can not be run on its own.', 'DMDirc');
  120. end;
  121. end.