mu3-mods/LoadBoost/MU3.Data/patch_DataManager.cs
akanyan 4ad595f6c3 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
2024-07-23 01:45:36 +09:00

72 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace MU3.Data;
public class patch_DataManager: DataManager {
private Dictionary<int, FumenAnalysisData> _fumenAnalysisData;
private string _fileName;
private void initCache() {
if(File.Exists(_fileName)) {
System.Console.WriteLine("Loading chart analysis cache...");
_fumenAnalysisData = new Dictionary<int, FumenAnalysisData>();
using FileStream input = File.OpenRead(_fileName);
using BinaryReader binaryReader = new BinaryReader(input);
while(binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) {
int key = binaryReader.ReadInt32();
bool isExist = binaryReader.ReadBoolean();
int bpm = binaryReader.ReadInt32();
int platinumScoreMax = binaryReader.ReadInt32();
string notesDesignerName = binaryReader.ReadString();
_fumenAnalysisData.Add(key, new FumenAnalysisData {
isExist = isExist,
bpm = bpm,
platinumScoreMax = platinumScoreMax,
notesDesignerName = notesDesignerName
});
}
} else {
_fumenAnalysisData = new Dictionary<int, FumenAnalysisData>();
}
}
private void saveCache() {
System.Console.WriteLine($"Saving chart analysis cache...{Enumerable.First(_fumenAnalysisData).Key},{Enumerable.First(_fumenAnalysisData).Value.notesDesignerName}");
if(File.Exists(_fileName)) {
File.Delete(_fileName);
}
using FileStream fileStream = File.OpenWrite(_fileName);
using BinaryWriter binaryWriter = new BinaryWriter(fileStream);
foreach(KeyValuePair<int, FumenAnalysisData> fumenAnalysisDatum in _fumenAnalysisData) {
binaryWriter.Write(fumenAnalysisDatum.Key);
binaryWriter.Write(fumenAnalysisDatum.Value.isExist);
binaryWriter.Write(fumenAnalysisDatum.Value.bpm);
binaryWriter.Write(fumenAnalysisDatum.Value.platinumScoreMax);
binaryWriter.Write(fumenAnalysisDatum.Value.notesDesignerName);
}
fileStream.Flush();
}
private extern void orig_makeFumenAnalysisDataList();
private void makeFumenAnalysisDataList() {
using IniFile iniFile = new("mu3.ini");
_fileName = Path.Combine(iniFile.getValue("Extra", "CacheDir", "."), "data_fumen_analysis_cache.bin");
try {
if(patch_DataStudioManager.needSave || !File.Exists(_fileName)) {
orig_makeFumenAnalysisDataList();
saveCache();
} else {
initCache();
}
} catch(Exception value) {
System.Console.WriteLine(value);
}
}
}