private void AGameBtn_Click(object sender, RoutedEventArgs e) { Button PressedButton = (Button)sender; _Tag = Convert.ToInt32((string)PressedButton.Tag); GamesInfoClass _GamesInfoClass = gamesInfoClasses[_Tag]; string GameInfoPath = Properties.Settings.Default.AppDataPath + "GameInfo.txt"; try { if (_GamesInfoClass != null) { webClient.DownloadFile(new Uri(_GamesInfoClass.InfoDriveLocationUri, UriKind.RelativeOrAbsolute), GameInfoPath); using (StreamReader StreamReader = new StreamReader(GameInfoPath)) { gamesInfoClasses[_Tag].NewGameVersion = new Version(StreamReader.ReadLine()); gamesInfoClasses[_Tag].GameDriveLocationUri = StreamReader.ReadLine(); StreamReader.Dispose(); } File.Delete(GameInfoPath); } else { gamesInfoClasses[_Tag].NewGameVersion = new Version("0.0"); gamesInfoClasses[_Tag].GameDriveLocationUri = ""; } } catch { //f } _MainWindow.GamesInfoClassList[_Tag] = gamesInfoClasses[_Tag]; _GamePage = new GamePage(_Tag, _MainWindow); ((MainWindow)Window.GetWindow(this)).Frame0.Navigate(_GamePage); }
async void GoogleDiscGamesCheck() { try { ListWithGameData.Clear(); string GameListFilePath = Properties.Settings.Default.AppDataPath + "gamelist.txt"; if (File.Exists(GameListFilePath)) { File.Delete(GameListFilePath); } webClient.DownloadFile(GameListFileUri, GameListFilePath); using (StreamReader StreamReader = new StreamReader(GameListFilePath)) { int LineNum = 0; string[] LineList; string line; string _GameReleaseStatus = ""; while ((line = await StreamReader.ReadLineAsync()) != null) { try { if (gamesInfoClasses[LineNum] == null) { gamesInfoClasses[LineNum] = new GamesInfoClass(); } } catch { gamesInfoClasses[LineNum] = new GamesInfoClass(); } LineList = line.Split('}'); if (gamesInfoClasses[LineNum].GameName == null) { gamesInfoClasses[LineNum].GameName = LineList[0]; } if (gamesInfoClasses[LineNum].GameName != LineList[0]) { gamesInfoClasses[LineNum].GameName = LineList[0]; } gamesInfoClasses[LineNum].GamePictureUri = LineList[1]; gamesInfoClasses[LineNum].InfoDriveLocationUri = LineList[2]; gamesInfoClasses[LineNum].GameReleaseStatus = Convert.ToInt32(LineList[3]); switch (Convert.ToInt32(LineList[3])) { case 0: _GameReleaseStatus = "Soon"; break; case 1: _GameReleaseStatus = "Beta"; break; case 2: _GameReleaseStatus = ""; break; } ListWithGameData.Add(new GameData() { AGameName = gamesInfoClasses[LineNum].GameName, IconSource = new Uri(LineList[1], UriKind.RelativeOrAbsolute), BtnTag = Convert.ToString(gamesInfoClasses[LineNum].Tag), GameReleaseStatus = _GameReleaseStatus }); LineNum++; } StreamReader.Dispose(); GameItemsControl.ItemsSource = ListWithGameData; } File.Delete(GameListFilePath); } catch { MessageBox.Show("Error: check your internet connection. ", "Error"); AddTestGame(); } }
void DeleteGame() { GameStatus = -2; _GamesInfoClass.GameStatus = GameStatus; _GamesInfoClass.CurrentGameVersion = null; StatusTextBlock.Text = "Status: Not installed."; InstallBtn.Content = "Install"; InstallBtn.Tag = "Install"; DeleteBtn.Visibility = Visibility.Hidden; BinaryWriter BinaryWriter = new BinaryWriter(File.Open(SettingsPath, FileMode.Create)); int i = 0; while (i != 99) { if (i == _GamesInfoClass.Tag) { BinaryWriter.Write( null + ";" + //0 null + ";" + //1 null + ";" + //2 null + ";" + //3 null + ";" + //4 null + ";" + //5 null + ";" + //6 null + ";" + //7 null + ";" + //8 null //9 ); _MainWindow.GamesInfoClassList[i] = _GamesInfoClass; } else { GamesInfoClass NotUpdatedGamesInfoClass = _MainWindow.GamesInfoClassList[i]; if (NotUpdatedGamesInfoClass == null) { NotUpdatedGamesInfoClass = new GamesInfoClass(); } if (NotUpdatedGamesInfoClass.GameName == null) { BinaryWriter.Write( null + ";" + //0 null + ";" + //1 null + ";" + //2 null + ";" + //3 null + ";" + //4 null + ";" + //5 null + ";" + //6 null + ";" + //7 null + ";" + //8 null //9 ); } else { BinaryWriter.Write( NotUpdatedGamesInfoClass.GameName + ";" + //0 NotUpdatedGamesInfoClass.GamePictureUri + ";" + //1 NotUpdatedGamesInfoClass.InfoDriveLocationUri + ";" + //2 NotUpdatedGamesInfoClass.GameDriveLocationUri + ";" + //3 NotUpdatedGamesInfoClass.GamePCLocation + ";" + //4 NotUpdatedGamesInfoClass.CurrentGameVersion + ";" + //5 NotUpdatedGamesInfoClass.NewGameVersion + ";" + //6 NotUpdatedGamesInfoClass.GameStatus + ";" + //7 NotUpdatedGamesInfoClass.GameReleaseStatus + ";" + //8 NotUpdatedGamesInfoClass.Tag //9 ); } } i++; } BinaryWriter.Dispose(); }
public GamePage(int _Tag, MainWindow mainWindow) { InitializeComponent(); _GamesInfoClass = mainWindow.GamesInfoClassList[_Tag]; _MainWindow = mainWindow; GameNameTextBlock.Text = _GamesInfoClass.GameName; if (_GamesInfoClass.GameReleaseStatus == 0) { GameReleaseStatusTextBlock.Text = "Soon"; InstallBtn.IsEnabled = false; GameIsComingSoon = true; } else if (_GamesInfoClass.GameReleaseStatus == 1) { GameReleaseStatusTextBlock.Text = "Beta"; } else { GameReleaseStatusTextBlock.Text = ""; } if (_GamesInfoClass.CurrentGameVersion == null) { GameStatus = -2; } else { switch (_GamesInfoClass.NewGameVersion.CompareTo(_GamesInfoClass.CurrentGameVersion)) { case 0: GameStatus = 0; //такая же break; case 1: GameStatus = 1; //новее break; case -1: GameStatus = -1; //старше break; } } //новая и текущая версия вносятся в текстблоки if (GameIsComingSoon == false) { VersionTextBlock.Text = "This version: " + _GamesInfoClass.CurrentGameVersion; } if (!_GamesInfoClass.NewGameVersion.Equals(_GamesInfoClass.CurrentGameVersion)) { VersionTextBlock.Text += " New version: " + _GamesInfoClass.NewGameVersion; } if (_GamesInfoClass.GamePCLocation == null) { _GamesInfoClass.GamePCLocation = Properties.Settings.Default.SaveFolderPath + _GamesInfoClass.GameName; _GamesInfoClass.GamePCLocation = _GamesInfoClass.GamePCLocation.Replace(" ", ""); } ProgressBar0.Visibility = Visibility.Hidden; DownSpeedTextBlock.Visibility = Visibility.Hidden; if (GameStatus == -2) { StatusTextBlock.Text = "Status: Not installed."; InstallBtn.Content = "Install"; DeleteBtn.Visibility = Visibility.Hidden; } else if (GameStatus == 1) { StatusTextBlock.Text = "Status: Update found."; InstallBtn.Content = "Update"; DeleteBtn.Visibility = Visibility.Visible; } else { StatusTextBlock.Text = "Status: Installed."; InstallBtn.Content = "Play"; DeleteBtn.Visibility = Visibility.Visible; } InfoRead(); ChangeTheme(); //MessageBox.Show("" + GameUpdateUri); }
private void Completed(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { try { MessageBox.Show("Complete"); GameStatus = 0; _GamesInfoClass.GameStatus = GameStatus; _GamesInfoClass.CurrentGameVersion = _GamesInfoClass.NewGameVersion; StatusTextBlock.Text = "Status: Installed."; InstallBtn.Content = "Play"; InstallBtn.Tag = "Play"; ZipFile.ExtractToDirectory(ZipPath, _GamesInfoClass.GamePCLocation); File.Delete(ZipPath); BinaryWriter BinaryWriter = new BinaryWriter(File.Open(SettingsPath, FileMode.Create)); int i = 0; while (i != 99) { /* * GameName - 0 * GamePictureUri - 1 * InfoDriveLocationUri - 2 * GameDriveLocationUri - 3 * GamePCLocation - 4 * CurrentGameVersion - 5 * NewGameVersion - 6 * GameStatus - 7 * GameReleaseStatus - 8 * Tag - 9 */ if (i == _GamesInfoClass.Tag) { BinaryWriter.Write( _GamesInfoClass.GameName + ";" + //0 _GamesInfoClass.GamePictureUri + ";" + //1 _GamesInfoClass.InfoDriveLocationUri + ";" + //2 _GamesInfoClass.GameDriveLocationUri + ";" + //3 _GamesInfoClass.GamePCLocation + ";" + //4 _GamesInfoClass.CurrentGameVersion + ";" + //5 _GamesInfoClass.NewGameVersion + ";" + //6 _GamesInfoClass.GameStatus + ";" + //7 _GamesInfoClass.GameReleaseStatus + ";" + //8 _GamesInfoClass.Tag //9 ); _MainWindow.GamesInfoClassList[i] = _GamesInfoClass; } else { GamesInfoClass NotUpdatedGamesInfoClass = _MainWindow.GamesInfoClassList[i]; if (NotUpdatedGamesInfoClass == null) { NotUpdatedGamesInfoClass = new GamesInfoClass(); } if (NotUpdatedGamesInfoClass.GameName == null) { BinaryWriter.Write( null + ";" + //0 null + ";" + //1 null + ";" + //2 null + ";" + //3 null + ";" + //4 null + ";" + //5 null + ";" + //6 null + ";" + //7 null + ";" + //8 null //9 ); } else { BinaryWriter.Write( NotUpdatedGamesInfoClass.GameName + ";" + //0 NotUpdatedGamesInfoClass.GamePictureUri + ";" + //1 NotUpdatedGamesInfoClass.InfoDriveLocationUri + ";" + //2 NotUpdatedGamesInfoClass.GameDriveLocationUri + ";" + //3 NotUpdatedGamesInfoClass.GamePCLocation + ";" + //4 NotUpdatedGamesInfoClass.CurrentGameVersion + ";" + //5 NotUpdatedGamesInfoClass.NewGameVersion + ";" + //6 NotUpdatedGamesInfoClass.GameStatus + ";" + //7 NotUpdatedGamesInfoClass.GameReleaseStatus + ";" + //8 NotUpdatedGamesInfoClass.Tag //9 ); } _MainWindow.GamesInfoClassList[i] = NotUpdatedGamesInfoClass; } i++; } if (!Directory.Exists(Properties.Settings.Default.AppDataPath + @"Games\" + _GamesInfoClass.GameName)) { Directory.CreateDirectory(Properties.Settings.Default.AppDataPath + @"Games\" + _GamesInfoClass.GameName); Directory.CreateDirectory(Properties.Settings.Default.AppDataPath + @"Games\" + _GamesInfoClass.GameName + @"\Screenshots\"); } BinaryWriter.Dispose(); } catch { MessageBox.Show("Error: Can't download this app, try later.", "Error"); } } InstallBtn.IsEnabled = true; DeleteBtn.Visibility = Visibility.Visible; //ProgressBar0.Visibility = Visibility.Hidden; _ProgressBar.Visibility = Visibility.Collapsed; _ProgressTextBox.Visibility = Visibility.Collapsed; DownSpeedTextBlock.Visibility = Visibility.Collapsed; Properties.Settings.Default.Installing = false; Properties.Settings.Default.Save(); }
void SettingsSearch() { if (File.Exists(DownGamesPath)) { try { GamesInfoClass gamesInfoClass; string[] BinaryReaderOutput; BinaryReader BinaryReader = new BinaryReader(File.OpenRead(DownGamesPath)); int LineNum = 0; while (BinaryReader.PeekChar() > -1) { /* * GameName - 0 * GamePictureUri - 1 * InfoDriveLocationUri - 2 * GameDriveLocationUri - 3 * GamePCLocation - 4 * CurrentGameVersion - 5 * NewGameVersion - 6 * GameStatus - 7 * GameReleaseStatus - 8 * Tag - 9 */ BinaryReaderOutput = BinaryReader.ReadString().Split(';'); gamesInfoClass = new GamesInfoClass(); gamesInfoClass.GameName = BinaryReaderOutput[0]; gamesInfoClass.GamePictureUri = BinaryReaderOutput[1]; gamesInfoClass.InfoDriveLocationUri = BinaryReaderOutput[2]; gamesInfoClass.GameDriveLocationUri = BinaryReaderOutput[3]; gamesInfoClass.GamePCLocation = BinaryReaderOutput[4]; try { gamesInfoClass.CurrentGameVersion = new Version(BinaryReaderOutput[5]); } catch { gamesInfoClass.CurrentGameVersion = null; } try { gamesInfoClass.NewGameVersion = new Version(BinaryReaderOutput[6]); } catch { gamesInfoClass.NewGameVersion = null; } try { gamesInfoClass.GameStatus = Convert.ToInt32(BinaryReaderOutput[7]); } catch { gamesInfoClass.GameStatus = 0; } try { gamesInfoClass.GameReleaseStatus = Convert.ToInt32(BinaryReaderOutput[8]); } catch { gamesInfoClass.GameReleaseStatus = 0; } try { gamesInfoClass.Tag = Convert.ToInt32(BinaryReaderOutput[9]); } catch { gamesInfoClass.Tag = LineNum; } GamesInfoClassList[LineNum] = gamesInfoClass; LineNum++; } BinaryReader.Dispose(); Properties.Settings.Default.SavedGamesIsReal = true; //MessageBox.Show("", "Yeap"); } catch { Properties.Settings.Default.SavedGamesIsReal = false; MessageBox.Show("", "Error SettingsSearch"); int i = 0; while (i != 99) { GamesInfoClassList[i] = new GamesInfoClass(); i++; } } } else { Properties.Settings.Default.SavedGamesIsReal = false; int i = 0; while (i != 99) { GamesInfoClassList[i] = new GamesInfoClass(); i++; } } }