From 777b7d9c349e1ad0ec5596581e2b7eec787c6e4a Mon Sep 17 00:00:00 2001 From: PopSlime Date: Thu, 17 Nov 2022 17:21:59 +0800 Subject: [PATCH] Code cleanup. --- .../Crtr/Browsing/LegacyResourceManager.cs | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/Assets/Cryville/Crtr/Browsing/LegacyResourceManager.cs b/Assets/Cryville/Crtr/Browsing/LegacyResourceManager.cs index 2baf3c6..ef682c0 100644 --- a/Assets/Cryville/Crtr/Browsing/LegacyResourceManager.cs +++ b/Assets/Cryville/Crtr/Browsing/LegacyResourceManager.cs @@ -126,12 +126,12 @@ namespace Cryville.Crtr.Browsing { resources = converter.ConvertFrom(file); } catch (Exception ex) { - Popup.Create(ex.Message); + LogAndPopup(4, ex.Message); return false; } foreach (var res in resources) { if (!res.Valid) { - Logger.Log("main", 3, "Resource", "Attempt to import invalid resource {0}", res); + LogAndPopup(3, "Attempt to import invalid resource: {0}", res); } else if (res is RawChartResource) { var tres = (RawChartResource)res; @@ -144,20 +144,27 @@ namespace Cryville.Crtr.Browsing { writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings)); } } - else if (res is CoverResource) { - var tres = (CoverResource)res; - var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name); - if (!dir.Exists) dir.Create(); - var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/" + tres.Source.Name); - if (!dest.Exists) tres.Source.CopyTo(dest.FullName); - + else if (res is FileResource) { + var tres = (FileResource)res; + FileInfo dest; + // TODO chart, ruleset, skin + if (res is CoverResource) + dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/" + tres.Source.Name); + else if (res is SongResource) + dest = new FileInfo(_rootPath + "/songs/" + res.Name + "/" + tres.Source.Extension); + else { + LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res); + continue; + } + var dir = dest.Directory; + if (!dest.Exists) { + if (!dir.Exists) dir.Create(); + tres.Source.CopyTo(dest.FullName); + } + else LogAndPopup(1, "Resource already exists: {0}", res); } - else if (res is SongResource) { - var tres = (SongResource)res; - var dir = new DirectoryInfo(_rootPath + "/songs/" + res.Name); - if (!dir.Exists) dir.Create(); - var dest = new FileInfo(_rootPath + "/songs/" + res.Name + "/" + tres.Source.Extension); - if (!dest.Exists) tres.Source.CopyTo(dest.FullName); + else { + LogAndPopup(3, "Attempt to import unsupported resource: {0}", res); } } return true; @@ -165,6 +172,12 @@ namespace Cryville.Crtr.Browsing { return false; } + void LogAndPopup(int level, string format, params object[] args) { + var msg = string.Format(format, args); + Logger.Log("main", level, "Resource", msg); + Popup.Create(msg); + } + public string[] GetSupportedFormats() { return converters.Keys.ToArray(); }