public void SetEXE(object obj) { if (SelectedExecutable != null) { MainViewModel.SelectedGame.UserPreferedEXE = SelectedExecutable; if (MainViewModel.SelectedGame.UserPreferedEXE != null) { var initialJson = File.ReadAllText(@"game.json"); var list = JsonConvert.DeserializeObject <List <Game> >(initialJson); Game game = new Game() { Executables = MainViewModel.SelectedGame.Executables, ID = MainViewModel.SelectedGame.ID, Platform = MainViewModel.SelectedGame.Platform, UserPreferedEXE = MainViewModel.SelectedGame.UserPreferedEXE, Name = MainViewModel.SelectedGame.Name }; //create steam game list.Add(game); var convertedJson = JsonConvert.SerializeObject(list, Formatting.Indented); File.WriteAllText(@"game.json", string.Empty); File.AppendAllText(@"game.json", convertedJson); } ExeWindow = Application.Current.Windows.OfType <ChooseGameExesView>().SingleOrDefault(w => w.IsActive); ExeWindow.Close(); } }
private void SetPreferedEXE(object obj) { if (SelectedGame != null) { //should put this into ctor string json = "game.json"; if (!File.Exists(json)) { using (StreamWriter file = File.CreateText(@"game.json")) { file.WriteLine("[]"); } } else { var initialJson = File.ReadAllText(@"game.json"); var gameDirList = JsonConvert.DeserializeObject <List <Game> >(initialJson); var gameFound = gameDirList.Find(game => game.Name == SelectedGame.Name); AllowGameToBePlayed = true; if (gameFound == null) { //if (SelectedGame.Executables.Count != 1) //{ Window = new ChooseGameExesView(SelectedGame); Window.ShowDialog(); AllowGameToBePlayed = false; // } //else //{ // if (SelectedGame.Executables.Count == 1) // { // MainViewModel.SelectedGame.UserPreferedEXE = SelectedGame.Executables[0]; // } //} } } } }