Информация Бекап\Восстановление папок\файлов в Inno Setup

Одноногий

Новичок
Привет.
Я не программист (да,совсем)....)!
Ищу коды вставляю в скрипты и т.д.... Никак не могу найти код,чтоб при установке делался бекап всей папки (не только заменяемых файлов),затем эта папка удалялась и на её место водружалась одноимённая папка из инсталлятора! На раб. столе нужен ярлык деинсталлятора. При деинст.,соответвенно,обратные действия - удаление новой папки и восстановление старой. Папка с именем bin. Подскажете?
 
Последнее редактирование:
Привет.
Я не программист (да,совсем)....)!
Ищу коды вставляю в скрипты и т.д.... Никак не могу найти код,чтоб при установке делался бекап всей папки (не только заменяемых файлов),затем эта папка удалялась и на её место водружалась одноимённая папка из инсталлятора! На раб. столе нужен ярлык деинсталлятора. При деинст.,соответвенно,обратные действия - удаление новой папки и восстановление старой. Папка с именем bin. Подскажете?
Самый простой способ
code_language.pascal:
#define BinDirName "bin"

[Setup]
AppName=Game1
AppVersion=1.0
DefaultDirName={sd}\Game1
OutputDir=.
DirExistsWarning=no
DisableProgramGroupPage=yes

[Files]
Source: "bin\*"; DestDir: "{app}\bin"; Flags: createallsubdirs recursesubdirs ignoreversion

[Icons]
Name: "{userdesktop}\Удалить папку bin"; Filename: "{uninstallexe}";

[code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if ( DirExists(ExpandConstant('{app}\{#BinDirName}')) and not DirExists(ExpandConstant('{app}\{#BinDirName}-Backup')) ) then
        RenameFile(ExpandConstant('{app}\{#BinDirName}'), ExpandConstant('{app}\{#BinDirName}-Backup'));
    end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\{#BinDirName}'), true, true, true);
    RenameFile(ExpandConstant('{app}\{#BinDirName}-Backup'), ExpandConstant('{app}\{#BinDirName}'));
  end;
end;
 
#define BinDirName "bin" [Setup] AppName=Game1 AppVersion=1.0 DefaultDirName={sd}\Game1 OutputDir=. DirExistsWarning=no DisableProgramGroupPage=yes [Files] Source: "bin\*"; DestDir: "{app}\bin"; Flags: createallsubdirs recursesubdirs ignoreversion [Icons] Name: "{userdesktop}\Удалить папку bin"; Filename: "{uninstallexe}";
Код:
 procedure CurStepChanged(CurStep: TSetupStep); begin if CurStep = ssInstall then begin if ( DirExists(ExpandConstant('{app}\{#BinDirName}')) and not DirExists(ExpandConstant('{app}\{#BinDirName}-Backup')) ) then RenameFile(ExpandConstant('{app}\{#BinDirName}'), ExpandConstant('{app}\{#BinDirName}-Backup')); end; end; procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if CurUninstallStep = usDone then begin DelTree(ExpandConstant('{app}\{#BinDirName}'), true, true, true); RenameFile(ExpandConstant('{app}\{#BinDirName}-Backup'), ExpandConstant('{app}\{#BinDirName}')); end; end;
Спасибо. Наконец-то работает!
Я так долго искал решение на папку bin,что забыл,то что при установке вместе с папкой bin устанавливается ещё (другая) папка и файл.
Можно сделать так,чтоб делался бекап всего,что устанавливается из Sourse и помещалось это всё в папку: _Backup ?
 
"всего" это сколько? Если еще одна папка и один файл, то вручную пропишите их в коде.
Да,одна папка и один файл. Нужно чтоб,папка bin полностью копировалась (что Вы и написали),а остальное бекапилось только то,что заменяется инсталлятором.
Ещё бы знать,что прописывать и где?) Я,вообще,не знаю программирование.
 
Всё что смог,в справке осилил. Да,там есть подпапки и файлы.
Пробуйте
code_language.pascal:
[Setup]
AppName=Game1
AppVersion=1.0
DefaultDirName={sd}\Game1
OutputDir=.
DirExistsWarning=no
DisableProgramGroupPage=yes

[Files]
Source: "bin\*"; DestDir: "{app}\bin"; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "Folder2\*"; DestDir: "{app}\Folder2"; BeforeInstall: MakeBackup; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "File1.exe"; DestDir: "{app}"; BeforeInstall: MakeBackup; Flags: ignoreversion

[Icons]
Name: "{userdesktop}\Удалить обновление"; Filename: "{uninstallexe}";

[code]
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\Backup\bin'));
    end;
end;

procedure CopyDir(const FromDir, ToDir:string);
var
  res : integer;
begin
  Exec('cmd.exe', ' /C XCOPY ' + AddQuotes(FromDir) + ' ' + AddQuotes(ToDir) + ' ' + '/E /I', ExpandConstant('{sys}'), SW_Hide,ewWaitUntilTerminated,res);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\bin'), true, true, true);
    CopyDir(ExpandConstant('{app}\Backup'), ExpandConstant('{app}'));
    DelTree(ExpandConstant('{app}\Backup'), true, true, true);
  end;
end;
 
Пробуйте
code_language.pascal:
[Setup]
AppName=Game1
AppVersion=1.0
DefaultDirName={sd}\Game1
OutputDir=.
DirExistsWarning=no
DisableProgramGroupPage=yes

[Files]
Source: "bin\*"; DestDir: "{app}\bin"; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "Folder2\*"; DestDir: "{app}\Folder2"; BeforeInstall: MakeBackup; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "File1.exe"; DestDir: "{app}"; BeforeInstall: MakeBackup; Flags: ignoreversion

[Icons]
Name: "{userdesktop}\Удалить обновление"; Filename: "{uninstallexe}";

[code]
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\Backup\bin'));
    end;
end;

procedure CopyDir(const FromDir, ToDir:string);
var
  res : integer;
begin
  Exec('cmd.exe', ' /C XCOPY ' + AddQuotes(FromDir) + ' ' + AddQuotes(ToDir) + ' ' + '/E /I', ExpandConstant('{sys}'), SW_Hide,ewWaitUntilTerminated,res);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\bin'), true, true, true);
    CopyDir(ExpandConstant('{app}\Backup'), ExpandConstant('{app}'));
    DelTree(ExpandConstant('{app}\Backup'), true, true, true);
  end;
end;
 

Вложения

  • Безымянный.jpg
    Безымянный.jpg
    4.7 KB · Просмотры: 7
@Одноногий, на форуме много раз цитировали @Shegorat. Он писал как сделать бекап по маске или по расширению или файлы отдельно. Забей в поисковик форума))
 
