Skip to content

Commit 4f9a22c

Browse files
committed
fix bugs for files with read-only attributes.
1 parent 2f226ca commit 4f9a22c

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

Applications/Ice/Main/Sources/Internal/Ads/Interop.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ public static IEnumerable<FileDataStream> EnumerateDataStreams(string src)
7474

7575
ThrowErrorAsException(err, lpFileName);
7676
}
77-
78-
Logger.Debug($"{lpFileName} -> {new string(data.cStreamName)}");
7977
return data;
8078
}
8179

@@ -91,7 +89,6 @@ public static IEnumerable<FileDataStream> EnumerateDataStreams(string src)
9189

9290
ThrowErrorAsException(err, null);
9391
}
94-
9592
return data;
9693
}
9794

Applications/Ice/Main/Sources/Internal/Ads/ZoneId.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Cube.FileSystem.SevenZip.Ice;
2121
using System.Linq;
2222
using System.Security;
2323
using System.Text;
24+
using Cube.Text.Extensions;
2425

2526
/* ------------------------------------------------------------------------- */
2627
///
@@ -94,7 +95,9 @@ public static SecurityZone Get(string src)
9495

9596
while ((str = reader.ReadLine()) != null)
9697
{
97-
if (str.StartsWith(key) && int.TryParse(str.Trim().Substring(key.Length), out var n)) return n switch
98+
if (str.FuzzyStartsWith(key) &&
99+
int.TryParse(str.Trim().Substring(key.Length), out var n)
100+
) return n switch
98101
{
99102
0 => SecurityZone.MyComputer,
100103
1 => SecurityZone.Intranet,
@@ -119,10 +122,17 @@ public static SecurityZone Get(string src)
119122
/* --------------------------------------------------------------------- */
120123
public static void Set(string src, SecurityZone id)
121124
{
122-
var ads = new FileDataStream(src, FileName, 0, FileDataStreamType.Data);
123-
using var writer = new StreamWriter(ads.Create(), Encoding.Default);
124-
writer.WriteLine($"[{SectionName}]");
125-
writer.WriteLine($"{KeyName}={id:D}");
125+
var attr = Io.Get(src).Attributes;
126+
127+
try
128+
{
129+
Io.SetAttributes(src, FileAttributes.Normal);
130+
var ads = new FileDataStream(src, FileName, 0, FileDataStreamType.Data);
131+
using var writer = new StreamWriter(ads.Create(), Encoding.Default);
132+
writer.WriteLine($"[{SectionName}]");
133+
writer.WriteLine($"{KeyName}={id:D}");
134+
}
135+
finally { Io.SetAttributes(src, attr); }
126136
}
127137

128138
#endregion
@@ -156,7 +166,7 @@ private static bool MoveSection(StreamReader src)
156166
string str;
157167
while ((str = src.ReadLine()) != null)
158168
{
159-
if (str.Trim() == $"[{SectionName}]") return true;
169+
if (str.Trim().FuzzyEquals($"[{SectionName}]")) return true;
160170
}
161171
return false;
162172
}
6.18 KB
Binary file not shown.

Tests/Ice/Sources/ExtractTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Cube.FileSystem.SevenZip.Ice.Tests;
2020
using System.Collections.Generic;
2121
using System.Linq;
2222
using System.Security;
23+
using Cube.Tests.Mocks;
2324
using NUnit.Framework;
2425

2526
/* ------------------------------------------------------------------------- */
@@ -55,6 +56,10 @@ public void Extract(string dest, IEnumerable<string> files, IEnumerable<string>
5556
foreach (var e in sources) ZoneId.Set(e, SecurityZone.Internet);
5657

5758
using var vm = NewVM(args.Concat(sources), settings);
59+
using var dc = new DisposableContainer();
60+
61+
dc.Add(new MockDialogBehavior(vm));
62+
5863
using (vm.SetPassword("password")) // if needed
5964
using (vm.SetDestination(Get("Runtime")))
6065
{
@@ -147,6 +152,18 @@ public static IEnumerable<TestCaseData> TestCases { get
147152
}
148153
);
149154

155+
yield return new(
156+
@"Preset\SampleReadOnly",
157+
new[] { "SampleReadOnly.zip" },
158+
Preset.Extract.ToArguments(),
159+
new ExtractionSettingValue
160+
{
161+
SaveLocation = SaveLocation.Preset,
162+
SaveMethod = SaveMethod.CreateSmart,
163+
Filtering = true,
164+
}
165+
);
166+
150167
yield return new(
151168
@"Preset\Sample 2018.02.13",
152169
new[] { "Sample 2018.02.13.zip" },

0 commit comments

Comments
 (0)