mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-09-28 07:11:25 +12:00
improved filetype detection
This commit is contained in:
parent
9622cef810
commit
145c350c14
1 changed files with 4 additions and 18 deletions
|
@ -6,6 +6,7 @@ using System.Net;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using static ModAssistant.Http;
|
using static ModAssistant.Http;
|
||||||
|
|
||||||
|
@ -113,9 +114,6 @@ namespace ModAssistant.API
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
static extern int memcmp(byte[] b1, byte[] b2, long count);
|
|
||||||
|
|
||||||
public static async Task<string> InstallMap(BeatSaverApiResponseMap Map, bool showNotification = true)
|
public static async Task<string> InstallMap(BeatSaverApiResponseMap Map, bool showNotification = true)
|
||||||
{
|
{
|
||||||
string zip = Path.Combine(Utils.BeatSaberPath, CustomSongsFolder, Map.hash) + ".zip";
|
string zip = Path.Combine(Utils.BeatSaberPath, CustomSongsFolder, Map.hash) + ".zip";
|
||||||
|
@ -136,23 +134,11 @@ namespace ModAssistant.API
|
||||||
|
|
||||||
if (File.Exists(zip))
|
if (File.Exists(zip))
|
||||||
{
|
{
|
||||||
byte[] zipMagicNumber = { 80, 75, 3, 4 };
|
string mimeType = MimeMapping.GetMimeMapping(zip);
|
||||||
byte[] magicNumber = new byte[4];
|
MessageBox.Show(mimeType);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (FileStream fs = new FileStream(zip, FileMode.Open, FileAccess.Read))
|
|
||||||
{
|
|
||||||
fs.Read(magicNumber, 0, magicNumber.Length);
|
|
||||||
fs.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(magicNumber.Length == zipMagicNumber.Length && memcmp(magicNumber, zipMagicNumber, magicNumber.Length) == 0))
|
if (!mimeType.StartsWith("application/x-zip"))
|
||||||
{
|
{
|
||||||
ModAssistant.Utils.Log($"Failed extracting BeatSaver map: {zip} \n| Content: {string.Join("\n", File.ReadAllLines(zip))}", "ERROR");
|
ModAssistant.Utils.Log($"Failed extracting BeatSaver map: {zip} \n| Content: {string.Join("\n", File.ReadAllLines(zip))}", "ERROR");
|
||||||
throw new Exception("File not a zip.");
|
throw new Exception("File not a zip.");
|
||||||
|
|
Loading…
Reference in a new issue