Fix config scene stuck on ruleset format error.
This commit is contained in:
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
using Logger = Cryville.Common.Logger;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class ConfigScene : MonoBehaviour {
|
public class ConfigScene : MonoBehaviour {
|
||||||
@@ -20,43 +21,48 @@ namespace Cryville.Crtr.Config {
|
|||||||
RulesetConfig _rscfg;
|
RulesetConfig _rscfg;
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
ChartPlayer.etor = new PdtEvaluator();
|
try {
|
||||||
FileInfo file = new FileInfo(
|
ChartPlayer.etor = new PdtEvaluator();
|
||||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
FileInfo file = new FileInfo(
|
||||||
);
|
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||||
if (!file.Exists) {
|
);
|
||||||
Popup.Create("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
if (!file.Exists) {
|
||||||
ReturnToMenu();
|
throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||||
return;
|
}
|
||||||
}
|
DirectoryInfo dir = file.Directory;
|
||||||
DirectoryInfo dir = file.Directory;
|
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
|
||||||
});
|
|
||||||
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
|
||||||
ruleset.LoadPdt(dir);
|
|
||||||
}
|
|
||||||
FileInfo cfgfile = new FileInfo(
|
|
||||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
|
||||||
);
|
|
||||||
if (!cfgfile.Exists) {
|
|
||||||
if (!cfgfile.Directory.Exists) cfgfile.Directory.Create();
|
|
||||||
_rscfg = new RulesetConfig();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
|
|
||||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
|
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||||
|
ruleset.LoadPdt(dir);
|
||||||
}
|
}
|
||||||
|
FileInfo cfgfile = new FileInfo(
|
||||||
|
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||||
|
);
|
||||||
|
if (!cfgfile.Exists) {
|
||||||
|
if (!cfgfile.Directory.Exists) cfgfile.Directory.Create();
|
||||||
|
_rscfg = new RulesetConfig();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
|
||||||
|
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_genericConfigPanel.Target = _rscfg.generic;
|
||||||
|
|
||||||
|
var proxy = new InputProxy(ruleset.Root, null);
|
||||||
|
proxy.LoadFrom(_rscfg.inputs);
|
||||||
|
m_inputConfigPanel.proxy = proxy;
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Popup.CreateException(ex);
|
||||||
|
Logger.Log("main", 4, "Config", "An error occured while loading the config: {0}", ex);
|
||||||
|
ReturnToMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_genericConfigPanel.Target = _rscfg.generic;
|
|
||||||
|
|
||||||
var proxy = new InputProxy(ruleset.Root, null);
|
|
||||||
proxy.LoadFrom(_rscfg.inputs);
|
|
||||||
m_inputConfigPanel.proxy = proxy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SwitchCategory(GameObject cat) {
|
public void SwitchCategory(GameObject cat) {
|
||||||
|
|||||||
Reference in New Issue
Block a user