Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SF-3159 Upgrade to SharpZipLib #2967

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="DotNetZip" Version="1.16.0" />
<PackageReference Include="Duende.AccessTokenManagement" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.7" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
Expand All @@ -41,6 +40,7 @@
InternetSettings.xml file. Also update server config scriptureforge.org_v2.yml. -->
<PackageReference Include="ParatextData" Version="9.5.0.8" />
<PackageReference Include="Serval.Client" Version="1.8.4" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.6.2" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
Expand Down
42 changes: 32 additions & 10 deletions src/SIL.XForge.Scripture/Services/SFInstallableDblResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using System.Linq;
using System.Net;
using Ionic.Zip;
using ICSharpCode.SharpZipLib.Zip;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Paratext.Data;
Expand Down Expand Up @@ -400,9 +400,32 @@ public void ExtractToDirectory(string path)
);
if (RobustFile.Exists(resourceFile))
{
using var zipFile = ZipFile.Read(resourceFile);
using var stream = new FileStream(resourceFile, FileMode.Open);
using var zipFile = new ZipFile(stream);
zipFile.Password = this._passwordProvider?.GetPassword();
zipFile.ExtractAll(path, ExtractExistingFileAction.DoNotOverwrite);
ExtractAll(zipFile, path);
}
}

private static void ExtractAll(ZipFile zip, string path)
{
foreach (ZipEntry entry in zip)
{
if (!entry.IsFile)
continue; // Skip directories

string entryPath = Path.Combine(path, entry.Name);

if (File.Exists(entryPath))
continue; // Don't overwrite

// Ensure directories in the ZIP entry are created
Directory.CreateDirectory(Path.GetDirectoryName(entryPath));

// Extract the file
using Stream zipStream = zip.GetInputStream(entry);
using FileStream output = File.Create(entryPath);
zipStream.CopyTo(output);
}
}

Expand Down Expand Up @@ -510,9 +533,8 @@ internal static IReadOnlyDictionary<string, int> GetInstalledResourceRevisions()
// See if this a zip file, and if it contains the correct ID
try
{
// This only uses DotNetZip because ParatextData uses DotNetZip
// You could use System.IO.Compression if you wanted to
using var zipFile = ZipFile.Read(resourceFile);
using var stream = new FileStream(resourceFile, FileMode.Open);
using var zipFile = new ZipFile(stream);
// Zip files use forward slashes, even on Windows
const string idSearchPath = DblFolderName + "/id/";
const string revisionSearchPath = DblFolderName + "/revision/";
Expand All @@ -524,19 +546,19 @@ internal static IReadOnlyDictionary<string, int> GetInstalledResourceRevisions()
if (
string.IsNullOrWhiteSpace(fileId)
&& !entry.IsDirectory
&& entry.FileName.StartsWith(idSearchPath, StringComparison.OrdinalIgnoreCase)
&& entry.Name.StartsWith(idSearchPath, StringComparison.OrdinalIgnoreCase)
)
{
fileId = entry.FileName.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
fileId = entry.Name.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
}
else if (
revision == 0
&& !entry.IsDirectory
&& entry.FileName.StartsWith(revisionSearchPath, StringComparison.OrdinalIgnoreCase)
&& entry.Name.StartsWith(revisionSearchPath, StringComparison.OrdinalIgnoreCase)
)
{
string revisionFilename = entry
.FileName.Split('/', StringSplitOptions.RemoveEmptyEntries)
.Name.Split('/', StringSplitOptions.RemoveEmptyEntries)
.Last();
if (!int.TryParse(revisionFilename, out revision))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text;
using Ionic.Zip;
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using Paratext.Data;
using Paratext.Data.Languages;
using Paratext.Data.ProjectFileAccess;
Expand Down Expand Up @@ -38,17 +39,17 @@
}
}

public ZipFile ZipFile { get; } = new ZipFile(new UTF8Encoding());
public ZipFile ZipFile { get; } = new ZipFile(new MemoryStream());

protected override ProjectFileManager CreateFileManager() =>
new MockZippedProjectFileManager(ZipFile, loadDblSettings: true, Name);

Check failure on line 45 in test/SIL.XForge.Scripture.Tests/Services/MockResourceScrText.cs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

Argument 1: cannot convert from 'ICSharpCode.SharpZipLib.Zip.ZipFile' to 'Ionic.Zip.ZipFile'

Check failure on line 45 in test/SIL.XForge.Scripture.Tests/Services/MockResourceScrText.cs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

Argument 1: cannot convert from 'ICSharpCode.SharpZipLib.Zip.ZipFile' to 'Ionic.Zip.ZipFile'

Check failure on line 45 in test/SIL.XForge.Scripture.Tests/Services/MockResourceScrText.cs

View workflow job for this annotation

GitHub Actions / Production build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

Argument 1: cannot convert from 'ICSharpCode.SharpZipLib.Zip.ZipFile' to 'Ionic.Zip.ZipFile'

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
ZipFile.Dispose();
(ZipFile as IDisposable).Dispose();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6786,7 +6786,8 @@ public MockResourceScrText GetResourceScrText(
CachedGuid = HexId.FromStr(projectId),
};
scrText.Settings.LanguageID = LanguageId.English;
scrText.ZipFile.AddFile(
scrText.ZipFile.BeginUpdate(); //todo check other places???
scrText.ZipFile.Add(
Path.Combine(ZippedProjectFileManagerBase.DBLFolderName, "language", "iso", zipLanguageCode)
);
return scrText;
Expand Down
Loading