Make it work under mono
This commit is contained in:
parent
d1e2efa945
commit
dac51f51f5
|
@ -26,8 +26,23 @@ namespace CXMLCli
|
|||
{
|
||||
|
||||
// Do you have gimconv?
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -42,31 +50,29 @@ namespace General
|
|||
|
||||
public static string GetFileExtension(byte[] Bytes)
|
||||
{
|
||||
if (IsImage(Bytes))
|
||||
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
|
||||
{
|
||||
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";
|
||||
}
|
||||
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))
|
||||
{
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user