Skip to content

Commit

Permalink
Moved sample to asset
Browse files Browse the repository at this point in the history
  • Loading branch information
uholeschak committed Dec 31, 2024
1 parent 16fdfca commit 1995952
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
27 changes: 25 additions & 2 deletions BmwDeepObd/ActivityCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10912,7 +10912,7 @@ public static string GetAssetEcuFilename()
try
{
Regex regex = new Regex(@"^Ecu.*\.bin$", RegexOptions.IgnoreCase);
AssetManager assets = ActivityCommon.GetPackageContext()?.Assets;
AssetManager assets = GetPackageContext()?.Assets;
if (assets != null)
{
string[] assetFiles = assets.List(string.Empty);
Expand Down Expand Up @@ -11055,7 +11055,30 @@ public static void ExtractZipFile(AssetManager assetManager, Assembly resourceAs
}
else
{
if (resourceAssembly != null)
if (assetManager != null)
{
AssetFileDescriptor assetFile = null;
try
{
assetFile = assetManager.OpenFd(archiveFilenameIn);
using (Stream inputStream = assetFile.CreateInputStream())
{
if (inputStream == null)
{
throw new IOException("Opening asset stream failed");
}

fs = new MemoryStream();
inputStream.CopyTo(fs);
fs.Seek(0, SeekOrigin.Begin);
}
}
finally
{
assetFile?.Close();
}
}
else if (resourceAssembly != null)
{
fs = resourceAssembly.GetManifestResourceStream(archiveFilenameIn);
}
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions BmwDeepObd/BmwDeepObd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ItemGroup>
<AndroidAsset Remove="Assets\.gitignore" />
<AndroidAsset Update="Assets\Ecu.bin" AssetPack="assets1" DeliveryType="InstallTime" />
<AndroidAsset Update="Assets\Sample.zip" AssetPack="assets1" DeliveryType="InstallTime" />
</ItemGroup>
<ItemGroup>
<TrimmerRootAssembly Include="Mono.Android" RootMode="visible" />
Expand All @@ -44,7 +45,6 @@
<None Remove="Assets\Ecu.bin" />
<None Remove="Resources\layout\service_busy.xml" />
<None Remove="Resources\xml\automotive_app_desc.xml" />
<None Remove="Sample\Sample.zip" />
<None Remove="Xml\BmwDeepObd.xsd" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -76,7 +76,6 @@
<Compile Include="..\Tools\ApkUncompress2\Utilities\MonoAndroidHelper.Basic.cs" Link="ApkUncompress\MonoAndroidHelper.Basic.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Sample\Sample.zip" />
<EmbeddedResource Include="Xml\BmwDeepObd.xsd" />
</ItemGroup>
<ItemGroup>
Expand Down
24 changes: 21 additions & 3 deletions BmwDeepObd/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6453,7 +6453,26 @@ private bool ExtractSampleFiles(bool force = false)
return false;
}

string resourceName = VehicleInfoBmw.FindResourceName("Sample.zip");
AssetManager assets = ActivityCommon.GetPackageContext()?.Assets;
if (assets == null)
{
return false;
}

string resourceName = null;
string[] assetFiles = assets.List(string.Empty);
if (assetFiles != null)
{
foreach (string fileName in assetFiles)
{
if (fileName.EndsWith("Sample.zip", StringComparison.OrdinalIgnoreCase))
{
resourceName = fileName;
break;
}
}
}

if (string.IsNullOrEmpty(resourceName))
{
return false;
Expand Down Expand Up @@ -6518,8 +6537,7 @@ private bool ExtractSampleFiles(bool force = false)
}
}

Assembly assembly = Assembly.GetExecutingAssembly();
ActivityCommon.ExtractZipFile(null, assembly, resourceName, sampleDir, null, null, null, null);
ActivityCommon.ExtractZipFile(assets, null, resourceName, sampleDir, null, null, null, null);

XElement xmlInfo = new XElement("Info");
xmlInfo.Add(new XAttribute("Name", resourceName));
Expand Down

0 comments on commit 1995952

Please sign in to comment.