Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MyAppName "My Program"
- #define MyAppVersion "1.5"
- [Setup]
- AppName={#MyAppName}
- AppVersion={#MyAppVersion}
- DefaultDirName={pf}\{#MyAppName}
- OutputDir=.
- [Languages]
- Name: "default"; MessagesFile: "compiler:Default.isl"
- [Files]
- Source: "{app}\1.txt"; DestDir: "{app}\txt"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
- Source: "{app}\2.txt"; DestDir: "{app}"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
- Source: "{app}\1.cjstyles"; DestDir: "{app}\cjstyles"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
- Source: "{app}\1.rtf"; DestDir: "{app}\txt"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
- Source: "{app}\1.zip"; DestDir: "{app}\zip"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
- [code]
- type
- #ifdef UNICODE
- #define A "W"
- PChar = PAnsiChar;
- #else
- #define A "A"
- #endif
- TSHFileOpStruct = record
- Wnd: HWND;
- wFunc: UINT;
- pFrom: PChar;
- pTo: PChar;
- fFlags: Word;
- fAnyOperationsAborted: BOOL;
- hNameMappings: HWND;
- lpszProgressTitle: PChar;
- end;
- const
- FO_MOVE = $0001;
- FO_COPY = $0002;
- FOF_SILENT = $0004;
- FOF_NOCONFIRMATION = $0010;
- FOF_FILESONLY = $0080;
- FOF_NOCONFIRMMKDIR = $0200;
- function SHFileOperation(const lpFileOp: TSHFileOpStruct):Integer; external 'SHFileOperation@shell32.dll stdcall';
- procedure BackupFile();
- var
- file, backFile, backpath: string;
- begin
- if FileExists(ExpandConstant(CurrentFileName)) then
- begin
- File := ExpandConstant(CurrentFileName);
- backpath := file;
- StringChangeEx(backpath, ExpandConstant('{app}'), '', True);
- backFile := ExpandConstant('{app}\Backup') + backpath;
- ForceDirectories(ExtractFilePath(backfile));
- RenameFile(file, backfile);
- end;
- end;
- function BackupDir(const fromDir, toDir: ansistring; IsMove: Boolean): Boolean;
- var
- fos: TSHFileOpStruct;
- _fromDir, _toDir: ansistring;
- SR: TFindRec;
- res: Boolean;
- begin
- ForceDirectories(toDir);
- if IsMove then
- fos.wFunc := FO_MOVE else
- fos.wFunc := FO_COPY;
- fos.fFlags := FOF_FILESONLY or FOF_SILENT or
- FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
- _fromDir:= AddBackslash(fromDir);
- _toDir := AddBackslash(toDir);
- if (Length(fromDir) = Length(_fromDir)) then
- begin
- res:= FindFirst(_fromDir + '*', SR);
- try
- while res do
- begin
- if (SR.Name <> '') and (SR.Name <> '.') and (SR.Name <> '..') then
- begin
- if SR.Attributes = FILE_ATTRIBUTE_DIRECTORY then
- begin
- _fromDir:= _fromDir + SR.Name + #0#0;
- _toDir := _toDir + #0#0;
- fos.pFrom := PChar(_fromDir);
- fos.pTo := PChar(_toDir);
- end else
- begin
- _fromDir:= _fromDir + SR.Name + #0#0;
- _toDir := _toDir + SR.Name + #0#0;
- fos.pFrom := PChar(_fromDir);
- fos.pTo := PChar(_toDir);
- end;
- Result := (0 = ShFileOperation(fos));
- _fromDir:= ExtractFilePath(_fromDir);
- _toDir:= ExtractFilePath(_toDir);
- end;
- res := FindNext(SR);
- end;
- finally
- FindClose(SR);
- end;
- end else
- begin
- _fromDir:= RemoveBackslashUnlessRoot(_fromDir) + #0#0;
- _toDir := RemoveBackslashUnlessRoot(_toDir) + #0#0;
- fos.pFrom := PChar(_fromDir);
- fos.pTo := PChar(_toDir);
- Result := (0 = ShFileOperation(fos));
- end;
- end;
- procedure RestoreBackup(backDir: string);
- begin
- BackupDir(backDir, ExpandConstant('{app}'), True);
- DelTree(backDir, true, true, true);
- end;
- procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
- begin
- if CurUninstallStep = usdone then
- begin
- RestoreBackup(ExpandConstant('{app}\Backup\'));
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement