Make it work under mono

This commit is contained in:
SilicaAndPina 2022-01-15 01:08:53 +13:00
parent d1e2efa945
commit dac51f51f5
3 changed files with 52 additions and 44 deletions

View File

@ -109,4 +109,4 @@
<Content Include="cxml.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

View File

@ -24,10 +24,25 @@ namespace CXMLCli
}
static int Main(string[] args)
{
// Do you have gimconv?
if (!File.Exists(Path.Combine("GimConv", "GimConv.exe")))
GimConv.DownloadGimConv(); // Politely ask sony to give it to us.
bool windowsNT = Environment.OSVersion.Platform.Equals(PlatformID.Win32NT);
bool windows32 = Environment.OSVersion.Platform.Equals(PlatformID.Win32Windows);
bool windows32S = Environment.OSVersion.Platform.Equals(PlatformID.Win32S);
bool windowsCE = Environment.OSVersion.Platform.Equals(PlatformID.WinCE);
if (windowsNT || windows32 || windows32S || windowsCE)
{
if (!File.Exists(Path.Combine("GimConv", "GimConv.exe")))
{
GimConv.DownloadGimConv(); // Politely ask sony to give it to us.
}
}
else
{
Console.WriteLine("NOTE: GimConv is windows binary, so you cant use it on this OS!\n.GIM Decoding will be disabled!");
}
bool Check = true;

View File

@ -13,6 +13,14 @@ namespace General
class Tools
{
public static byte[] bmp = Encoding.ASCII.GetBytes("BM"); // BMP
public static byte[] gif = Encoding.ASCII.GetBytes("GIF"); // GIF
public static byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
public static byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
public static byte[] tiff2 = new byte[] { 77, 77, 42 }; // TIFF
public static byte[] jpeg = new byte[] { 255, 216, 255 }; // jpeg
public static void WriteStringToStream(Stream s, String str)
{
Byte[] bytes = Encoding.UTF8.GetBytes(str);
@ -40,34 +48,32 @@ namespace General
return Bytes;
}
public static string GetFileExtension(byte[] Bytes)
public static string GetFileExtension(byte[] Bytes)
{
if (IsImage(Bytes))
{
using (Bitmap bmp = GetBitmap(Bytes))
{
if (bmp.RawFormat.Equals(ImageFormat.Jpeg))
return ".jpeg";
else if (bmp.RawFormat.Equals(ImageFormat.Bmp))
return ".bmp";
else if (bmp.RawFormat.Equals(ImageFormat.Gif))
return ".gif";
else if (bmp.RawFormat.Equals(ImageFormat.Png))
return ".png";
else if (bmp.RawFormat.Equals(ImageFormat.Tiff))
return ".tiff";
else if (bmp.RawFormat.Equals(ImageFormat.Icon))
return ".ico";
else if (bmp.RawFormat.Equals(ImageFormat.Exif))
return ".exif";
else if (bmp.RawFormat.Equals(ImageFormat.Emf))
return ".emf";
else if (bmp.RawFormat.Equals(ImageFormat.Wmf))
return ".wmf";
else
return ".raw";
}
}
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
{
return ".bmp";
}
else if (gif.SequenceEqual(Bytes.Take(gif.Length)))
{
return ".gif";
}
else if (png.SequenceEqual(Bytes.Take(png.Length)))
{
return ".png";
}
else if (tiff.SequenceEqual(Bytes.Take(tiff.Length)))
{
return ".tiff";
}
else if (tiff2.SequenceEqual(Bytes.Take(tiff2.Length)))
{
return ".tiff";
}
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
{
return ".jpg";
}
else if (IsZlib(Bytes))
{
return ".z";
@ -171,19 +177,6 @@ namespace General
public static bool IsImage(byte[] Bytes)
{
try
{
GetBitmap(Bytes);
}
catch (Exception)
{
return false;
}
return true;
}
public static Bitmap GetBitmap(byte[] BitmapBytes)
{
MemoryStream ms = ByteToStream(BitmapBytes);