Code cleanup.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user