Fix skin resource import destination path.

This commit is contained in:
2022-11-18 11:08:22 +08:00
parent b954dda676
commit 78bb820f9e
2 changed files with 16 additions and 24 deletions

View File

@@ -162,7 +162,7 @@ namespace Cryville.Crtr.Browsing {
else if (res is RulesetResource) else if (res is RulesetResource)
dest = new DirectoryInfo(_rootPath + "/rulesets/" + res.Name); dest = new DirectoryInfo(_rootPath + "/rulesets/" + res.Name);
else if (res is SkinResource) else if (res is SkinResource)
dest = new DirectoryInfo(_rootPath + "/skins/" + res.Name); dest = new DirectoryInfo(_rootPath + "/skins/" + (res as SkinResource).RulesetName + "/" + res.Name);
else if (res is SongResource) else if (res is SongResource)
dest = new DirectoryInfo(_rootPath + "/songs/" + res.Name); dest = new DirectoryInfo(_rootPath + "/songs/" + res.Name);
else { else {

View File

@@ -1,6 +1,7 @@
using Cryville.Common; using Cryville.Common;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing {
@@ -27,12 +28,12 @@ namespace Cryville.Crtr.Browsing {
public override bool Valid { get { return true; } } public override bool Valid { get { return true; } }
} }
public abstract class FileResource : Resource { public abstract class FileResource : Resource {
public FileResource(string name, FileInfo master, FileInfo[] attachments) : base(name) { public FileResource(string name, FileInfo master) : base(name) {
Master = master; Master = master;
Attachments = attachments; Attachments = new List<FileInfo>();
} }
public FileInfo Master { get; private set; } public FileInfo Master { get; private set; }
public FileInfo[] Attachments { get; private set; } public List<FileInfo> Attachments { get; private set; }
public override bool Valid { public override bool Valid {
get { get {
if (!Master.Exists) return false; if (!Master.Exists) return false;
@@ -44,44 +45,35 @@ namespace Cryville.Crtr.Browsing {
} }
} }
public class ChartResource : FileResource { public class ChartResource : FileResource {
public ChartResource(string name, FileInfo master) : base(name, master, GetAttachments(master)) { } public ChartResource(string name, FileInfo master) : base(name, master) {
static FileInfo[] GetAttachments(FileInfo master) {
using (var reader = new StreamReader(master.FullName)) { using (var reader = new StreamReader(master.FullName)) {
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd()); var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
var result = new List<FileInfo> { Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")), if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
};
if (meta.cover != null) result.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
return result.ToArray();
} }
} }
} }
public class SongResource : FileResource { public class SongResource : FileResource {
public SongResource(string name, FileInfo master) : base(name, master, new FileInfo[0]) { } public SongResource(string name, FileInfo master) : base(name, master) { }
} }
public class RulesetResource : FileResource { public class RulesetResource : FileResource {
public RulesetResource(string name, FileInfo master) : base(name, master, GetAttachments(master)) { } public RulesetResource(string name, FileInfo master) : base(name, master) {
static FileInfo[] GetAttachments(FileInfo master) {
using (var reader = new StreamReader(master.FullName)) { using (var reader = new StreamReader(master.FullName)) {
var meta = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd()); var meta = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
return new FileInfo[] { Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")),
};
} }
} }
} }
public class SkinResource : FileResource { public class SkinResource : FileResource {
public SkinResource(string name, FileInfo master) : base(name, master, GetAttachments(master)) { } public string RulesetName { get; private set; }
static FileInfo[] GetAttachments(FileInfo master) { public SkinResource(string name, FileInfo master) : base(name, master) {
using (var reader = new StreamReader(master.FullName)) { using (var reader = new StreamReader(master.FullName)) {
var meta = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd()); var meta = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
var result = new List<FileInfo> { RulesetName = meta.ruleset;
new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")), Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
};
foreach (var frame in meta.frames) { foreach (var frame in meta.frames) {
result.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame))); Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
} }
return result.ToArray();
} }
} }
} }