mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-01 09:48:37 +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.Voice => true,
|
||||
LbpFileType.Plan => true,
|
||||
LbpFileType.Jpeg => true,
|
||||
#if DEBUG
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(file), $"Unhandled file type ({file.FileType}) in FileHelper.IsFileSafe()"),
|
||||
#else
|
||||
|
@ -39,9 +40,6 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
using MemoryStream ms = new(data);
|
||||
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);
|
||||
|
||||
return Encoding.ASCII.GetString(header) switch
|
||||
|
@ -52,10 +50,27 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
"VOP" => LbpFileType.Voice,
|
||||
"LVL" => LbpFileType.Level,
|
||||
"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 void EnsureDirectoryCreated(string path)
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Files
|
|||
Plan, // PLN, uploaded with levels
|
||||
Voice, // VOP, voice data
|
||||
Painting, // PTG, paintings
|
||||
Jpeg, // JFIF / FIF, used in sticker switches
|
||||
Unknown,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue