private void LoadGamesOnSd() { IsSdCardMounted = CheckSdCardIsMountedAndInFat32(); if (!IsSdCardMounted) { return; } var sdCardManager = new SdCardManager(SdFolderComboBox.SelectedItem as string); try { gamesOnSdCard = sdCardManager.GetGames(out List <string> errors); if (errors.Any()) { foreach (var error in errors) { WriteError(error); } } SdFolderComboBox.BorderBrush = Brushes.LightGray; } catch (FileNotFoundException e) { WriteError(e.Message); IsScanSuccessful = false; SdFolderComboBox.BorderBrush = Brushes.Red; gamesOnSdCard = new List <GameOnSd>(); return; } catch (Exception ex) { WriteError(ex.Message); } finally { UpdatePcFoldersIsInSdCard(); } long freeSpace = sdCardManager.GetFreeSpace(); SdSpaceLabel.Content = FileManager.FormatSize(freeSpace); WriteSuccess("Games on SD scanned"); }
public async Task CopySelectedGames() { var sdCardManager = new SdCardManager(viewModel.SdDrive); var gamesToCopy = viewModel.GamesOnPc .Where(i => i.MustBeOnSd && (!i.IsInSdCard || i.MustShrink)); WriteInfo($"Copying {gamesToCopy.Count()} game(s) to SD card..."); CopyProgressLabel.Visibility = Visibility.Visible; CopyProgressBar.Maximum = gamesToCopy.Count(); CopyProgressBar.Value = 0; CopyProgressBar.Visibility = Visibility.Visible; CopyProgressBar.Refresh(); short index = 2; foreach (GameOnPc selectedItem in gamesToCopy) { WriteInfo($"Copying {selectedItem.GameName} {selectedItem.Disc}..."); if (!string.IsNullOrEmpty(selectedItem.SdFolder)) { index = short.Parse(Path.GetFileName(selectedItem.SdFolder)); } else { try { index = sdCardManager.FindAvailableFolderForGame(index); } catch (Exception e) { WriteError("Error while trying to find an available folder to copy games: " + e.Message); CopyProgressBar.Value++; CopyProgressBar.Refresh(); continue; } if (index == -1) { WriteError($"You cannot have more than 9999 games on your SD card."); CopyProgressBar.Value = CopyProgressBar.Maximum; break; } } try { await sdCardManager.AddGame(selectedItem, index); CopyProgressBar.Value++; CopyProgressBar.Refresh(); WriteInfo($"{CopyProgressBar.Value}/{gamesToCopy.Count()} games copied"); } catch (Exception error) { string messageBoxText = error.Message; string caption = "Error"; MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.Warning; MessageBox.Show(messageBoxText, caption, button, icon); WriteError(error.Message); CopyProgressBar.Value++; CopyProgressBar.Refresh(); } } if (CopyProgressBar.Value < gamesToCopy.Count()) { WriteInfo($"There was an error. {CopyProgressBar.Value} games were copied."); } else { WriteSuccess($"Games copied"); } CloseButton.IsEnabled = true; }
private async Task CopySelectedGames() { var sdCardManager = new SdCardManager(SdFolderComboBox.SelectedItem as string); var gamesToCopy = PcFoldersWithGdiListView.Items.Cast <GameOnPc>().Where(i => i.MustCopy); WriteInfo($"Copying {gamesToCopy.Count()} game(s) to SD card..."); CopyProgressLabel.Visibility = Visibility.Visible; CopyProgressBar.Maximum = gamesToCopy.Count(); CopyProgressBar.Value = 0; CopyProgressBar.Visibility = Visibility.Visible; short index = 2; foreach (GameOnPc selectedItem in gamesToCopy) { WriteInfo($"Copying {selectedItem.GameName} {selectedItem.Disc}..."); if (!string.IsNullOrEmpty(selectedItem.SdFolder)) { index = short.Parse(Path.GetFileName(selectedItem.SdFolder)); } else { try { index = sdCardManager.FindAvailableFolderForGame(index); } catch (Exception e) { WriteError("Error while trying to find an available folder to copy games: " + e.Message); } if (index == -1) { WriteError($"You cannot have more than 9999 games on your SD card."); break; } } try { await sdCardManager.AddGame(selectedItem, index); CopyProgressBar.Value++; WriteInfo($"{CopyProgressBar.Value}/{gamesToCopy.Count()} games copied"); } catch (Exception error) { string messageBoxText = error.Message; string caption = "Error"; MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.Warning; MessageBox.Show(messageBoxText, caption, button, icon); WriteError(error.Message); } } if (CopyProgressBar.Value < gamesToCopy.Count()) { WriteInfo($"There was an error. {CopyProgressBar.Value} games were copied."); } else { WriteSuccess($"Games copied"); } }