1
0
forked from akanyan/mu3-mods

feat(SortByInternal): store selection in the fs

This commit is contained in:
2024-12-17 19:03:52 +00:00
parent fdd29d0c9d
commit aec0f47b9c

View File

@ -1,5 +1,9 @@
using MU3.Client; using MU3.Client;
using MU3.DB; using MU3.DB;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace MU3.User; namespace MU3.User;
class patch_UserDetail: UserDetail { class patch_UserDetail: UserDetail {
@ -9,12 +13,62 @@ class patch_UserDetail: UserDetail {
// Attempting to use a profile with InternalLevel sorting enabled // Attempting to use a profile with InternalLevel sorting enabled
// causes unpatched clients to crash thanks to enormous incompetence // causes unpatched clients to crash thanks to enormous incompetence
// of Sxga's interns. So, unfortunately, this value has to be discarded. // of Sxga's interns.
// See: // See:
// * MusicSelectViewDataList._sort1 set // * MusicSelectViewDataList._sort1 set
// * UserDetail.copyFrom() // * UserDetail.copyFrom()
if(userDetail.tabSetting == (int)patch_MusicSort1ID.InternalLevel) { if(userDetail.tabSetting == (int)patch_MusicSort1ID.InternalLevel) {
userDetail.tabSetting = (int)patch_MusicSort1ID.Level; userDetail.tabSetting = (int)patch_MusicSort1ID.Level;
stashTabSelection(userDetail.userName, true);
} else {
stashTabSelection(userDetail.userName, false);
} }
} }
public extern void orig_copyFrom(UserData userDetail);
public new void copyFrom(UserData userDetail) {
orig_copyFrom(userDetail);
if(userDetail.tabSetting == (int)patch_MusicSort1ID.Level && isStashedTabSelection(userDetail.userName)) {
MusicSort1 = (MusicSort1ID)patch_MusicSort1ID.InternalLevel;
}
}
private void stashTabSelection(string user, bool value) {
var path = getStashPath();
List<string> entries;
try {
entries = File.ReadAllText(path).Split('\n').ToList();
entries = entries.Where((val) => val.Length > 0 && val != user).ToList();
} catch(Exception) {
entries = [];
}
if(value) {
entries.Add(user);
}
try {
File.WriteAllText(path, entries.Aggregate("", (acc, s) => acc + s + "\n").Trim());
} catch(Exception e) {
UnityEngine.Debug.Log("Unable to write tab selection: " + e.ToString());
}
}
private bool isStashedTabSelection(string user) {
try {
var entries = File.ReadAllText(getStashPath()).Split('\n').ToList();
return entries.Contains(user);
} catch(Exception) {
// Whatever, this is not mission critical
return false;
}
}
private string getStashPath() {
using IniFile iniFile = new("mu3.ini");
var dir = iniFile.getValue("Extra", "CacheDir", ".");
Directory.CreateDirectory(dir);
return Path.Combine(dir, "data_tab_cache.txt");
}
} }