mu3-mods/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs
akanyan 032b6864da fix: cache mkdir
I originally left it out because I wanted to avoid unnecessary
code duplication. Turns out it wasn't unnecessary.
2024-08-24 14:14:02 +00:00

57 lines
1.4 KiB
C#

using System;
using System.Collections.ObjectModel;
using System.IO;
namespace MU3.Operation;
class patch_OperationManager: OperationManager {
private ReadOnlyCollection<MovieData> _movieDataList;
private int _movieIndex;
private string _fileName;
~patch_OperationManager() {
try {
File.WriteAllText(_fileName, MovieIndex.ToString());
} catch(Exception ex) {
System.Console.WriteLine(ex);
}
}
public int MovieIndex {
set {
if(_movieDataList.Count > 0) {
_movieIndex = (value + _movieDataList.Count) % _movieDataList.Count;
} else {
_movieIndex = 0;
}
}
get {
return _movieIndex;
}
}
public new MovieData movieData {
get {
if(_movieDataList.Count > 0) {
return _movieDataList[MovieIndex];
}
return null;
}
}
public extern void orig_initialize();
public new void initialize() {
orig_initialize();
using IniFile iniFile = new("mu3.ini");
var dir = iniFile.getValue("Extra", "CacheDir", ".");
Directory.CreateDirectory(dir);
_fileName = Path.Combine(dir, "data_advert_cache.txt");
try {
_movieIndex = Math.Max(0, int.Parse(File.ReadAllText(_fileName)));
} catch(Exception) {
_movieIndex = 0;
}
}
}