ied206/Joveler.FileMagician

Mobile OS support

pm64 opened this issue · 3 comments

pm64 commented

In this age of modern .NET miracles, I wonder if support for Android and iOS has been considered?

I have not engaged in mobile C# development, and do not have a plan to in the near future yet.
However, I always welcome tests and contributions!

The libmagic bindings should work in theory if you supply your own binary.
On .NET Core 3.1 or later, this library uses NativeLibrary to load a native library. If this API does not support mobile platforms, you may be out of luck.

Do Android/iOS allow the use of libdl?

pm64 commented

This is not an area where I have overwhelming expertise, but I see that it should be possible to obtain the binaries:

Android:
https://github.com/huzongyao/AndroidMagic

iOS:
https://github.com/kishikawakatsumi/swift-magic

pm64 commented

Moving this here from #4

I started taking a look at requirements for #2, and it seems that a (seemingly) small enhancement could open the door to achieving it.

In .NET MAUI, the modern mobile development framework for .NET, "Content" is not a valid build action for magic.mgc and magic.src.

Instead, in this case it's necessary to use the new "MauiAsset" build action to include these files in the build.

Following this, you'd access magic.mgc like so:

async Task LoadMauiAsset()
{
	using var stream = await FileSystem.OpenAppPackageFileAsync("magic.mgc");
	using var reader = new StreamReader(stream);
	
	var contents = reader.ReadToEnd();
}

This has to do with how MAUI manages assets and abstracts away details of the device's underlying file system.

So, if overrides for Magic.Open() and Magic.GlobalInit() were added that could accept a stream like this as the parameter, then native binaries for iOS and Android could be added, and voila!

I hope you'll consider making this enhancement. I'm at your disposal to assist in any way.