Skip to content

Commit

Permalink
Ported to SharpZipLib
Browse files Browse the repository at this point in the history
  • Loading branch information
uholeschak committed Dec 20, 2024
1 parent 8483ec1 commit 4552644
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
38 changes: 25 additions & 13 deletions Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
using Xamarin.Android.Tools;

Expand Down Expand Up @@ -35,10 +36,14 @@ protected AssemblyStoreExplorer (Stream storeStream, string path)
Is64Bit = reader.Is64Bit;

var dict = new Dictionary<string, AssemblyStoreItem> (StringComparer.Ordinal);
foreach (AssemblyStoreItem item in Assemblies) {
dict.Add (item.Name, item);
}
AssembliesByName = dict.AsReadOnly ();
if (Assemblies != null)
{
foreach (AssemblyStoreItem item in Assemblies)
{
dict.Add(item.Name, item);
}
}
AssembliesByName = dict.AsReadOnly ();
}

protected AssemblyStoreExplorer (FileInfo storeInfo)
Expand Down Expand Up @@ -151,16 +156,23 @@ public static (IList<AssemblyStoreExplorer>? explorers, string? errorMessage) Op
{
var ret = new List<AssemblyStoreExplorer> ();

foreach (string path in paths) {
if (!zip.ContainsEntry (path)) {
continue;
}
foreach (string path in paths)
{
foreach (ZipEntry zipEntry in zf)
{
if (!zipEntry.IsFile)
{
continue; // Ignore directories
}

ZipEntry entry = zip.ReadEntry (path);
var stream = new MemoryStream ();
entry.Extract (stream);
ret.Add (new AssemblyStoreExplorer (stream, $"{fi.FullName}!{path}"));
}
if (string.Compare(zipEntry.Name, path, StringComparison.OrdinalIgnoreCase) == 0)
{
Stream zipStream = zf.GetInputStream(zipEntry);
ret.Add(new AssemblyStoreExplorer(zipStream, $"{fi.FullName}!{path}"));
break;
}
}
}

if (ret.Count == 0) {
return (null, null, false);
Expand Down
12 changes: 6 additions & 6 deletions Tools/ApkUncompress2/Utilities/MonoAndroidHelper.Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static AndroidTargetArch AbiToTargetArch (string abi)

public static string AbiToRid (string abi)
{
if (!AbiToRidMap.TryGetValue (abi, out string rid)) {
if (!AbiToRidMap.TryGetValue (abi, out string? rid)) {
throw new NotSupportedException ($"Internal error: unsupported ABI '{abi}'");
};

Expand All @@ -103,7 +103,7 @@ public static string AbiToRid (string abi)

public static string RidToAbi (string rid)
{
if (!RidToAbiMap.TryGetValue (rid, out string abi)) {
if (!RidToAbiMap.TryGetValue (rid, out string? abi)) {
throw new NotSupportedException ($"Internal error: unsupported Runtime Identifier '{rid}'");
};

Expand Down Expand Up @@ -131,7 +131,7 @@ public static AndroidTargetArch RidToArch (string rid)

public static string ArchToRid (AndroidTargetArch arch)
{
if (!ArchToRidMap.TryGetValue (arch, out string rid)) {
if (!ArchToRidMap.TryGetValue (arch, out string? rid)) {
throw new InvalidOperationException ($"Internal error: unsupported architecture '{arch}'");
};

Expand All @@ -140,7 +140,7 @@ public static string ArchToRid (AndroidTargetArch arch)

public static string ArchToAbi (AndroidTargetArch arch)
{
if (!ArchToAbiMap.TryGetValue (arch, out string abi)) {
if (!ArchToAbiMap.TryGetValue (arch, out string? abi)) {
throw new InvalidOperationException ($"Internal error: unsupported architecture '{arch}'");
};

Expand All @@ -158,9 +158,9 @@ public static string ArchToAbi (AndroidTargetArch arch)
return Convert.ToString (obj, CultureInfo.InvariantCulture);
}

public static string MapAndroidAbiToClang (string androidAbi)
public static string? MapAndroidAbiToClang (string androidAbi)
{
if (ClangAbiMap.TryGetValue (androidAbi, out string clangAbi)) {
if (ClangAbiMap.TryGetValue (androidAbi, out string? clangAbi)) {
return clangAbi;
}
return null;
Expand Down

0 comments on commit 4552644

Please sign in to comment.