This commit is contained in:
CroakFang
2023-03-29 15:31:48 +08:00
parent 1479d0b6ac
commit f342c77c60
8 changed files with 625 additions and 157 deletions
+2 -2
View File
@@ -36,7 +36,7 @@ public class Config
}
catch (Exception ex)
{
UmaViewerUI.Instance.ShowMessage("Config load error. Using default. " + ex.Message);
UmaViewerUI.Instance.ShowMessage("Config load error. Using default. " + ex.Message, UIMessageType.Error);
MainPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume";
}
}
@@ -47,7 +47,7 @@ public class Config
public void UpdateConfig()
{
File.WriteAllText(configPath, JsonUtility.ToJson(this, true));
UmaViewerUI.Instance.ShowMessage("The configuration has changed. Please restart the application.");
UmaViewerUI.Instance.ShowMessage("The configuration has changed. Please restart the application.", UIMessageType.Default);
}
}
+36 -21
View File
@@ -13,8 +13,8 @@ public class ManifestDB
{
public SqliteConnection MetaDB;
public static string DBPath;
public Action<string> callback;
public Action<string, UIMessageType> callback;
private bool isError;
public ManifestDB()
{
string DBPath = $"{Config.Instance.MainPath}\\meta_umaviewer";
@@ -51,13 +51,14 @@ public class ManifestDB
}
}
public IEnumerator UpdateResourceVersion(Action<string> callback)
public IEnumerator UpdateResourceVersion(Action<string, UIMessageType> callback)
{
isError = false;
this.callback = callback;
callback?.Invoke("Checking Resource Version");
callback?.Invoke("Checking Resource Version", UIMessageType.Default);
yield return UpdateMetaDB();
yield return UpdateMasterDB();
callback?.Invoke($"Done. Please restart the application.");
callback?.Invoke(isError ? "Update aborted." : $"Done. Please restart the application.", isError ? UIMessageType.Error : UIMessageType.Success);
}
//umamusume uses the manifest file to generate meta database.
@@ -68,7 +69,7 @@ public class ManifestDB
public IEnumerator UpdateMetaDB()
{
string rootHash = null;
callback?.Invoke("Getting resource version");
callback?.Invoke("Getting resource version", UIMessageType.Default);
yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/MetaC/root", txt =>
{
if (string.IsNullOrEmpty(txt)) return;
@@ -81,7 +82,9 @@ public class ManifestDB
if (rootHash == null)
{
callback?.Invoke("Get RootHash Error", UIMessageType.Error);
Debug.LogError("Get RootHash Error");
isError = true;
yield break;
}
@@ -99,7 +102,7 @@ public class ManifestDB
public IEnumerator UpdateMetaDB(ManifestEntry rootEntry)
{
if (MetaDB == null || MetaDB.State == System.Data.ConnectionState.Closed)
if (MetaDB == null || MetaDB.State != System.Data.ConnectionState.Open)
{
Debug.LogError("Open Meta Database Error");
yield break;
@@ -112,12 +115,13 @@ public class ManifestDB
UpdateManifestEntry(index, "manifest3", rootEntry, ref command);
//Insert platform
callback?.Invoke("Reading Platform Manifest");
callback?.Invoke("Reading Platform Manifest", UIMessageType.Default);
ManifestEntry[] platformEntrys = null;
yield return GetManifest(rootEntry.hname, Kind.PlatformManifest, entrys => { platformEntrys = entrys; });
if (platformEntrys == null)
{
Debug.LogError("Read PlatformManifest Error");
isError = true;
MetaDB.Close();
yield break;
}
@@ -126,11 +130,13 @@ public class ManifestDB
UpdateManifestEntry(index, "manifest2", platformEntry, ref command);
//Insert AssetManifest
callback?.Invoke($"Reading Assets Manifest", UIMessageType.Default);
ManifestEntry[] assetEntrys = null;
yield return GetManifest(platformEntry.hname, Kind.AssetManifest, entrys => { assetEntrys = entrys; });
if (assetEntrys == null)
{
Debug.LogError("Read AssetManifest Error");
isError = true;
MetaDB.Close();
yield break;
}
@@ -139,7 +145,6 @@ public class ManifestDB
for (int i = 0; i < assetEntrys.Length; i++)
{
index++;
callback?.Invoke($"Reading Assets Manifest : {assetEntrys[i].tname} ({i + 1}/{assetEntrys.Length})");
UpdateManifestEntry(index, "manifest", assetEntrys[i], ref command);
}
tran.Commit();
@@ -153,13 +158,14 @@ public class ManifestDB
if (assets == null)
{
Debug.LogError("Read AssetManifest Error");
isError = true;
continue;
}
callback?.Invoke($"Reading AssetBundles Manifest : {assetEntry.tname}", UIMessageType.Default);
using SqliteTransaction tran = MetaDB.BeginTransaction();
for (int i = 0; i < assets.Length; i++)
{
index++;
callback?.Invoke($"Reading AssetBundles Manifest : {assetEntry.tname} ({i + 1}/{assets.Length})");
UpdateManifestEntry(index, assetEntry.tname, assets[i], ref command);
}
tran.Commit();
@@ -168,13 +174,17 @@ public class ManifestDB
public IEnumerator UpdateMasterDB()
{
if (MetaDB == null || MetaDB.State == System.Data.ConnectionState.Closed)
if (MetaDB == null || MetaDB.State != System.Data.ConnectionState.Open)
{
Debug.LogError("Open Meta Database Error");
isError = true;
yield break;
}
callback?.Invoke($"Checking master.mdb");
var masterPath = $"{Path.GetDirectoryName(DBPath)}\\master\\master_umaviewer.mdb";
var masterDir = Path.GetDirectoryName(masterPath);
callback?.Invoke($"Checking master.mdb", UIMessageType.Default);
SqliteCommand command = new SqliteCommand("SELECT h FROM a WHERE n LIKE 'master.mdb.lz4'", MetaDB);
var reader = command.ExecuteReader();
@@ -184,7 +194,7 @@ public class ManifestDB
var path = GetManifestPath(hash);
if (!File.Exists(path))
{
callback?.Invoke($"Downloading master.mdb");
callback?.Invoke($"Downloading master.mdb", UIMessageType.Default);
UnityWebRequest www = UnityWebRequest.Get(UmaViewerDownload.GetGenericRequestUrl(hash));
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.Success)
@@ -194,20 +204,24 @@ public class ManifestDB
else
{
Debug.LogError("Download Master.mdb Failed :" + www.error);
callback?.Invoke("Download Master.mdb Failed :" + www.error, UIMessageType.Error);
isError = true;
yield break;
}
}
callback?.Invoke($"Decompress master.mdb");
var masterPath = $"{Path.GetDirectoryName(DBPath)}/master/master_umaviewer.mdb";
Directory.CreateDirectory(Path.GetDirectoryName(masterPath));
callback?.Invoke($"Decompress master.mdb", UIMessageType.Default);
try
{
File.WriteAllBytes(masterPath, LZ4Util.DecompressFromFile(path));
Directory.CreateDirectory(masterDir);
var bytes = LZ4Util.DecompressFromFile(path);
File.WriteAllBytes(masterPath, bytes);
}
catch
catch (Exception e)
{
callback?.Invoke($"Decompress master.mdb error");
Debug.LogError($"Decompress master.mdb Error: {e.Message}");
callback?.Invoke($"Decompress master.mdb Error", UIMessageType.Error);
isError = true;
yield break;
}
}
@@ -268,7 +282,7 @@ public class ManifestDB
var path = GetManifestPath(hash);
if (!File.Exists(path))
{
this.callback?.Invoke($"Downloading Manifest :{hash}");
this.callback?.Invoke($"Downloading Manifest :{hash}", UIMessageType.Default);
yield return DownloadManifest(hash);
}
if (File.Exists(path))
@@ -289,7 +303,8 @@ public class ManifestDB
else
{
Debug.LogError("Download Manifest Failed :" + www.error);
callback?.Invoke($"Download Manifest Failed :{www.error},Update aborted");
callback?.Invoke($"Download Manifest Failed :{www.error}", UIMessageType.Error);
isError = true;
yield break;
}
}
+10 -2
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using Gallop;
using System.IO;
using static UmaViewerUI;
public class UmaDatabaseEntry
{
@@ -28,9 +29,9 @@ public class UmaDatabaseEntry
public static void DownloadAsset(UmaDatabaseEntry entry)
{
var path = $"{Config.Instance.MainPath}\\dat\\{entry.Url.Substring(0, 2)}\\{entry.Url}";
UmaViewerDownload.DownloadAssetSync(entry, path , delegate(string msg)
UmaViewerDownload.DownloadAssetSync(entry, path , delegate(string msg, UIMessageType type)
{
UmaViewerUI.Instance.ShowMessage(msg);
Instance.ShowMessage(msg, type);
});
}
@@ -132,6 +133,13 @@ public class CostumeEntry
public Sprite Icon;
}
public enum UIMessageType
{
Default,
Warning,
Error,
Success
}
public enum UmaFileType
{
_3d_cutt,
@@ -92,7 +92,7 @@ public class UmaDatabaseController
{
msg += "\nPlease install the dmm game client";
}
UmaViewerUI.Instance.ShowMessage(msg);
UmaViewerUI.Instance.ShowMessage(msg, UIMessageType.Error);
}
}
@@ -131,7 +131,6 @@ public class UmaDatabaseController
return ReadMaster(conn, "SELECT * FROM mob_data");
}
static IEnumerable<DataRow> ReadMaster(SqliteConnection conn,string sql)
{
SqliteCommand sqlite_cmd = conn.CreateCommand();
@@ -144,6 +143,7 @@ public class UmaDatabaseController
{
yield return (DataRow)temp.Current;
}
sqlite_cmd.Dispose();
}
static IEnumerable<FaceTypeData> ReadFaceTypeData(SqliteConnection conn)
@@ -191,7 +191,6 @@ public class UmaDatabaseController
return null;
}
public static DataRow ReadMobDressColor(string mobid)
{
var results= ReadMaster(instance.masterDb, $"SELECT * FROM mob_dress_color_set WHERE id LIKE {mobid}");
@@ -216,6 +215,11 @@ public class UmaDatabaseController
{
masterDb.Close();
metaDb.Close();
masterDb.Dispose();
metaDb.Dispose();
SqliteConnection.ClearAllPools();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
+11 -8
View File
@@ -1744,16 +1744,19 @@ public class UmaViewerBuilder : MonoBehaviour
{
string value = $"chara/chr{id}/chr_icon_{id}";
var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value));
string path = entry.FilePath;
if (File.Exists(path))
if (entry != null)
{
AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
if (assetBundle.Contains($"chr_icon_{id}"))
string path = entry.FilePath;
if (File.Exists(path))
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"chr_icon_{id}");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
if (assetBundle.Contains($"chr_icon_{id}"))
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"chr_icon_{id}");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
}
}
}
return null;
+5 -7
View File
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using static UmaViewerUI;
public class UmaViewerDownload : MonoBehaviour
{
@@ -28,13 +29,10 @@ public class UmaViewerDownload : MonoBehaviour
}
}
public static void DownloadAssetSync(UmaDatabaseEntry entry,string path, Action<string> callback = null)
public static void DownloadAssetSync(UmaDatabaseEntry entry,string path, Action<string , UIMessageType> callback = null)
{
string baseurl = GetAssetRequestUrl(entry.Url);
if (!string.IsNullOrEmpty(Path.GetExtension(entry.Name)))
{
baseurl = GetGenericRequestUrl(entry.Url);
}
callback?.Invoke($"Downloading AssetBundle: {Path.GetFileName(entry.Name)}", UIMessageType.Default);
string baseurl = (string.IsNullOrEmpty(Path.GetExtension(entry.Name)) ? GetAssetRequestUrl(entry.Url) : GetGenericRequestUrl(entry.Url));
using UnityWebRequest www = UnityWebRequest.Get(baseurl);
www.SendWebRequest();
@@ -42,7 +40,7 @@ public class UmaViewerDownload : MonoBehaviour
if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError(www.error);
callback?.Invoke($"Failed to download resources : {www.error}");
callback?.Invoke($"Failed to download resources : {www.error}", UIMessageType.Error);
}
else
{
+13 -6
View File
@@ -9,6 +9,7 @@ using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Debug = UnityEngine.Debug;
public class UmaViewerUI : MonoBehaviour
{
@@ -40,7 +41,7 @@ public class UmaViewerUI : MonoBehaviour
public PageManager PropPageCtrl;
public ScrollRect SceneList;
public PageManager ScenePageCtrl;
public GameObject MessagePannel;
public ScrollRect MessageScrollRect;
public Text MessageText;
[Header("lists")]
@@ -1221,7 +1222,7 @@ public class UmaViewerUI : MonoBehaviour
if (UpdateResVerCoroutine != null && Config.Instance.WorkMode != WorkMode.Standalone) return;
UmaDatabaseController.Instance.CloseAllConnection();
ManifestDB dB = new ManifestDB();
UpdateResVerCoroutine = dB.UpdateResourceVersion(delegate (string msg) { ShowMessage(msg); });
UpdateResVerCoroutine = dB.UpdateResourceVersion(delegate (string msg, UIMessageType type) { ShowMessage(msg,type); });
StartCoroutine(UpdateResVerCoroutine);
}
@@ -1261,10 +1262,16 @@ public class UmaViewerUI : MonoBehaviour
Shader.SetGlobalFloat("_GlobalOutlineWidth", val);
}
public void ShowMessage(string msg)
public void ShowMessage(string msg, UIMessageType type)
{
MessagePannel.SetActive(true);
MessageText.text = msg;
MessageText.text += type switch
{
UIMessageType.Error => string.Format("<color=red>{0}</color>\n", msg),
UIMessageType.Warning => string.Format("<color=yellow>{0}</color>\n", msg),
UIMessageType.Success => string.Format("<color=green>{0}</color>\n", msg),
_ => $"{msg}\n",
};
MessageScrollRect.gameObject.SetActive(true);
MessageScrollRect.verticalNormalizedPosition = 0;
}
}