From dac51f51f5e657f028bf6aa738eb88c5e02bd7fd Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Sat, 15 Jan 2022 01:08:53 +1300 Subject: [PATCH] Make it work under mono --- AppInfoCli/CXMLCli.csproj | 2 +- AppInfoCli/Program.cs | 21 +++++++++-- AppInfoCli/Tools.cs | 73 ++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 44 deletions(-) diff --git a/AppInfoCli/CXMLCli.csproj b/AppInfoCli/CXMLCli.csproj index 73c096b..01a2170 100644 --- a/AppInfoCli/CXMLCli.csproj +++ b/AppInfoCli/CXMLCli.csproj @@ -109,4 +109,4 @@ - \ No newline at end of file + diff --git a/AppInfoCli/Program.cs b/AppInfoCli/Program.cs index bdb165c..337c876 100644 --- a/AppInfoCli/Program.cs +++ b/AppInfoCli/Program.cs @@ -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; diff --git a/AppInfoCli/Tools.cs b/AppInfoCli/Tools.cs index 230a829..c745f3d 100644 --- a/AppInfoCli/Tools.cs +++ b/AppInfoCli/Tools.cs @@ -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);