2
0
Эх сурвалжийг харах

Add support for overwriting read-only files.

Martijn Laan 3 сар өмнө
parent
commit
6c670c706b

+ 4 - 0
Projects/Src/Compression.SevenZipDLLDecoder.pas

@@ -342,6 +342,10 @@ begin
         if not ValidateAndCombinePath(FExpandedDestDir, Path, FCurrent.ExpandedPath) then
         if not ValidateAndCombinePath(FExpandedDestDir, Path, FCurrent.ExpandedPath) then
           OleError(E_ACCESSDENIED);
           OleError(E_ACCESSDENIED);
         ForceDirectories(FDisableFsRedir, PathExtractPath(FCurrent.ExpandedPath));
         ForceDirectories(FDisableFsRedir, PathExtractPath(FCurrent.ExpandedPath));
+        const ExistingFileAttr = GetFileAttributesRedir(FDisableFsRedir, FCurrent.ExpandedPath);
+        if (ExistingFileAttr <> INVALID_FILE_ATTRIBUTES) and
+           (ExistingFileAttr and FILE_ATTRIBUTE_READONLY <> 0) then
+          SetFileAttributesRedir(FDisableFsRedir, FCurrent.ExpandedPath, ExistingFileAttr and not FILE_ATTRIBUTE_READONLY);
         { From IArchive.h: can also set outstream to nil to tell 7zip to skip the file }
         { From IArchive.h: can also set outstream to nil to tell 7zip to skip the file }
         outstream := TSequentialOutStream.Create(TFileRedir.Create(FDisableFsRedir, FCurrent.ExpandedPath, fdCreateAlways, faWrite, fsNone));
         outstream := TSequentialOutStream.Create(TFileRedir.Create(FDisableFsRedir, FCurrent.ExpandedPath, fdCreateAlways, faWrite, fsNone));
       end;
       end;