public async static Task CreateMenuWithoutIndex(string destinationFolder) { var tempPath = @".\menu_tools_and_files\temp_content"; if (Directory.Exists(tempPath)) { FileManager.RemoveAllFilesInDirectory(tempPath); } else { Directory.CreateDirectory(tempPath); } string tempListIniPath = tempPath + @"\LIST.INI"; await FileManager.CopyDirectoryContentToAnother(@".\menu_tools_and_files\content", tempPath, false); File.Delete(tempListIniPath); var commandResult = await Command .Run(@".\menu_tools_and_files\mkisofs.exe", "-C", "0,11702", "-V", "GDMENU", "-G", @".\menu_tools_and_files\ip.bin", "-l", "-o", @".\menu_tools_and_files\disc.iso", tempPath) .Task; var commandResult2 = await Command .Run(@".\menu_tools_and_files\cdi4dc.exe", @".\menu_tools_and_files\disc.iso", @".\menu_tools_and_files\disc.cdi") .Task; File.Move(@".\menu_tools_and_files\disc.cdi", Path.Combine(destinationFolder, @"01\disc.cdi"), true); }
public async Task AddGame(GameOnPc game, short destinationFolderIndex) { string format = GetGdemuFolderNameFromIndex(destinationFolderIndex); string destinationFolder = Path.GetFullPath(DrivePath + destinationFolderIndex.ToString(format)); if (game.MustShrink) { if (Directory.Exists(destinationFolder)) { FileManager.RemoveAllFilesInDirectory(destinationFolder); } else { Directory.CreateDirectory(destinationFolder); } var oldGdiPath = Directory.EnumerateFiles(game.FullPath).Single(f => Path.GetExtension(f) == ".gdi"); //var commandResult = await Command // .Run(@".\gditools\dist\gditools_messily_tweaked.exe", oldGdiPath, destinationFolder) // .Task; var cts = new CancellationTokenSource(); cts.CancelAfter(TimeSpan.FromMinutes(2)); Command command = null; try { command = Command.Run(@".\gditools\dist\gditools_messily_tweaked.exe", oldGdiPath, destinationFolder); await command.Task.WaitOrCancel(cts.Token); } catch (OperationCanceledException ex) { if (command != null) { command.Kill(); } throw new OperationCanceledException($"Timeout while shrinking {game.GameName}. You might need to copy it without shrinking."); } //if (!commandResult.Success) //{ // // There is always an error even if it's working, need find out why // //throw new System.Exception("There was an error while shriking the GDI: " + commandResult.StandardError); //} var gdiPath = Directory.EnumerateFiles(destinationFolder).SingleOrDefault(f => Path.GetExtension(f) == ".gdi"); if (gdiPath == null) { throw new OperationCanceledException($"Could not shrink {game.GameName}. You might need to copy it without shrinking."); } var newGdi = GameManager.GetGdiFromFile(gdiPath); File.Delete(gdiPath); newGdi.SaveTo(Path.Combine(destinationFolder, "disc.gdi"), true); newGdi.RenameTrackFiles(destinationFolder); } else { await FileManager.CopyDirectoryContentToAnother(game.FullPath, destinationFolder, true); var gdiPath = Directory.EnumerateFiles(destinationFolder).Single(f => Path.GetExtension(f) == ".gdi"); var newGdi = GameManager.GetGdiFromFile(gdiPath); File.Delete(gdiPath); newGdi.SaveTo(Path.Combine(destinationFolder, "disc.gdi"), true); newGdi.RenameTrackFiles(destinationFolder); } }
public async static Task CreateIndex(string destinationFolder, IEnumerable <GameOnSd> gamesToIndex) { if (!Directory.Exists(Path.Combine(destinationFolder, @"01\disc.cdi"))) { Directory.CreateDirectory(Path.Combine(destinationFolder, @"01")); } var sdFolders = Directory.EnumerateDirectories(destinationFolder); foreach (var folder in sdFolders.Where(f => Path.GetFileName(f) != "01" && int.TryParse(Path.GetFileName(f), out int _))) { if (Directory.Exists(folder + "_")) { Directory.Delete(folder + "_", true); } Directory.Move(folder, folder + "_"); } var tempPath = @".\menu_tools_and_files\temp_content"; if (Directory.Exists(tempPath)) { FileManager.RemoveAllFilesInDirectory(tempPath); } else { Directory.CreateDirectory(tempPath); } string tempListIniPath = tempPath + @"\LIST.INI"; await FileManager.CopyDirectoryContentToAnother(@".\menu_tools_and_files\content", tempPath, false); for (short i = 2; i <= gamesToIndex.Count() + 1; i++) { var game = gamesToIndex.OrderBy(g => g.GameName).ElementAt(i - 2); string index = i.ToString(SdCardManager.GetGdemuFolderNameFromIndex(i)); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{ index}.name={game.GameName}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.disc={game.FormattedDiscNumber}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.vga=1"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.region={game.Region}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.version={game.ProductV}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.date={game.ReleaseDate}"); string newPath = Path.Combine(destinationFolder, index); if (!game.FullPath.Contains("_")) { Directory.Move(game.FullPath + "_", newPath); } else { Directory.Move(game.FullPath, newPath); } File.Create(Path.Combine(newPath, "name.txt")).Close(); File.AppendAllText(Path.Combine(newPath, "name.txt"), game.GameName); } for (int i = 0; i <= 2; i++) { File.AppendAllText(tempListIniPath, Environment.NewLine); } await Command .Run(@".\menu_tools_and_files\mkisofs.exe", "-C", "0,11702", "-V", "GDMENU", "-G", @".\menu_tools_and_files\ip.bin", "-l", "-o", @".\menu_tools_and_files\disc.iso", tempPath) .Task; await Command .Run(@".\menu_tools_and_files\cdi4dc.exe", @".\menu_tools_and_files\disc.iso", @".\menu_tools_and_files\disc.cdi") .Task; File.Move(@".\menu_tools_and_files\disc.cdi", Path.Combine(destinationFolder, @"01\disc.cdi"), true); File.Move(Path.Combine(tempPath, @"readme.txt"), Path.Combine(destinationFolder, @"01\readme.txt"), true); FileManager.RemoveAllFilesInDirectory(tempPath); }
public async static Task CreateIndex(string destinationFolder, IEnumerable <GameOnSd> gamesToIndex) { if (!Directory.Exists(Path.Combine(destinationFolder, @"01\disc.cdi"))) { Directory.CreateDirectory(Path.Combine(destinationFolder, @"01")); } var sdFolders = Directory.EnumerateDirectories(destinationFolder); foreach (var folder in sdFolders.Where(f => Path.GetFileName(f).Contains("_") && !Directory.EnumerateFileSystemEntries(f).Any())) { Directory.Delete(folder); } var tempPath = @".\menu_tools_and_files\temp_content"; string tempListIniPath = tempPath + @"\LIST.INI"; try { foreach (var folder in sdFolders.Where(f => Path.GetFileName(f) != "01" && !Path.GetFileName(f).Contains("_") && int.TryParse(Path.GetFileName(f), out int _))) { if (Directory.Exists(folder + "_")) { throw new Exception("The SD is populated with non-empty folders with underscore (_) in them. This might be temp folders created by the tool in a previous index creation. Please check manually what they contain and rename them with a correct name (01, 02, 03,... 999)."); } Directory.Move(folder, folder + "_"); } if (Directory.Exists(tempPath)) { FileManager.RemoveAllFilesInDirectory(tempPath); } else { Directory.CreateDirectory(tempPath); } await FileManager.CopyDirectoryContentToAnother(@".\menu_tools_and_files\content", tempPath, false); for (short i = 2; i <= gamesToIndex.Count(g => g.GameName != "GDMENU") + 1; i++) { var game = gamesToIndex.Where(g => g.GameName != "GDMENU").OrderBy(g => g.GameName).ElementAt(i - 2); string index = i.ToString(SdCardManager.GetGdemuFolderNameFromIndex(i)); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{ index}.name={game.GameName}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.disc={game.FormattedDiscNumber}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.vga=1"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.region={game.Region}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.version={game.ProductV}"); File.AppendAllText(tempListIniPath, Environment.NewLine); File.AppendAllText(tempListIniPath, $"{index}.date={game.ReleaseDate}"); string newPath = Path.Combine(destinationFolder, index); Directory.Move(game.FullPath + "_", newPath); File.Create(Path.Combine(newPath, "name.txt")).Close(); File.AppendAllText(Path.Combine(newPath, "name.txt"), game.GameName); } } catch { var sdFoldersWithUnderscore = Directory.EnumerateDirectories(destinationFolder).Where(f => Path.GetFileName(f).Contains("_")); foreach (var folderWithUnderscore in sdFoldersWithUnderscore) { Directory.Move(folderWithUnderscore, folderWithUnderscore.Replace("_", string.Empty)); } throw; } for (int i = 0; i <= 2; i++) { File.AppendAllText(tempListIniPath, Environment.NewLine); } await Command .Run(@".\menu_tools_and_files\mkisofs.exe", "-C", "0,11702", "-V", "GDMENU", "-G", @".\menu_tools_and_files\ip.bin", "-l", "-o", @".\menu_tools_and_files\disc.iso", tempPath) .Task; await Command .Run(@".\menu_tools_and_files\cdi4dc.exe", @".\menu_tools_and_files\disc.iso", @".\menu_tools_and_files\disc.cdi") .Task; File.Move(@".\menu_tools_and_files\disc.cdi", Path.Combine(destinationFolder, @"01\disc.cdi"), true); File.Move(Path.Combine(tempPath, @"readme.txt"), Path.Combine(destinationFolder, @"01\readme.txt"), true); FileManager.RemoveAllFilesInDirectory(tempPath); }