private GameOnPc RetrieveGameInFolder(string folderPath) { GameOnPc game = null; var imageFiles = FileManager.GetImageFilesPathInFolder(folderPath); if (imageFiles.Count() > 1) { WriteError($"You have more than one GDI/CDI file in the folder {folderPath}. Please make sure you only have one GDI/CDI per folder."); CopyProgressBar.Value++; CopyProgressBar.Refresh(); return(null); } if (imageFiles.Any()) { try { game = GameManager.ExtractPcGameData(folderPath); } catch (Exception error) { WriteError(error.Message); CopyProgressBar.Value++; CopyProgressBar.Refresh(); return(null); } } CopyProgressBar.Value++; CopyProgressBar.Refresh(); return(game); }
private GameOnPc RetrieveGameInArchive(string compressedFilePath) { GameOnPc game = null; WriteInfo($"Checking archive {compressedFilePath}..."); IArchive archive; try { archive = ArchiveFactory.Open(new FileInfo(compressedFilePath)); } catch (Exception ex) { WriteError($"Could not open archive {compressedFilePath}. Error: {ex.Message}"); CopyProgressBar.Value += 10; CopyProgressBar.Refresh(); return(null); } if (ArchiveManager.RetreiveUniqueFileFromArchiveEndingWith(archive, ".gdi") == null) { WriteWarning($"Could not find GDI in archive {compressedFilePath} (CDI are ignored in archives)"); CopyProgressBar.Value += 10; CopyProgressBar.Refresh(); return(null); } else { try { if (archive.Type == SharpCompress.Common.ArchiveType.SevenZip && !viewModel.MustScanSevenZip) { WriteWarning($"Archive {compressedFilePath} ignored as it's a 7z file and the option isn't ticked."); CopyProgressBar.Value += 10; CopyProgressBar.Refresh(); return(null); } game = GameManager.ExtractPcGameDataFromArchive(compressedFilePath, archive); } catch (Exception ex) { WriteError(ex.Message); CopyProgressBar.Value += 10; CopyProgressBar.Refresh(); return(null); } } CopyProgressBar.Value += 10; CopyProgressBar.Refresh(); return(game); }
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; }