Skip to content

Commit e361cbc

Browse files
committed
Android: Extract assets to file for song and video assets anyway; Bump version
1 parent 7cdbb4b commit e361cbc

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎FNA.NET.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@
460460
<PackageTags>fna;xna;net8</PackageTags>
461461
<PackageId>FNA.NET</PackageId>
462462
<Copyright>Copyright 2026 FNA-NET</Copyright>
463-
<VersionPrefix>2.2.10.2602</VersionPrefix>
463+
<VersionPrefix>2.2.11.2602</VersionPrefix>
464464
<VersionSuffix></VersionSuffix>
465465
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
466466

‎src/SDL3IOStream.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public override long Position
6868
set => SDL.SDL_SeekIO(_io, value, SDL.SDL_IOWhence.SDL_IO_SEEK_SET);
6969
}
7070

71+
public string FileName => _filename;
72+
7173
#endregion
7274

7375
#region Stream Methods

‎src/TitleContainer.cs‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#region Using Statements
2222
using System;
2323
using System.IO;
24-
24+
using Microsoft.Xna.Framework.Media;
2525
using SDL3;
2626
#endregion
2727

@@ -36,7 +36,12 @@ public static Stream OpenStream(string name)
3636
string safeName = MonoGame.Utilities.FileHelpers.NormalizeFilePathSeparators(name);
3737

3838
if (SDL.SDL_GetPlatform() == "Android")
39+
{
40+
if (IsSongOrVideo(safeName))
41+
return AndroidExtractAssetAndOpenStream(safeName);
42+
3943
return new SDL3IOStream(safeName);
44+
}
4045

4146
#if CASE_SENSITIVITY_HACK
4247
if (Path.IsPathRooted(safeName))
@@ -146,6 +151,44 @@ private static string SearchCase(string name, string[] list)
146151
#endif
147152

148153
#endregion
154+
155+
internal static bool IsSongOrVideo(string name)
156+
{
157+
string ext = Path.GetExtension(name).ToLower();
158+
for (int i = 0; i < Content.SongReader.supportedExtensions.Length; i += 1)
159+
{
160+
if (ext == Content.SongReader.supportedExtensions[i])
161+
return true;
162+
}
163+
for (int i = 0; i < Content.VideoReader.supportedExtensions.Length; i += 1)
164+
{
165+
if (ext == Content.VideoReader.supportedExtensions[i])
166+
return true;
167+
}
168+
foreach(var item in VideoPlayer.codecExtensions)
169+
{
170+
if (ext == "." + item.Key)
171+
return true;
172+
}
173+
return false;
174+
}
175+
176+
public static FileStream AndroidExtractAssetAndOpenStream(string name)
177+
{
178+
var path = Path.Combine(TitleLocation.Path, name);
179+
if (!File.Exists(path))
180+
{
181+
var inputStream = new SDL3IOStream(name);
182+
183+
Directory.CreateDirectory(Path.GetDirectoryName(path)); // Ensure subdirectories
184+
FileStream s = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
185+
inputStream.CopyTo(s);
186+
s.Seek(0, SeekOrigin.Begin);
187+
return s;
188+
}
189+
else
190+
return File.OpenRead(path);
191+
}
149192
}
150193
}
151194

0 commit comments

Comments
 (0)