forked from akanyan/mu3-mods
feat: various enhancements
* AttractVideoPlayer,LoadBoost: allow setting a cache directory * AttractVideoPlayer: color leds * BetterGiveUp: prevent multiple restarts in a row * use GetTriggerOn in general where applicable
This commit is contained in:
@ -4,40 +4,46 @@ using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace MU3.Data;
|
||||
|
||||
public class DataStudioManager {
|
||||
public class patch_DataStudioManager: DataStudioManager {
|
||||
public static bool needSave;
|
||||
|
||||
private static string _fileName;
|
||||
private static Dictionary<string, object> _dataCache;
|
||||
|
||||
private static extern bool orig_Deserialize<T>(string filePath, out T dsr) where T : new();
|
||||
|
||||
private static void InitCache() {
|
||||
if(File.Exists("data_cache.bin")) {
|
||||
System.Console.WriteLine("Loading cache...");
|
||||
using FileStream serializationStream = File.OpenRead("data_cache.bin");
|
||||
private static void initCache() {
|
||||
using IniFile iniFile = new("mu3.ini");
|
||||
_fileName = Path.Combine(iniFile.getValue("Extra", "CacheDir", "."), "data_cache.bin");
|
||||
|
||||
if(File.Exists(_fileName)) {
|
||||
System.Console.WriteLine("Loading data cache...");
|
||||
using FileStream serializationStream = File.OpenRead(_fileName);
|
||||
_dataCache = (Dictionary<string, object>)new BinaryFormatter().Deserialize(serializationStream);
|
||||
return;
|
||||
}
|
||||
_dataCache = new Dictionary<string, object>();
|
||||
_dataCache = new();
|
||||
}
|
||||
|
||||
private static void SaveCache() {
|
||||
if(File.Exists("data_cache.bin")) {
|
||||
File.Delete("data_cache.bin");
|
||||
private static void saveCache() {
|
||||
if(_fileName == "") {
|
||||
return;
|
||||
}
|
||||
using FileStream serializationStream = File.OpenWrite("data_cache.bin");
|
||||
if(File.Exists(_fileName)) {
|
||||
File.Delete(_fileName);
|
||||
}
|
||||
using FileStream serializationStream = File.OpenWrite(_fileName);
|
||||
new BinaryFormatter().Serialize(serializationStream, _dataCache);
|
||||
}
|
||||
|
||||
private static bool Deserialize<T>(string filePath, out T dsr) where T : new() {
|
||||
if(_dataCache == null) {
|
||||
InitCache();
|
||||
initCache();
|
||||
}
|
||||
if(_dataCache.ContainsKey(filePath)) {
|
||||
dsr = (T)_dataCache[filePath];
|
||||
return true;
|
||||
}
|
||||
if(orig_Deserialize<T>(filePath, out dsr)) {
|
||||
if(orig_Deserialize(filePath, out dsr)) {
|
||||
needSave = true;
|
||||
_dataCache.Add(filePath, dsr);
|
||||
return true;
|
||||
@ -47,11 +53,11 @@ public class DataStudioManager {
|
||||
|
||||
public extern bool orig_IsLoaded();
|
||||
|
||||
public bool IsLoaded() {
|
||||
public new bool IsLoaded() {
|
||||
if(orig_IsLoaded()) {
|
||||
if(needSave) {
|
||||
System.Console.WriteLine("Saving cache...");
|
||||
SaveCache();
|
||||
System.Console.WriteLine("Saving data cache...");
|
||||
saveCache();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user