Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make extensions case insensitive for type guessing and texture reloading #676

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Celeste.Mod.mm/Mod/Entities/CustomHeightDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CustomHeightDisplay(string dialog, int target, int from = 0, bool progres
Target = target;
Approach = from;

int idx = Text.IndexOf("{x}", StringComparison.InvariantCultureIgnoreCase);
int idx = Text.IndexOf("{x}", StringComparison.OrdinalIgnoreCase);
if (idx != -1) {
hasCount = true;
displaySound = SFX.game_07_altitudecount;
Expand Down
36 changes: 21 additions & 15 deletions Celeste.Mod.mm/Mod/Everest/Everest.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace Celeste.Mod {

/// <summary>
/// Special meta type for assets.
/// Special meta type for assets.
/// A ModAsset with a Type field that subclasses from this will not log path conflicts.
/// </summary>
public abstract class AssetTypeNonConflict { }
Expand Down Expand Up @@ -632,7 +632,7 @@ public static bool TryAdd(string path, ModAsset metadata) {
if (pathSplit[i].StartsWith(".") || BlacklistFolders.Contains(pathSplit[i]) || (i == 0 && BlacklistRootFolders.Contains(pathSplit[0])))
return false;
}

if (metadata != null &&
(metadata.Source?.Ignore?.IsIgnored(path, metadata.Type == typeof(AssetTypeDirectory)) ?? false)) {
return false;
Expand Down Expand Up @@ -709,25 +709,33 @@ public static bool TryAdd(string path, ModAsset metadata) {
public static void Add(string path, ModAsset metadata)
=> TryAdd(path, metadata);

private static readonly string[] METADATA_YAML_NAMES = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata.yaml and multimetadata.yaml are no longer supported, I just forgot to remove them from the type guesser apparently

"metadata", "multimetadata", "everest"
};

private static readonly string[] SPRITEBANK_XML_NAMES = {
"Graphics/Sprites", "Graphics/SpritesGui", "Graphics/Portraits"
};

/// <summary>
/// Invoked when GuessType can't guess the asset type.
/// Subscribe to this event to register your own custom types.
/// </summary>
public static event TypeGuesser OnGuessType;
/// <summary>
/// Guess the file type and format based on its path.
/// Guess the file type and format based on its path.
/// </summary>
/// <param name="file">The relative asset path.</param>
/// <param name="type">The file type.</param>
/// <param name="format">The file format (file ending).</param>
/// <returns>The passed asset path, trimmed if required.</returns>
public static string GuessType(string file, out Type type, out string format) {
type = typeof(object);
format = Path.GetExtension(file) ?? "";
format = Path.GetExtension(file).ToLowerInvariant() ?? "";
if (format.Length >= 1)
format = format.Substring(1);

// Assign game asset types
// Assign game asset types
if (format == "dll") {
type = typeof(AssetTypeAssembly);

Expand All @@ -739,30 +747,31 @@ public static string GuessType(string file, out Type type, out string format) {
type = typeof(ObjModel);
file = file.Substring(0, file.Length - 4);

} else if (file.EndsWith(".obj.export")) {
} else if (file.EndsWith(".obj.export", StringComparison.OrdinalIgnoreCase)) {
type = typeof(AssetTypeObjModelExport);
file = file.Substring(0, file.Length - 7);

} else if (file == "metadata.yaml" || file == "multimetadata.yaml" || file == "everest.yaml" || file == "everest.yml") {
} else if ((format == "yaml" || format == "yml") && METADATA_YAML_NAMES.Contains(file.Substring(0, file.Length - format.Length - 1))) {
type = typeof(AssetTypeMetadataYaml);
file = file.Substring(0, file.Length - format.Length - 1);
format = "yml";

} else if (file == "DecalRegistry.xml") {
} else if (format == "xml" && file.Substring(0, file.Length - 4) == "DecalRegistry") {
type = typeof(AssetTypeDecalRegistry);
file = file.Substring(0, file.Length - 4);

} else if (file == "Graphics/Sprites.xml" || file == "Graphics/SpritesGui.xml" || file == "Graphics/Portraits.xml") {
} else if (format == "xml" && SPRITEBANK_XML_NAMES.Contains(file.Substring(0, file.Length - 4))) {
type = typeof(AssetTypeSpriteBank);
file = file.Substring(0, file.Length - 4);

} else if (file.StartsWith("Dialog/")) {
if (format == "txt") {
type = typeof(AssetTypeDialog);
file = file.Substring(0, file.Length - 4);
} else if (file.EndsWith(".txt.export")) {
} else if (file.EndsWith(".txt.export", StringComparison.OrdinalIgnoreCase)) {
type = typeof(AssetTypeDialogExport);
file = file.Substring(0, file.Length - 7);
file = file.Substring(0, file.Length - 7 - 4);
file += ".txt";
} else if (format == "fnt") {
type = typeof(AssetTypeFont);
file = file.Substring(0, file.Length - 4);
Expand All @@ -780,10 +789,7 @@ public static string GuessType(string file, out Type type, out string format) {
if (format == "bank") {
type = typeof(AssetTypeBank);
file = file.Substring(0, file.Length - 5);
} else if (file.EndsWith(".guids.txt")) {
type = typeof(AssetTypeGUIDs);
file = file.Substring(0, file.Length - 4);
} else if (file.EndsWith(".GUIDs.txt")) { // Default FMOD casing
} else if (file.EndsWith(".guids.txt", StringComparison.OrdinalIgnoreCase)) {
type = typeof(AssetTypeGUIDs);
file = file.Substring(0, file.Length - 4 - 6);
file += ".guids";
Expand Down
8 changes: 4 additions & 4 deletions Celeste.Mod.mm/Patches/Monocle/VirtualTexture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS0626 // Method, operator, or accessor is marked external and has no attributes on it
#pragma warning disable CS0626 // Method, operator, or accessor is marked external and has no attributes on it
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value null

// #define FTL_DEBUG
Expand Down Expand Up @@ -603,7 +603,7 @@ internal override unsafe void Reload() {
byte[] buffer = null;
IntPtr bufferPtr = IntPtr.Zero;
bool bufferStolen = false;
switch (System.IO.Path.GetExtension(Path)) {
switch (System.IO.Path.GetExtension(Path).ToLowerInvariant()) {
case ".data":
using (FileStream stream = File.OpenRead(System.IO.Path.Combine(Engine.ContentDirectory, Path))) {
// Vanilla has got a static readonly byte[] bytes of fixed length - currently 524288
Expand Down Expand Up @@ -783,7 +783,7 @@ internal override unsafe void Reload() {
private bool CanPreload {
get {
if (!string.IsNullOrEmpty(Path)) {
string extension = System.IO.Path.GetExtension(Path);
string extension = System.IO.Path.GetExtension(Path).ToLowerInvariant();
if (extension == ".data") {
return true;
} else if (extension == ".png") {
Expand Down Expand Up @@ -813,7 +813,7 @@ private bool Preload(bool force = false) {
// Preload the width / height, and if needed, the entire texture.

if (!string.IsNullOrEmpty(Path)) {
string extension = System.IO.Path.GetExtension(Path);
string extension = System.IO.Path.GetExtension(Path).ToLowerInvariant();
if (extension == ".data") {
// Easy.
using (FileStream stream = File.OpenRead(System.IO.Path.Combine(Engine.ContentDirectory, Path)))
Expand Down