public bool Process(InfoReader instance, CommandParser parser) { var or = instance.GetOrtdp(); if (parser.MainCommand == "open") { if (parser.Arguments[0] == "beatmappage") { Open(instance.GetOrtdp().Beatmap.DownloadLink); } else if (parser.Arguments[0] == "beatmapfolder") { Open(or.Beatmap.BeatmapFolder); } else if (parser.Arguments[0] == "musicfolder") { Open(instance.Setting.DefaultMusicCopyingDirectory); } else if (parser.Arguments[0] == "videofolder") { Open(instance.Setting.DefaultVideoCopyingDirectory); } else if (parser.Arguments[0] == "bgfolder") { Open(instance.Setting.DefaultBackgroundCopyingDirectory); } else if (parser.Arguments[0] == "oszfolder") { Open(instance.Setting.OszDir); } else if (parser.Arguments[0] == "userpage") { string username; if (parser.Arguments.Count < 1) { OsuInfo info = new OsuInfo(); username = info.UserName; if (string.IsNullOrEmpty(username)) { IO.CurrentIO.WriteColor("无法检测用户名,请在最后填入用户名", ConsoleColor.Red); } } else { username = CombineString(parser.Arguments.Skip(1).ToArray()); } Open($"https://osu.ppy.sh/users/{username}"); } else { IO.CurrentIO.Write(GetHelp()); } } return(true); }
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 static object GetVariableValue(InfoReader infoReader, string varName, ref bool exist) { Type t = infoReader.GetOrtdp().GetType(); var properties = t.GetProperties(); foreach (var p in properties) { if (p.Name == varName) { exist = true; return(p.GetValue(infoReader.GetOrtdp())); } } return(null); }
void GetOsz(InfoReader instance) { var ortdpWrapper = instance.GetOrtdp(); Win32Class.SevenZip zip = new Win32Class.SevenZip { SevenZipDirectory = "..\\pg\\7-zip\\7za.exe" }; StringBuilder tmp = new StringBuilder(ortdpWrapper.FullPath); string basicinfo = $"{ortdpWrapper.Artist} - {ortdpWrapper.Title}"; string pattern = "[" + new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars()) + ":*]"; System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern); Win32Class.SevenZip.Native.SevenZipArgs arg = new Win32Class.SevenZip.Native.SevenZipArgs { FileType = Win32Class.SevenZip.Native.ArchieveType.Zip }; string newdir = reg.Replace($"{ortdpWrapper.Artist} - {ortdpWrapper.Title}", " "); arg.ArchieveFileName = "\"" + instance.Setting.OszDir + "\\" + ortdpWrapper.Beatmap.BeatmapSetId + " " + newdir + ".osz\""; if (File.Exists(arg.ArchieveFileName.Trim('\"'))) { IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_OSZEXISTED")); File.Delete(arg.ArchieveFileName.Trim('\"')); } arg.OperationType = Win32Class.SevenZip.Native.Operation.Add; if (!instance.Setting.OszDir.ToString().EndsWith("\\")) { arg.Files = "\"" + ortdpWrapper.Beatmap.BeatmapFolder + "\\*.*" + "\""; } else { arg.Files = "\"" + ortdpWrapper.Beatmap.BeatmapFolder + "\""; } var sta = Win32Class.SevenZip.Native.Run7zCmd(zip.SevenZipDirectory, arg); if (sta == Win32Class.SevenZip.Native.SevenZipStateCode.Success) { IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_COMPRESSED")); } if (sta == Win32Class.SevenZip.Native.SevenZipStateCode.FaltalError) { IO.CurrentIO.WriteColor(NI18n.GetLanguageElement("LANG_7ZSTATUS_FATALERR"), ConsoleColor.Red); } if (sta == Win32Class.SevenZip.Native.SevenZipStateCode.OutOfMemory) { IO.CurrentIO.WriteColor(NI18n.GetLanguageElement("LANG_7ZSTATUS_OUTOFMEMORY"), ConsoleColor.Red); } if (sta == Win32Class.SevenZip.Native.SevenZipStateCode.Canceled) { IO.CurrentIO.WriteColor(NI18n.GetLanguageElement("LANG_7ZSTATUS_OPERATIONCANCELED"), ConsoleColor.Red); } if (sta == Win32Class.SevenZip.Native.SevenZipStateCode.CommandLineError) { IO.CurrentIO.WriteColor(NI18n.GetLanguageElement("LANG_7ZSTATUS_COMMANDLINEERR"), ConsoleColor.Red); } if (sta == Win32Class.SevenZip.Native.SevenZipStateCode.Warning) { IO.CurrentIO.WriteColor(NI18n.GetLanguageElement("LANG_7ZSTATUS_WARNINGS"), ConsoleColor.Yellow); } }
public bool Process(InfoReader instance, CommandParser parser) { Beatmap currentBeatmap = instance.GetOrtdp().Beatmap; if (parser.Arguments[0] == "au") { if (currentBeatmap is null || string.IsNullOrEmpty(currentBeatmap.AudioFileName) || !File.Exists(currentBeatmap.FullAudioFileName)) { return(true); } string ext = Path.GetExtension(currentBeatmap.FullAudioFileName); string targetPath = GetName(instance.Setting.DefaultMusicCopyingDirectory, currentBeatmap, ext); if (!File.Exists(targetPath)) { File.Copy(currentBeatmap.FullAudioFileName ?? throw new InvalidOperationException(), targetPath); } IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_COPYSUCCESS")); } else if (parser.Arguments[0] == "vi") { if (currentBeatmap is null || !currentBeatmap.HasVideo || string.IsNullOrEmpty(currentBeatmap.VideoFileName) || !File.Exists(currentBeatmap.FullVideoFileName)) { return(true); } string ext = Path.GetExtension(currentBeatmap.VideoFileName); string targetPath = GetName(instance.Setting.DefaultMusicCopyingDirectory, currentBeatmap, ext); if (!File.Exists(targetPath)) { File.Copy(currentBeatmap.FullVideoFileName ?? throw new InvalidOperationException(), targetPath); } IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_COPYSUCCESS")); } else if (parser.Arguments[0] == "bg") { if (currentBeatmap is null || string.IsNullOrEmpty(currentBeatmap.BackgroundFileName) || !File.Exists(currentBeatmap.FullBackgroundFileName)) { return(true); } string ext = Path.GetExtension(currentBeatmap.BackgroundFileName); string targetPath = GetName(instance.Setting.DefaultBackgroundCopyingDirectory, currentBeatmap, ext); if (!File.Exists(targetPath)) { File.Copy(currentBeatmap.FullBackgroundFileName ?? throw new InvalidOperationException(), targetPath); } IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_COPYSUCCESS")); } else if (parser.Arguments[0] == "osz") { GetOsz(instance); } else { IO.CurrentIO.Write(GetHelp()); } return(true); }
void Search(InfoReader infoReader, string varName) { var p = infoReader.GetOrtdp().GetType().GetProperties(); Sync.Tools.IO.CurrentIO.Write(NI18n.GetLanguageElement("LANG_INFO_VARSEARCHRESULT")); foreach (System.Reflection.PropertyInfo info in p) { string argupper = varName.ToUpper(); string perupper = info.Name.ToUpper(); if (perupper.Contains(argupper)) { Sync.Tools.IO.CurrentIO.Write(info.Name, false, false); Sync.Tools.IO.CurrentIO.Write(" ", false, false); } } Sync.Tools.IO.CurrentIO.Write("\n", true, false); }
public bool Process(InfoReader instance, CommandParser parser) { if (_viewer is null) { _viewer = new VariableViewer(instance.GetOrtdp()); } if (parser.MainCommand == "var") { if (parser.Arguments[0] == "gui") { if (!_msgLoopStarted) { if (instance.Setting.DebugMode.ToString().Equals("True", StringComparison.OrdinalIgnoreCase)) { IO.CurrentIO.Write($"Message loop on window VariableViewer started."); } Thread th = new Thread(() => { System.Windows.Forms.Application.Run(_viewer); }); th.Start(); if (th.ThreadState == ThreadState.Running) { _msgLoopStarted = true; } return(true); } if (instance.Setting.DebugMode.ToString().Equals("True", StringComparison.OrdinalIgnoreCase)) { IO.CurrentIO.Write($"Message loop on VariableViewer is running. Showing window..."); } _viewer.Show(); return(true); } int match = 0; var s = parser.Arguments[0]; Type t = instance.GetOrtdp().GetType(); var ps = t.GetProperties(); string[] gets = s.Split('.'); object currentObject = instance.GetOrtdp(); var currentProperties = ps; foreach (var name in gets) { foreach (var property in currentProperties) { if (property.Name == name) { currentObject = property.GetValue(currentObject); currentProperties = currentObject.GetType().GetProperties(); match++; } } } IO.CurrentIO.Write(match == gets.Length ? $"{s}:{currentObject}" : NI18n.GetLanguageElement("LANG_ERR_VARNOTFOUND")); return(true); } return(true); }