Skip to content

Commit 42407c1

Browse files
committed
fix - use resource submodule
1 parent ac4bda5 commit 42407c1

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

src/DotFastLZ.Resource/R.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public static class R
3636

3737
// ready zip files
3838
public static readonly ImmutableArray<SourceZip> SourceZipFiles = ImmutableArray.Create(
39-
new SourceZip("canterburycorpus.zip", "canterbury"),
40-
new SourceZip("silesia.zip", "silesia"),
41-
new SourceZip("enwik8.zip", "enwik")
39+
new SourceZip("enwik/enwik8.zip", "enwik/enwik8.txt")
4240
);
4341

4442
public static readonly ImmutableArray<string> SourceFiles = ImmutableArray.Create(
@@ -65,7 +63,7 @@ public static class R
6563
"silesia/webster",
6664
"silesia/x-ray",
6765
"silesia/xml",
68-
"enwik/enwik8"
66+
"enwik/enwik8.txt"
6967
);
7068

7169

@@ -79,20 +77,22 @@ public static byte[] ToBytes(string filename)
7977
return buffer;
8078
}
8179

82-
public static string Find(string pathName)
80+
public static string Find(string path)
8381
{
84-
string path = Path.Combine("resources", pathName);
82+
string rpath = Path.Combine(Prefix, path);
83+
//Console.WriteLine(rpath);
8584
for (int i = 0; i < 10; ++i)
8685
{
87-
if (File.Exists(path) || Directory.Exists(path))
86+
if (File.Exists(rpath) || Directory.Exists(rpath))
8887
{
89-
return Path.GetFullPath(path);
88+
return Path.GetFullPath(rpath);
9089
}
9190

92-
path = Path.Combine("..", path);
91+
rpath = Path.Combine("..", rpath);
92+
//Console.WriteLine($"{i} - {rpath}");
9393
}
9494

95-
return Path.GetFullPath(pathName);
95+
return Path.GetFullPath(rpath);
9696
}
9797

9898
public static int ExtractZipFile(string zipFilePath, string destDir)
@@ -200,16 +200,15 @@ public static void ExtractAll()
200200
// extract source files
201201
foreach (var sourceZip in SourceZipFiles)
202202
{
203-
sourceZip.Extract(Prefix);
203+
sourceZip.Extract("");
204204
}
205205
}
206206

207207
public static void DeleteAll()
208208
{
209-
var path = Find(Prefix);
210-
if (!string.IsNullOrEmpty(path))
209+
foreach (var sourceZip in SourceZipFiles)
211210
{
212-
Directory.Delete(path, true);
211+
sourceZip.Delete();
213212
}
214213
}
215214
}

src/DotFastLZ.Resource/SourceZip.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,38 @@ namespace DotFastLZ.Resource;
2727

2828
public class SourceZip
2929
{
30-
private readonly string _fileName;
31-
private readonly string _extractPath;
30+
private readonly string _path;
31+
private readonly string _deletablePath;
3232

33-
public SourceZip(string fileName, string extractPath)
33+
public SourceZip(string path, string deletablePath)
3434
{
35-
_fileName = fileName;
36-
_extractPath = extractPath;
35+
_path = path;
36+
_deletablePath = deletablePath;
3737
}
3838

3939
public void Extract(string extractRootPath)
4040
{
41-
var zipFilePath = R.Find(_fileName);
41+
var zipFilePath = R.Find(_path);
4242
var directoryName = Path.GetDirectoryName(zipFilePath);
4343
if (null == directoryName)
4444
{
4545
throw new DirectoryNotFoundException($"not found directoryName - {zipFilePath}");
4646
}
4747

48-
var extractPath = Path.Combine(directoryName, extractRootPath, _extractPath);
48+
var extractPath = Path.Combine(directoryName, extractRootPath);
4949
R.ExtractZipFile(zipFilePath, extractPath);
5050
}
51+
52+
public void Delete()
53+
{
54+
var deletePath = R.Find(_deletablePath);
55+
if (Directory.Exists(deletePath))
56+
{
57+
Directory.Delete(deletePath, true);
58+
}
59+
else if (File.Exists(deletePath))
60+
{
61+
File.Delete(deletePath);
62+
}
63+
}
5164
}

test/DotFastLZ.Compression.Tests/RoundTripTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void TestRefDecompressorLevel1()
5353
Console.WriteLine("Test reference decompressor for Level 1");
5454
foreach (var name in R.SourceFiles)
5555
{
56-
var filename = R.Find(Path.Combine(R.Prefix, name));
56+
var filename = R.Find(name);
5757
bool result = TestHelper.test_ref_decompressor_level1(name, filename);
5858
Assert.That(result, Is.EqualTo(true), $"test_ref_decompressor_level1({name}, {filename})");
5959
}
@@ -65,7 +65,7 @@ public void TestRefDecompressorLevel2()
6565
Console.WriteLine("Test reference decompressor for Level 2");
6666
foreach (var name in R.SourceFiles)
6767
{
68-
var filename = R.Find(Path.Combine(R.Prefix, name));
68+
var filename = R.Find(name);
6969
bool result = TestHelper.test_ref_decompressor_level2(name, filename);
7070
Assert.That(result, Is.EqualTo(true), $"test_ref_decompressor_level2({name}, {filename})");
7171
}
@@ -78,7 +78,7 @@ public void TestRoundtripLevel1()
7878
Console.WriteLine("Test round-trip for Level 1");
7979
foreach (var name in R.SourceFiles)
8080
{
81-
var filename = R.Find(Path.Combine(R.Prefix, name));
81+
var filename = R.Find(name);
8282
bool result = TestHelper.test_roundtrip_level1(name, filename);
8383
Assert.That(result, Is.EqualTo(true), $"test_roundtrip_level1({name}, {filename})");
8484
}
@@ -90,7 +90,7 @@ public void TestRoundtripLevel2()
9090
Console.WriteLine("Test round-trip for Level 2");
9191
foreach (var name in R.SourceFiles)
9292
{
93-
var filename = R.Find(Path.Combine(R.Prefix, name));
93+
var filename = R.Find(name);
9494
var result = TestHelper.test_roundtrip_level2(name, filename);
9595
Assert.That(result, Is.EqualTo(true), $"test_roundtrip_level2({name}, {filename})");
9696
}

0 commit comments

Comments
 (0)