mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 01:58:40 +00:00
Add jpeg to supported filetypes
This commit is contained in:
parent
8f7d536f50
commit
cd855ba7db
2 changed files with 20 additions and 4 deletions
|
@ -26,6 +26,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
LbpFileType.Level => true,
|
LbpFileType.Level => true,
|
||||||
LbpFileType.Voice => true,
|
LbpFileType.Voice => true,
|
||||||
LbpFileType.Plan => true,
|
LbpFileType.Plan => true,
|
||||||
|
LbpFileType.Jpeg => true,
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(file), $"Unhandled file type ({file.FileType}) in FileHelper.IsFileSafe()"),
|
_ => throw new ArgumentOutOfRangeException(nameof(file), $"Unhandled file type ({file.FileType}) in FileHelper.IsFileSafe()"),
|
||||||
#else
|
#else
|
||||||
|
@ -39,9 +40,6 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
using MemoryStream ms = new(data);
|
using MemoryStream ms = new(data);
|
||||||
using BinaryReader reader = new(ms);
|
using BinaryReader reader = new(ms);
|
||||||
|
|
||||||
string footer = Encoding.ASCII.GetString(BinaryHelper.ReadLastBytes(reader, 4));
|
|
||||||
if (footer == "FARC") return LbpFileType.FileArchive;
|
|
||||||
|
|
||||||
byte[] header = reader.ReadBytes(3);
|
byte[] header = reader.ReadBytes(3);
|
||||||
|
|
||||||
return Encoding.ASCII.GetString(header) switch
|
return Encoding.ASCII.GetString(header) switch
|
||||||
|
@ -52,10 +50,27 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
"VOP" => LbpFileType.Voice,
|
"VOP" => LbpFileType.Voice,
|
||||||
"LVL" => LbpFileType.Level,
|
"LVL" => LbpFileType.Level,
|
||||||
"PLN" => LbpFileType.Plan,
|
"PLN" => LbpFileType.Plan,
|
||||||
_ => LbpFileType.Unknown,
|
_ => determineFileTypePartTwoWeirdName(reader),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LbpFileType determineFileTypePartTwoWeirdName(BinaryReader reader)
|
||||||
|
{
|
||||||
|
reader.BaseStream.Position = 0;
|
||||||
|
|
||||||
|
// Determine if file is FARC
|
||||||
|
string footer = Encoding.ASCII.GetString(BinaryHelper.ReadLastBytes(reader, 4));
|
||||||
|
if (footer == "FARC") return LbpFileType.FileArchive;
|
||||||
|
|
||||||
|
// Determine if file is JPEG
|
||||||
|
byte[] header = reader.ReadBytes(9);
|
||||||
|
|
||||||
|
if (header[0] == 0xFF && header[1] == 0xD8 && header[2] == 0xFF && header[3] == 0xE0)
|
||||||
|
return LbpFileType.Jpeg;
|
||||||
|
|
||||||
|
return LbpFileType.Unknown; // Still unknown.
|
||||||
|
}
|
||||||
|
|
||||||
public static bool ResourceExists(string hash) => File.Exists(GetResourcePath(hash));
|
public static bool ResourceExists(string hash) => File.Exists(GetResourcePath(hash));
|
||||||
|
|
||||||
public static void EnsureDirectoryCreated(string path)
|
public static void EnsureDirectoryCreated(string path)
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Files
|
||||||
Plan, // PLN, uploaded with levels
|
Plan, // PLN, uploaded with levels
|
||||||
Voice, // VOP, voice data
|
Voice, // VOP, voice data
|
||||||
Painting, // PTG, paintings
|
Painting, // PTG, paintings
|
||||||
|
Jpeg, // JFIF / FIF, used in sticker switches
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue