Advertisement
Oxygene

Untitled

Feb 7th, 2016
2,540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define MyAppName "My Program"
  2. #define MyAppVersion "1.5"
  3.  
  4. [Setup]
  5. AppName={#MyAppName}
  6. AppVersion={#MyAppVersion}
  7. DefaultDirName={pf}\{#MyAppName}
  8. OutputDir=.
  9.  
  10. [Languages]
  11. Name: "default"; MessagesFile: "compiler:Default.isl"
  12.  
  13. [Files]
  14. Source: "{app}\1.txt"; DestDir: "{app}\txt"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
  15. Source: "{app}\2.txt"; DestDir: "{app}"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
  16. Source: "{app}\1.cjstyles"; DestDir: "{app}\cjstyles"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
  17. Source: "{app}\1.rtf"; DestDir: "{app}\txt"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
  18. Source: "{app}\1.zip"; DestDir: "{app}\zip"; BeforeInstall: "BackupFile()"; Flags: ignoreversion
  19.  
  20. [code]
  21. type
  22. #ifdef UNICODE
  23. #define A "W"
  24. PChar = PAnsiChar;
  25. #else
  26. #define A "A"
  27. #endif
  28.    TSHFileOpStruct =  record
  29.      Wnd: HWND;
  30.      wFunc: UINT;
  31.      pFrom: PChar;
  32.      pTo: PChar;
  33.      fFlags: Word;
  34.      fAnyOperationsAborted: BOOL;
  35.      hNameMappings: HWND;
  36.      lpszProgressTitle: PChar;
  37.    end;
  38.    
  39. const
  40.    FO_MOVE            = $0001;
  41.    FO_COPY            = $0002;
  42.    FOF_SILENT         = $0004;
  43.    FOF_NOCONFIRMATION = $0010;
  44.    FOF_FILESONLY      = $0080;
  45.    FOF_NOCONFIRMMKDIR = $0200;
  46.  
  47. function SHFileOperation(const lpFileOp: TSHFileOpStruct):Integer; external 'SHFileOperation@shell32.dll stdcall';
  48.  
  49. procedure BackupFile();
  50. var
  51. file, backFile, backpath: string;
  52. begin
  53. if FileExists(ExpandConstant(CurrentFileName)) then
  54. begin
  55. File := ExpandConstant(CurrentFileName);
  56. backpath := file;
  57. StringChangeEx(backpath, ExpandConstant('{app}'), '', True);
  58. backFile := ExpandConstant('{app}\Backup') + backpath;
  59. ForceDirectories(ExtractFilePath(backfile));
  60. RenameFile(file, backfile);
  61. end;
  62. end;
  63.  
  64. function BackupDir(const fromDir, toDir: ansistring; IsMove: Boolean): Boolean;
  65. var
  66.   fos: TSHFileOpStruct;
  67.   _fromDir, _toDir: ansistring;
  68.   SR: TFindRec;
  69.   res: Boolean;
  70. begin
  71.     ForceDirectories(toDir);
  72.   if IsMove then
  73.     fos.wFunc  := FO_MOVE else
  74.     fos.wFunc  := FO_COPY;
  75.     fos.fFlags := FOF_FILESONLY or FOF_SILENT or
  76.                FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
  77.     _fromDir:= AddBackslash(fromDir);
  78.     _toDir  := AddBackslash(toDir);
  79.   if (Length(fromDir) = Length(_fromDir)) then
  80.     begin
  81.         res:= FindFirst(_fromDir + '*', SR);
  82.       try
  83.         while res do
  84.         begin
  85.           if (SR.Name <> '') and (SR.Name <> '.') and (SR.Name <> '..') then
  86.           begin
  87.             if SR.Attributes = FILE_ATTRIBUTE_DIRECTORY then
  88.               begin
  89.                 _fromDir:= _fromDir + SR.Name + #0#0;
  90.                 _toDir  := _toDir + #0#0;
  91.                 fos.pFrom  := PChar(_fromDir);
  92.                 fos.pTo    := PChar(_toDir);
  93.               end else
  94.               begin
  95.                 _fromDir:= _fromDir + SR.Name + #0#0;
  96.                 _toDir  := _toDir   + SR.Name + #0#0;
  97.                 fos.pFrom  := PChar(_fromDir);
  98.                 fos.pTo    := PChar(_toDir);
  99.               end;
  100.                 Result := (0 = ShFileOperation(fos));
  101.                 _fromDir:= ExtractFilePath(_fromDir);
  102.                 _toDir:= ExtractFilePath(_toDir);
  103.           end;
  104.           res := FindNext(SR);
  105.         end;
  106.       finally
  107.         FindClose(SR);
  108.       end;
  109.     end else
  110.     begin
  111.       _fromDir:= RemoveBackslashUnlessRoot(_fromDir) + #0#0;
  112.       _toDir  := RemoveBackslashUnlessRoot(_toDir)   + #0#0;
  113.       fos.pFrom  := PChar(_fromDir);
  114.       fos.pTo    := PChar(_toDir);
  115.       Result := (0 = ShFileOperation(fos));
  116.     end;
  117. end;
  118.  
  119. procedure RestoreBackup(backDir: string);
  120. begin
  121. BackupDir(backDir, ExpandConstant('{app}'), True);
  122. DelTree(backDir, true, true, true);
  123. end;
  124.  
  125. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  126. begin
  127. if CurUninstallStep = usdone then
  128. begin
  129. RestoreBackup(ExpandConstant('{app}\Backup\'));
  130. end;
  131. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement