Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
FastDebugModEntity.cs
浏览该文件的文档.
1using System.Reflection;
2using System.Xml.Linq;
3using Engine;
4using NuGet.Versioning;
5
6namespace Game {
8 public Dictionary<string, FileInfo> FModFiles = [];
9
11 modInfo = new ModInfo { Name = "[Debug]", PackageName = "debug" };
13 modInfo.LoadOrder = int.MinValue + 1;
14 }
15
16 public override void InitResources() {
18 if (!GetFile(
19 "modinfo.json",
20 stream => {
22 modInfo.Name = $"[FastDebug]{modInfo.Name}";
23 }
24 )) {
25 modInfo = new ModInfo {
26 Name = "FastDebug",
27 Version = "1.0.0",
28 NuGetVersion = new NuGetVersion(1, 0, 0),
29 ApiVersion = ModsManager.APIVersionString,
30 ApiVersionRange = new VersionRange(ModsManager.APINuGetVersion),
31 Link = "https://gitee.com/SC-SPM/SurvivalcraftApi",
32 Author = "SC-SPM",
33 Description = "Debug uncompressed mod. 调试未压缩模组",
34 ScVersion = "2.4.0.0",
35 PackageName = "fastdebug"
36 };
37 }
38 if(!GetFile("icon.webp", LoadIcon)) {
39 GetFile("icon.png", LoadIcon);
40 }
41 }
42
43 public void ReadDirResouces(string basepath, string path) {
44 if (string.IsNullOrEmpty(path)) {
45 path = basepath;
46 }
47 foreach (string d in Storage.ListDirectoryNames(path)) {
48 ReadDirResouces(basepath, $"{path}/{d}");
49 }
50 foreach (string f in Storage.ListFileNames(path)) {
51 if (f.EndsWith(".scmod")) {
52 continue;
53 }
54 string abpath = $"{path}/{f}";
55 string FilenameInZip = abpath.Substring(basepath.Length + 1);
56 if (FilenameInZip.StartsWith("Assets/")) {
57 string name = FilenameInZip.Substring(7);
58 ContentInfo contentInfo = new(name);
59 MemoryStream memoryStream = new();
60 using (Stream stream = Storage.OpenFile(abpath, OpenFileMode.Read)) {
61 stream.CopyTo(memoryStream);
62 contentInfo.SetContentStream(memoryStream);
63 ContentManager.Add(contentInfo);
64 }
65 }
66 FModFiles.Add(FilenameInZip, new FileInfo(Storage.GetSystemPath(abpath)));
67 }
68 }
69
76 public override void GetFiles(string extension, Action<string, Stream> action) {
77 bool skip = false;
78 Loader?.GetModFiles(extension, action, out skip);
79 if (skip) {
80 return;
81 }
82 foreach (KeyValuePair<string, FileInfo> item in FModFiles) {
83 if (item.Key.EndsWith(extension)) {
84 using (Stream fs = item.Value.OpenRead()) {
85 try {
86 action?.Invoke(item.Key, fs);
87 }
88 catch (Exception e) {
89 Log.Error($"GetFile {item.Key} Error:{e}");
90 }
91 }
92 }
93 }
94 }
95
96 public override bool GetFile(string filename, Action<Stream> stream) {
97 bool skip = false;
98 bool loaderReturns = false;
99 Loader?.GetModFile(filename, stream, out skip, out loaderReturns);
100 if (skip) {
101 return loaderReturns;
102 }
103 if (FModFiles.TryGetValue(filename, out FileInfo fileInfo)) {
104 using (Stream fs = fileInfo.OpenRead()) {
105 try {
106 stream?.Invoke(fs);
107 }
108 catch (Exception e) {
109 Log.Error($"GetFile {filename} Error:{e}");
110 }
111 }
112 return true;
113 }
114 return false;
115 }
116
117 public override bool GetAssetsFile(string filename, Action<Stream> stream) => GetFile($"Assets/{filename}", stream);
118 }
119}
static void Error(object message)
定义 Log.cs:80
static string GetSystemPath(string path)
static IEnumerable< string > ListDirectoryNames(string path)
static IEnumerable< string > ListFileNames(string path)
static Stream OpenFile(string path, OpenFileMode openFileMode)
void SetContentStream(Stream stream)
static void Add(ContentInfo contentInfo)
void ReadDirResouces(string basepath, string path)
override bool GetFile(string filename, Action< Stream > stream)
获取指定文件
override void InitResources()
初始化Content资源
override bool GetAssetsFile(string filename, Action< Stream > stream)
Dictionary< string, FileInfo > FModFiles
override void GetFiles(string extension, Action< string, Stream > action)
获取指定后缀文件列表,带.
virtual void LoadIcon(Stream stream)
static NuGetVersion APINuGetVersion
static ModInfo DeserializeJson(string json)
static string ModsPath
static string APIVersionString
static string StreamToString(Stream stream)