Make it work under mono
This commit is contained in:
parent
d1e2efa945
commit
dac51f51f5
|
@ -109,4 +109,4 @@
|
||||||
<Content Include="cxml.ico" />
|
<Content Include="cxml.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -24,10 +24,25 @@ namespace CXMLCli
|
||||||
}
|
}
|
||||||
static int Main(string[] args)
|
static int Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Do you have gimconv?
|
// 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;
|
bool Check = true;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,14 @@ namespace General
|
||||||
class Tools
|
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)
|
public static void WriteStringToStream(Stream s, String str)
|
||||||
{
|
{
|
||||||
Byte[] bytes = Encoding.UTF8.GetBytes(str);
|
Byte[] bytes = Encoding.UTF8.GetBytes(str);
|
||||||
|
@ -40,34 +48,32 @@ namespace General
|
||||||
return Bytes;
|
return Bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetFileExtension(byte[] Bytes)
|
public static string GetFileExtension(byte[] Bytes)
|
||||||
{
|
{
|
||||||
if (IsImage(Bytes))
|
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
|
||||||
{
|
{
|
||||||
using (Bitmap bmp = GetBitmap(Bytes))
|
return ".bmp";
|
||||||
{
|
}
|
||||||
if (bmp.RawFormat.Equals(ImageFormat.Jpeg))
|
else if (gif.SequenceEqual(Bytes.Take(gif.Length)))
|
||||||
return ".jpeg";
|
{
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Bmp))
|
return ".gif";
|
||||||
return ".bmp";
|
}
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Gif))
|
else if (png.SequenceEqual(Bytes.Take(png.Length)))
|
||||||
return ".gif";
|
{
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Png))
|
return ".png";
|
||||||
return ".png";
|
}
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Tiff))
|
else if (tiff.SequenceEqual(Bytes.Take(tiff.Length)))
|
||||||
return ".tiff";
|
{
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Icon))
|
return ".tiff";
|
||||||
return ".ico";
|
}
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Exif))
|
else if (tiff2.SequenceEqual(Bytes.Take(tiff2.Length)))
|
||||||
return ".exif";
|
{
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Emf))
|
return ".tiff";
|
||||||
return ".emf";
|
}
|
||||||
else if (bmp.RawFormat.Equals(ImageFormat.Wmf))
|
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
|
||||||
return ".wmf";
|
{
|
||||||
else
|
return ".jpg";
|
||||||
return ".raw";
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (IsZlib(Bytes))
|
else if (IsZlib(Bytes))
|
||||||
{
|
{
|
||||||
return ".z";
|
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)
|
public static Bitmap GetBitmap(byte[] BitmapBytes)
|
||||||
{
|
{
|
||||||
MemoryStream ms = ByteToStream(BitmapBytes);
|
MemoryStream ms = ByteToStream(BitmapBytes);
|
||||||
|
|
Loading…
Reference in New Issue