private void ReadFromOsudb(Beatmap beatmap) { NowPlaying = "Loading..."; _bStatus = OsuBeatmapStatus.Loading; if (_md5Str is null || _md5Str1 is null) { return; } _md5Str = new MD5String(""); if (_md5Str != _md5Str1) { _beatmapDb = new OsuBeatmapDb(); _md5Str1 = _md5Str; } try { if (beatmap != null) { var md5 = MD5String.GetString( new MD5CryptoServiceProvider().ComputeHash(File.ReadAllBytes(beatmap.FilenameFull))); var osuBeatmap = _beatmapDb.Beatmaps.FindByMd5(md5); if (!(osuBeatmap is null)) { Beatmap = new Beatmaps.Beatmap(osuBeatmap); _osuBeatmap = osuBeatmap; NowPlaying = Beatmap.ToString(); _hitObjects = Beatmap.HitObjects; var lastHitObjectEndTime = TimeSpan.FromMilliseconds(_hitObjects.LastOrDefault().GetEndTime()); _bStatus = osuBeatmap.BeatmapStatus; var totalTime = osuBeatmap.TotalTime; _dur = totalTime; _drainTime = lastHitObjectEndTime; if (CurrentMode is ILegacyMode le) { if (_osuBeatmap.Mode == OsuGameMode.Osu) { Beatmap.Stars = _osuBeatmap.ModStarPair.GetStars(le.LegacyMode, Mods.ToIntMod()); } } if (DebugMode) { IO.CurrentIO.Write("Beatmap read from OsuDb.", true, false); } } else { IO.CurrentIO.WriteColor("Fail to get beatmap info.", ConsoleColor.Red, true, false); } } }
public bool Process(InfoReader infoReader, CommandParser parser) { Type t = infoReader.GetOrtdp().GetType(); PropertyInfo[] properties = t.GetProperties(); StringBuilder b = new StringBuilder(); foreach (var property in properties) { if (property.GetCustomAttribute <AvailableVariableAttribute>() is AvailableVariableAttribute attr) { b.AppendLine($"{attr.VariableName} {NI18n.GetLanguageElement(attr.LanguageElementName)}"); } if (property.PropertyType.IsClass) { var currentObject = property.GetValue(infoReader.GetOrtdp()); if (!(currentObject is null)) { var currentProperties = currentObject.GetType().GetProperties(); foreach (var i in currentProperties) { if (i.GetCustomAttribute <AvailableVariableAttribute>() is AvailableVariableAttribute attra) { b.AppendLine($"{attra.VariableName} {NI18n.GetLanguageElement(attra.LanguageElementName)}"); } } } } } if (File.Exists("vars.txt")) { MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider(); provider.ComputeHash(File.ReadAllBytes("vars.txt")); string md5NewFile = MD5String.GetString(provider); provider.ComputeHash(b.ToString().ToBytes()); string md5Target = MD5String.GetString(provider); if (md5NewFile != md5Target) { IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_WRITINGHELP")); File.WriteAllText("vars.txt", b.ToString()); } } else { IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_WRITINGHELP")); File.WriteAllText("vars.txt", b.ToString()); } System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo { FileName = "notepad.exe", Arguments = "vars.txt" }); return(true); }
public InfoReader() : base(PLUGIN_NAME, PLUGIN_AUTHOR) { if (!File.Exists("InfoReader.db")) { File.WriteAllBytes("InfoReader.db", Resource1.Database); } /*else * { * byte[] dbBytes = File.ReadAllBytes("InfoReader.db"); * MD5 selfMd5 = MD5.Create(), fileMd5 = MD5.Create(); * selfMd5.ComputeHash(Resource1.Database); * fileMd5.ComputeHash(dbBytes); * MD5String selfMd5String = new MD5String(selfMd5), fileMd5String = new MD5String(fileMd5); * if (selfMd5String != fileMd5String) * { * File.Delete("InfoReader.db"); * File.WriteAllBytes("InfoReader.db",Resource1.Database); * } * }*/ StringBuilder builder = new StringBuilder(32); GetPrivateProfileString("Sync.DefaultConfiguration", "Language", "zh-cn", builder, 32, "..\\config.ini"); SyncLang = builder.ToString(); CurrentNi18N = NI18n.GetCurrentLanguage(); CurrentNi18N.InitializeOperator(); ScanCommand(); if (File.Exists("RealTimePPDisplayer.dll")) { byte[] b = File.ReadAllBytes("RealTimePPDisplayer.dll"); MD5 selfMd5 = MD5.Create(), fileMd5 = MD5.Create(); selfMd5.ComputeHash(Resource1.ModifiedRealTimePPDisplayer); fileMd5.ComputeHash(b); if (MD5String.GetString(selfMd5) != MD5String.GetString(fileMd5)) { var dirInfo = Directory.CreateDirectory("..\\OrignalRealTimePPDisplayer\\"); IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_RTPPDREPLACED")); if (File.Exists(Path.Combine(dirInfo.FullName, "RealTimePPDisplayer.dll"))) { File.Delete(Path.Combine(dirInfo.FullName, "RealTimePPDisplayer.dll")); } File.Move("RealTimePPDisplayer.dll", Path.Combine(dirInfo.FullName, "RealTimePPDisplayer.dll")); File.WriteAllBytes("RealTimePPDisplayer.dll", Resource1.ModifiedRealTimePPDisplayer); } } else { File.WriteAllBytes("RealTimePPDisplayer.dll", Resource1.ModifiedRealTimePPDisplayer); } /*if(!File.Exists("bass.dll")) * File.WriteAllBytes("bass.dll",Resource1.bass);*/ _outputInfoMap = MemoryMappedFile.CreateOrOpen("InfoReaderMmf", 128); EventBus.BindEvent <PluginEvents.InitPluginEvent>(Init); EventBus.BindEvent <PluginEvents.LoadCompleteEvent>(Loaded); EventBus.BindEvent <PluginEvents.InitCommandEvent>(CommandInit); PluginConfigurationManager manager = new Sync.Tools.PluginConfigurationManager(this); manager.AddItem(Setting); }