@Одноногий, на форуме много раз цитировали @Shegorat. Он писал как сделать бекап по маске или по расширению или файлы отдельно. Забей в поисковик форума))
Да я со всех форумов (и отсюда включительно) уже собрал коды! Только тут Хамик помог с папкой bin. Я,вроде,начал кое-что понимать и даже,.однажды,сам прописал end;,когда была ошибка (прям аж распёрло от гордости))..).....Но тут,вставил в скрипт очередной кусок кода,скомпилировал,установил и...поседел лет на 15 вперёд!!) Из папки bin в папку _backup переместилась одна папка из двух вложенных и,где-то,половина файлов!! Остальное осталось на месте!....Причём расширения файлов и у перемещённых и у оставшихся были одинаковые. Да и в коде,вроде,не было конкретики по расширениям........... И как тут изучишь базовое кодирование?
 
Вот этот сборник делает всё как надо до анинсталла - копирует в бекап папку bin заменяет её новой,бекапит заменяемые файлы и всё это в папку _Backup! Вот только анисталл не восстанавливает из бекапа!

Код:
[code]
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\_Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\_Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\_Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\_Backup\bin'));
    end;
end;

function InitializeSetup(): Boolean;
begin
  Result := True;
  if RegKeyExists(HKEY_LOCAL_MACHINE,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') or
     RegKeyExists(HKEY_CURRENT_USER,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') then
  begin
    MsgBox('Приложение уже установлено. Выполните деинсталляцию.', mbInformation, MB_OK);
    Result := False;
  end;
end;

procedure CreateBackup;
var
  srcFile, destFile: string;
begin
  srcFile:= ExpandConstant(CurrentFileName);
  destFile:= srcFile + '.bak';
  DeleteFile(destFile);
  RenameFile(srcFile, destFile);
end;
 
procedure RestoreBackup(backupDir: string);
var
  srcFile, destFile: string;
  FSR, DSR: TFindRec;
  FindResult: Boolean;
  APath: string;
begin
  APath := AddBackslash(backupDir);
  FindResult := FindFirst(APath + '*.bak', FSR);
  try
    while FindResult do
    begin
      if FSR.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
        begin
          srcFile:= APath + FSR.Name;
          destFile:= Copy(srcFile, 0, Length(srcFile)-4);
          DeleteFile(destFile);
          RenameFile(srcFile, destFile);
        end;
      FindResult := FindNext(FSR);
    end;
    FindResult := FindFirst(APath + '*.*', DSR);
    while FindResult do
    begin
      if ((DSR.Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) and
        not ((DSR.Name = '.') or (DSR.Name = '..')) then
{Recursion} RestoreBackup(APath + DSR.Name);
      FindResult := FindNext(DSR);
    end;
  finally
    FindClose(FSR);
    FindClose(DSR);
  end;
end;
 
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\{#BinDirName}'), true, true, true);
    RenameFile(ExpandConstant('{app}\{#BinDirName}_Backup'), ExpandConstant('{app}\{#BinDirName}'));
  end;
end;
 
Вот этот сборник делает всё как надо до анинсталла - копирует в бекап папку bin заменяет её новой,бекапит заменяемые файлы и всё это в папку _Backup! Вот только анисталл не восстанавливает из бекапа!

Код:
[code]
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\_Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\_Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\_Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\_Backup\bin'));
    end;
end;

function InitializeSetup(): Boolean;
begin
  Result := True;
  if RegKeyExists(HKEY_LOCAL_MACHINE,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') or
     RegKeyExists(HKEY_CURRENT_USER,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') then
  begin
    MsgBox('Приложение уже установлено. Выполните деинсталляцию.', mbInformation, MB_OK);
    Result := False;
  end;
end;

procedure CreateBackup;
var
  srcFile, destFile: string;
begin
  srcFile:= ExpandConstant(CurrentFileName);
  destFile:= srcFile + '.bak';
  DeleteFile(destFile);
  RenameFile(srcFile, destFile);
end;
 
procedure RestoreBackup(backupDir: string);
var
  srcFile, destFile: string;
  FSR, DSR: TFindRec;
  FindResult: Boolean;
  APath: string;
begin
  APath := AddBackslash(backupDir);
  FindResult := FindFirst(APath + '*.bak', FSR);
  try
    while FindResult do
    begin
      if FSR.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
        begin
          srcFile:= APath + FSR.Name;
          destFile:= Copy(srcFile, 0, Length(srcFile)-4);
          DeleteFile(destFile);
          RenameFile(srcFile, destFile);
        end;
      FindResult := FindNext(FSR);
    end;
    FindResult := FindFirst(APath + '*.*', DSR);
    while FindResult do
    begin
      if ((DSR.Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) and
        not ((DSR.Name = '.') or (DSR.Name = '..')) then
{Recursion} RestoreBackup(APath + DSR.Name);
      FindResult := FindNext(DSR);
    end;
  finally
    FindClose(FSR);
    FindClose(DSR);
  end;
end;
 
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\{#BinDirName}'), true, true, true);
    RenameFile(ExpandConstant('{app}\{#BinDirName}_Backup'), ExpandConstant('{app}\{#BinDirName}'));
  end;
end;
Что не так с моим вторым примером? Вроде выполняет все ваши требования.
По поводу ошибки: вы её поняли, о чем она гласит?
 
А думали над её решением или неохота заморачиваться?
В том-то и дело,что охота заморочится. Тут,как говорится: всё сложно...

Вот заморочился:
Код:
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\_Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\_Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\_Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\_Backup\bin-Backup'));
    end;
end;

function InitializeSetup(): Boolean;
begin
  Result := True;
  if RegKeyExists(HKEY_LOCAL_MACHINE,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') or
     RegKeyExists(HKEY_CURRENT_USER,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') then
  begin
    MsgBox('Приложение уже установлено. Выполните деинсталляцию.', mbInformation, MB_OK);
    Result := False;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\_Backup\{#BinDirName}'), true, true, true);
    RenameFile(ExpandConstant('{app}\_Backup\{#BinDirName}-Backup'), ExpandConstant('{app}\{#BinDirName}'));
    MoveDir(ExpandConstant('{app}\_Backup\'), ExpandConstant('{app}\'));
    DelTree(ExpandConstant('{app}\_Backup\'), true, true, true);
  end;
end;

Делает всё,что нужно,только вторую папку из бекапа восстанавлмвает не в {app}! Получается: папка\папка.

MoveDir(ExpandConstant('{app}\_Backup\'), ExpandConstant('{app}\')); - если убираю слеши,то не восствнавливает! Если ставлю,то папка\папка.
 
В том-то и дело,что охота заморочится. Тут,как говорится: всё сложно...

Вот заморочился:
Код:
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\_Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\_Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\_Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\_Backup\bin-Backup'));
    end;
end;

function InitializeSetup(): Boolean;
begin
  Result := True;
  if RegKeyExists(HKEY_LOCAL_MACHINE,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') or
     RegKeyExists(HKEY_CURRENT_USER,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#GameID}_is1') then
  begin
    MsgBox('Приложение уже установлено. Выполните деинсталляцию.', mbInformation, MB_OK);
    Result := False;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\_Backup\{#BinDirName}'), true, true, true);
    RenameFile(ExpandConstant('{app}\_Backup\{#BinDirName}-Backup'), ExpandConstant('{app}\{#BinDirName}'));
    MoveDir(ExpandConstant('{app}\_Backup\'), ExpandConstant('{app}\'));
    DelTree(ExpandConstant('{app}\_Backup\'), true, true, true);
  end;
end;

Делает всё,что нужно,только вторую папку из бекапа восстанавлмвает не в {app}! Получается: папка\папка.

MoveDir(ExpandConstant('{app}\_Backup\'), ExpandConstant('{app}\')); - если убираю слеши,то не восствнавливает! Если ставлю,то папка\папка.
code_language.pascal:
[Setup]
AppName=Game1
AppVersion=1.0
DefaultDirName={sd}\Game1
OutputDir=.
DirExistsWarning=no
DisableProgramGroupPage=yes

[Files]
Source: "bin\*"; DestDir: "{app}\bin"; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "Folder2\*"; DestDir: "{app}\Folder2"; BeforeInstall: MakeBackup; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "File1.exe"; DestDir: "{app}"; BeforeInstall: MakeBackup; Flags: ignoreversion

[Icons]
Name: "{userdesktop}\Удалить обновление"; Filename: "{uninstallexe}";

[code]
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\Backup\bin'));
    end;
end;

procedure CopyDir2(const FromDir, ToDir:string);
var
  res : integer;
begin
  Exec('cmd.exe', ' /C XCOPY ' + AddQuotes(FromDir) + ' ' + AddQuotes(ToDir) + ' ' + '/E /I', ExpandConstant('{sys}'), SW_Hide,ewWaitUntilTerminated,res);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\bin'), true, true, true);
    CopyDir2(ExpandConstant('{app}\Backup'), ExpandConstant('{app}'));
    DelTree(ExpandConstant('{app}\Backup'), true, true, true);
  end;
end;
 
code_language.pascal:
[Setup]
AppName=Game1
AppVersion=1.0
DefaultDirName={sd}\Game1
OutputDir=.
DirExistsWarning=no
DisableProgramGroupPage=yes

[Files]
Source: "bin\*"; DestDir: "{app}\bin"; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "Folder2\*"; DestDir: "{app}\Folder2"; BeforeInstall: MakeBackup; Flags: createallsubdirs recursesubdirs ignoreversion
Source: "File1.exe"; DestDir: "{app}"; BeforeInstall: MakeBackup; Flags: ignoreversion

[Icons]
Name: "{userdesktop}\Удалить обновление"; Filename: "{uninstallexe}";

[code]
var
  NotBackupDirExists: boolean;

procedure MakeBackup();
var
  curPath, curFile, myBackupDir: string;
begin
  if NotBackupDirExists then
  begin
    curPath := Copy(CurrentFileName, Pos('{app}\', CurrentFileName)+Length('{app}\'), Length(CurrentFileName));
    curPath := ExtractFileDir(curPath);
    curFile := ExtractFileName(CurrentFileName);
    myBackupDir := ExpandConstant('{app}\Backup\')+curPath;
    if FileExists(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile) then
    begin
      if not DirExists(myBackupDir) then ForceDirectories(myBackupDir);
      FileCopy(ExpandConstant('{app}\')+AddBackslash(curPath)+curFile, AddBackslash(myBackupDir)+curFile, false);
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      if not DirExists(ExpandConstant('{app}\Backup')) then
      begin
        NotBackupDirExists := True;
        ForceDirectories(ExpandConstant('{app}\Backup'));
      end;
      if NotBackupDirExists then
        RenameFile(ExpandConstant('{app}\bin'), ExpandConstant('{app}\Backup\bin'));
    end;
end;

procedure CopyDir2(const FromDir, ToDir:string);
var
  res : integer;
begin
  Exec('cmd.exe', ' /C XCOPY ' + AddQuotes(FromDir) + ' ' + AddQuotes(ToDir) + ' ' + '/E /I', ExpandConstant('{sys}'), SW_Hide,ewWaitUntilTerminated,res);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usDone then
  begin
    DelTree(ExpandConstant('{app}\bin'), true, true, true);
    CopyDir2(ExpandConstant('{app}\Backup'), ExpandConstant('{app}'));
    DelTree(ExpandConstant('{app}\Backup'), true, true, true);
  end;
end;
Спасибо огромное. Всё работает как часики!

/DestDir: "{app}\bin"; BeforeInstall: MakeBackup;/
 
Назад
Сверху