2024-07-04 12:43:10 +00:00
|
|
|
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;
|
2024-07-22 16:45:36 +00:00
|
|
|
private string _fileName;
|
2024-07-04 12:43:10 +00:00
|
|
|
|
2024-07-22 16:45:36 +00:00
|
|
|
private void initCache() {
|
|
|
|
if(File.Exists(_fileName)) {
|
|
|
|
System.Console.WriteLine("Loading chart analysis cache...");
|
2024-07-04 12:43:10 +00:00
|
|
|
_fumenAnalysisData = new Dictionary<int, FumenAnalysisData>();
|
2024-07-22 16:45:36 +00:00
|
|
|
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
|
|
|
|
});
|
2024-07-04 12:43:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_fumenAnalysisData = new Dictionary<int, FumenAnalysisData>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 16:45:36 +00:00
|
|
|
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);
|
2024-07-04 12:43:10 +00:00
|
|
|
}
|
2024-07-22 16:45:36 +00:00
|
|
|
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);
|
2024-07-04 12:43:10 +00:00
|
|
|
}
|
2024-07-22 16:45:36 +00:00
|
|
|
fileStream.Flush();
|
2024-07-04 12:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private extern void orig_makeFumenAnalysisDataList();
|
|
|
|
|
|
|
|
private void makeFumenAnalysisDataList() {
|
2024-07-22 16:45:36 +00:00
|
|
|
using IniFile iniFile = new("mu3.ini");
|
|
|
|
_fileName = Path.Combine(iniFile.getValue("Extra", "CacheDir", "."), "data_fumen_analysis_cache.bin");
|
|
|
|
|
2024-07-04 12:43:10 +00:00
|
|
|
try {
|
2024-07-22 16:45:36 +00:00
|
|
|
if(patch_DataStudioManager.needSave || !File.Exists(_fileName)) {
|
2024-07-04 12:43:10 +00:00
|
|
|
orig_makeFumenAnalysisDataList();
|
2024-07-22 16:45:36 +00:00
|
|
|
saveCache();
|
2024-07-04 12:43:10 +00:00
|
|
|
} else {
|
2024-07-22 16:45:36 +00:00
|
|
|
initCache();
|
2024-07-04 12:43:10 +00:00
|
|
|
}
|
|
|
|
} catch(Exception value) {
|
|
|
|
System.Console.WriteLine(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|