瀏覽代碼

Add support for overwriting read-only files.

Martijn Laan 4 月之前
父節點
當前提交
6c670c706b
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      Projects/Src/Compression.SevenZipDLLDecoder.pas

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

@@ -342,6 +342,10 @@ begin
         if not ValidateAndCombinePath(FExpandedDestDir, Path, FCurrent.ExpandedPath) then
           OleError(E_ACCESSDENIED);
         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 }
         outstream := TSequentialOutStream.Create(TFileRedir.Create(FDisableFsRedir, FCurrent.ExpandedPath, fdCreateAlways, faWrite, fsNone));
       end;