mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
make sure config is loaded
This commit is contained in:
parent
83251a8746
commit
a6b8af5cb9
3 changed files with 26 additions and 6 deletions
|
@ -80,8 +80,6 @@ namespace SanAndreasUnity.Editor
|
|||
return;
|
||||
}
|
||||
|
||||
Config.Load();
|
||||
|
||||
string selectedFolder = EditorUtility.OpenFolderPanel("Select GTA installation folder", Config.GamePath ?? "", "");
|
||||
if (string.IsNullOrWhiteSpace(selectedFolder))
|
||||
{
|
||||
|
|
|
@ -45,6 +45,8 @@ namespace SanAndreasUnity.Utilities
|
|||
}
|
||||
|
||||
|
||||
private static bool _loaded = false;
|
||||
|
||||
private static JObject _root = new JObject ();
|
||||
private static JObject _user = new JObject ();
|
||||
|
||||
|
@ -52,6 +54,11 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
|
||||
|
||||
static Config()
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
private static TVal ConvertVal<TVal>(JToken val)
|
||||
{
|
||||
// note that if you pass string[] as type, it will fail on IL2CPP
|
||||
|
@ -68,6 +75,8 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
private static TVal Get<TVal>(string key)
|
||||
{
|
||||
Load();
|
||||
|
||||
var userVal = _user[key];
|
||||
if (userVal != null)
|
||||
return ConvertVal<TVal>(userVal);
|
||||
|
@ -92,6 +101,8 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
private static string GetSubstitution(string key)
|
||||
{
|
||||
Load();
|
||||
|
||||
if (_substitutions.ContainsKey(key)) return _substitutions[key];
|
||||
|
||||
string subs;
|
||||
|
@ -112,16 +123,19 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
private static string ReplaceSubstitutions(string value)
|
||||
{
|
||||
Load();
|
||||
return _regex.Replace(value, x => GetSubstitution(x.Groups["key"].Value));
|
||||
}
|
||||
|
||||
public static string GetPath(string key)
|
||||
{
|
||||
Load();
|
||||
return ReplaceSubstitutions(GetString(key));
|
||||
}
|
||||
|
||||
public static string[] GetPaths(string key)
|
||||
{
|
||||
Load();
|
||||
return Get<JArray>(key)
|
||||
.Select(x => ReplaceSubstitutions((string)x))
|
||||
.ToArray();
|
||||
|
@ -129,11 +143,17 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
public static void SetString (string key, string value)
|
||||
{
|
||||
Load();
|
||||
_user [key] = value;
|
||||
}
|
||||
|
||||
public static void Load ()
|
||||
private static void Load ()
|
||||
{
|
||||
if (_loaded)
|
||||
return;
|
||||
|
||||
_loaded = true;
|
||||
|
||||
_root = new JObject ();
|
||||
_user = new JObject ();
|
||||
_substitutions.Clear ();
|
||||
|
@ -150,11 +170,13 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
public static void SaveUserConfig ()
|
||||
{
|
||||
Load();
|
||||
File.WriteAllText (UserConfigFilePath, _user.ToString (Newtonsoft.Json.Formatting.Indented));
|
||||
}
|
||||
|
||||
public static void SaveUserConfigSafe ()
|
||||
{
|
||||
Load();
|
||||
F.RunExceptionSafe (() => SaveUserConfig ());
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace SanAndreasUnity.Utilities
|
|||
{
|
||||
void Awake()
|
||||
{
|
||||
Config.Load();
|
||||
//Config.Load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue