Fix resource import interrupted when item not valid.

This commit is contained in:
2022-11-15 09:15:53 +08:00
parent 975b48e61e
commit 74b1a5485b
2 changed files with 13 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Logger = Cryville.Common.Logger;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing {
internal class LegacyResourceManager : IResourceManager<ChartDetail> { internal class LegacyResourceManager : IResourceManager<ChartDetail> {
@@ -117,7 +118,10 @@ namespace Cryville.Crtr.Browsing {
foreach (var converter in converters[file.Extension]) { foreach (var converter in converters[file.Extension]) {
var resources = converter.ConvertFrom(file); var resources = converter.ConvertFrom(file);
foreach (var res in resources) { foreach (var res in resources) {
if (res is ChartResource) { if (!res.Valid) {
Logger.Log("main", 3, "Resource", "Attempt to import invalid resource {0}", res);
}
else if (res is ChartResource) {
var tres = (ChartResource)res; var tres = (ChartResource)res;
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name); var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
if (!dir.Exists) dir.Create(); if (!dir.Exists) dir.Create();
@@ -134,6 +138,7 @@ namespace Cryville.Crtr.Browsing {
if (!dir.Exists) dir.Create(); if (!dir.Exists) dir.Create();
var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/cover" + tres.Source.Extension); var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/cover" + tres.Source.Extension);
if (!dest.Exists) tres.Source.CopyTo(dest.FullName); if (!dest.Exists) tres.Source.CopyTo(dest.FullName);
} }
else if (res is SongResource) { else if (res is SongResource) {
var tres = (SongResource)res; var tres = (SongResource)res;

View File

@@ -12,6 +12,10 @@ namespace Cryville.Crtr.Browsing {
Name = StringUtils.EscapeFileName(name); Name = StringUtils.EscapeFileName(name);
} }
public string Name { get; private set; } public string Name { get; private set; }
public abstract bool Valid { get; }
public override string ToString() {
return string.Format("{0} ({1})", Name, ReflectionHelper.GetSimpleName(GetType()));
}
} }
public class ChartResource : Resource { public class ChartResource : Resource {
public ChartResource(string name, Chart main, ChartMeta meta) : base(name) { public ChartResource(string name, Chart main, ChartMeta meta) : base(name) {
@@ -19,17 +23,20 @@ namespace Cryville.Crtr.Browsing {
} }
public Chart Main { get; private set; } public Chart Main { get; private set; }
public ChartMeta Meta { get; private set; } public ChartMeta Meta { get; private set; }
public override bool Valid { get { return true; } }
} }
public class CoverResource : Resource { public class CoverResource : Resource {
public CoverResource(string name, FileInfo src) : base(name) { public CoverResource(string name, FileInfo src) : base(name) {
Source = src; Source = src;
} }
public FileInfo Source { get; private set; } public FileInfo Source { get; private set; }
public override bool Valid { get { return Source.Exists; } }
} }
public class SongResource : Resource { public class SongResource : Resource {
public SongResource(string name, FileInfo src) : base(name) { public SongResource(string name, FileInfo src) : base(name) {
Source = src; Source = src;
} }
public FileInfo Source { get; private set; } public FileInfo Source { get; private set; }
public override bool Valid { get { return Source.Exists; } }
} }
} }