Solidify mod from config/directory errors

This commit is contained in:
Terry Hearst 2023-09-04 00:57:33 -04:00
parent 8e92d3a0fb
commit 2ac822a487
3 changed files with 30 additions and 17 deletions

View file

@ -29,9 +29,13 @@ namespace CustomCosmeticLoader
public static void Init() public static void Init()
{ {
if (File.Exists(GetConfigPath())) bool configExists = File.Exists(GetConfigPath());
if (configExists)
ReadConfig(); ReadConfig();
else
ensureSkinSelected();
if (!configExists && enabled)
SaveConfig(); SaveConfig();
} }
@ -62,16 +66,6 @@ namespace CustomCosmeticLoader
if (data[PROPERTY_CURRENT_SKIN] != null) if (data[PROPERTY_CURRENT_SKIN] != null)
currentSkin = data[PROPERTY_CURRENT_SKIN].Value; currentSkin = data[PROPERTY_CURRENT_SKIN].Value;
if (currentSkin == null || !skins.ContainsKey(currentSkin))
{
if (skins.Count == 0)
{
Debug.LogWarning("No custom skins found, disabling");
enabled = false;
return;
}
currentSkin = skins.Keys.ToList()[0];
}
if (data[PROPERTY_SKIN_NAME_TO_HIJACK] != null) if (data[PROPERTY_SKIN_NAME_TO_HIJACK] != null)
skinNameToHijack = data[PROPERTY_SKIN_NAME_TO_HIJACK].Value; skinNameToHijack = data[PROPERTY_SKIN_NAME_TO_HIJACK].Value;
@ -96,5 +90,19 @@ namespace CustomCosmeticLoader
File.WriteAllText(GetConfigPath(), node.ToString()); File.WriteAllText(GetConfigPath(), node.ToString());
} }
public static void ensureSkinSelected()
{
if (currentSkin == null || !skins.ContainsKey(currentSkin))
{
if (skins.Count == 0)
{
Debug.LogWarning("No custom skins found, disabling");
enabled = false;
return;
}
currentSkin = skins.Keys.ToList()[0];
}
}
} }
} }

View file

@ -32,6 +32,11 @@ namespace CustomCosmeticLoader
{ {
string skinsPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string skinsPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
skinsPath = Path.Combine(skinsPath, "skins"); skinsPath = Path.Combine(skinsPath, "skins");
if (!Directory.Exists(skinsPath))
{
Debug.Log(skinsPath + " directory does not exist, no skins to load");
return;
}
string printStr = "Loaded custom skins: "; string printStr = "Loaded custom skins: ";
foreach (string skinFile in Directory.GetFiles(skinsPath)) foreach (string skinFile in Directory.GetFiles(skinsPath))
{ {

View file

@ -6,21 +6,21 @@ namespace CustomCosmeticLoader
public static class Shared public static class Shared
{ {
private static Cosmetic skinToHijack; private static Cosmetic skinToHijack;
private static bool noSkinToHijack = false;
public static Cosmetic SkinToHijack public static Cosmetic SkinToHijack
{ {
get get
{ {
if (noSkinToHijack)
return null;
if (skinToHijack == null) if (skinToHijack == null)
{ {
DetermineSkinToHijack(); DetermineSkinToHijack();
if (skinToHijack == null) if (skinToHijack == null)
Debug.LogWarning("Couldn't hijack skin " + Config.skinNameToHijack); {
Debug.LogWarning("Couldn't find skin " + Config.skinNameToHijack + " to hijack");
Config.skinNameToHijack = "Swirl_M";
DetermineSkinToHijack();
}
} }
return skinToHijack; return skinToHijack;
} }
} }