public CheatWindow(VirtualFileSystem virtualFileSystem, string titleId, string titleName) { LoadedCheats = new AvaloniaList <CheatsList>(); Heading = string.Format(LocaleManager.Instance["CheatWindowHeading"], titleName, titleId.ToUpper()); InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif string modsBasePath = virtualFileSystem.ModLoader.GetModsBasePath(); string titleModsPath = virtualFileSystem.ModLoader.GetTitleDir(modsBasePath, titleId); ulong titleIdValue = ulong.Parse(titleId, System.Globalization.NumberStyles.HexNumber); _enabledCheatsPath = Path.Combine(titleModsPath, "cheats", "enabled.txt"); string[] enabled = { }; if (File.Exists(_enabledCheatsPath)) { enabled = File.ReadAllLines(_enabledCheatsPath); } int cheatAdded = 0; var mods = new ModLoader.ModCache(); ModLoader.QueryContentsDir(mods, new DirectoryInfo(Path.Combine(modsBasePath, "contents")), titleIdValue); string currentCheatFile = string.Empty; string buildId = string.Empty; string parentPath = string.Empty; CheatsList currentGroup = null; foreach (var cheat in mods.Cheats) { if (cheat.Path.FullName != currentCheatFile) { currentCheatFile = cheat.Path.FullName; parentPath = currentCheatFile.Replace(titleModsPath, ""); buildId = Path.GetFileNameWithoutExtension(currentCheatFile).ToUpper(); currentGroup = new CheatsList(buildId, parentPath); LoadedCheats.Add(currentGroup); } var model = new CheatModel(cheat.Name, buildId, enabled.Contains($"{buildId}-{cheat.Name}")); currentGroup?.Add(model); cheatAdded++; } if (cheatAdded == 0) { NoCheatsFound = true; } DataContext = this; Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["CheatWindowTitle"]; }
private CheatWindow(Builder builder, VirtualFileSystem virtualFileSystem, ulong titleId, string titleName) : base(builder.GetObject("_cheatWindow").Handle) { builder.Autoconnect(this); _baseTitleInfoLabel.Text = $"Cheats Available for {titleName} [{titleId:X16}]"; string modsBasePath = virtualFileSystem.ModLoader.GetModsBasePath(); string titleModsPath = virtualFileSystem.ModLoader.GetTitleDir(modsBasePath, titleId.ToString("X16")); _enabledCheatsPath = System.IO.Path.Combine(titleModsPath, "cheats", "enabled.txt"); _cheatTreeView.Model = new TreeStore(typeof(bool), typeof(string), typeof(string), typeof(string)); CellRendererToggle enableToggle = new CellRendererToggle(); enableToggle.Toggled += (sender, args) => { _cheatTreeView.Model.GetIter(out TreeIter treeIter, new TreePath(args.Path)); bool newValue = !(bool)_cheatTreeView.Model.GetValue(treeIter, 0); _cheatTreeView.Model.SetValue(treeIter, 0, newValue); if (_cheatTreeView.Model.IterChildren(out TreeIter childIter, treeIter)) { do { _cheatTreeView.Model.SetValue(childIter, 0, newValue); }while (_cheatTreeView.Model.IterNext(ref childIter)); } }; _cheatTreeView.AppendColumn("Enabled", enableToggle, "active", 0); _cheatTreeView.AppendColumn("Name", new CellRendererText(), "text", 1); _cheatTreeView.AppendColumn("Path", new CellRendererText(), "text", 2); var buildIdColumn = _cheatTreeView.AppendColumn("Build Id", new CellRendererText(), "text", 3); buildIdColumn.Visible = false; string[] enabled = { }; if (File.Exists(_enabledCheatsPath)) { enabled = File.ReadAllLines(_enabledCheatsPath); } int cheatAdded = 0; var mods = new ModLoader.ModCache(); ModLoader.QueryContentsDir(mods, new DirectoryInfo(System.IO.Path.Combine(modsBasePath, "contents")), titleId); string currentCheatFile = string.Empty; string buildId = string.Empty; TreeIter parentIter = default; foreach (var cheat in mods.Cheats) { if (cheat.Path.FullName != currentCheatFile) { currentCheatFile = cheat.Path.FullName; string parentPath = currentCheatFile.Replace(titleModsPath, ""); buildId = System.IO.Path.GetFileNameWithoutExtension(currentCheatFile).ToUpper(); parentIter = ((TreeStore)_cheatTreeView.Model).AppendValues(false, buildId, parentPath, ""); } string cleanName = cheat.Name.Substring(1, cheat.Name.Length - 8); ((TreeStore)_cheatTreeView.Model).AppendValues(parentIter, enabled.Contains($"{buildId}-{cheat.Name}"), cleanName, "", buildId); cheatAdded++; } if (cheatAdded == 0) { ((TreeStore)_cheatTreeView.Model).AppendValues(false, "No Cheats Found", "", ""); _cheatTreeView.GetColumn(0).Visible = false; _noCheatsFound = true; _saveButton.Visible = false; } _cheatTreeView.ExpandAll(); }