Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Created December 19, 2025 22:46
Show Gist options
  • Select an option

  • Save MartinZikmund/0e7b8d1022b0325d478ddfce4b80fd1c to your computer and use it in GitHub Desktop.

Select an option

Save MartinZikmund/0e7b8d1022b0325d478ddfce4b80fd1c to your computer and use it in GitHub Desktop.
private static string _localWadPath;
/// <summary>
/// Prepares assets for WebAssembly by downloading them via HTTP
/// </summary>
public static async Task PrepareAssetsAsync()
{
var localFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Wads", CreationCollisionOption.OpenIfExists);
foreach (var name in iwadNames)
{
var assetPath = $"Assets/{name}";
try
{
var fileFromAssets = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///{assetPath}"));
if (fileFromAssets != null)
{
// Copy to local folder
var existingFile = await localFolder.TryGetItemAsync(name);
if (existingFile != null)
{
_localWadPath = existingFile.Path;
Console.WriteLine($"IWAD {name} already exists in local folder.");
break;
} else
{
var copiedFile = await fileFromAssets.CopyAsync(localFolder, name, NameCollisionOption.ReplaceExisting);
Console.WriteLine($"Copied IWAD {name} to local folder.");
_localWadPath = copiedFile.Path;
}
}
}
catch
{
// Ignore missing assets
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment