public static void ImportGameZip(object sender, EventArgs e) { if (VerifyGameFolderPath()) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "Select a ZIP file containing the DOS game..."; dialog.Filter = "Zip Files (*.zip)|*.zip;*.exe"; if (dialog.ShowDialog(MainForm) == DialogResult.OK) { MainForm.Cursor = Cursors.WaitCursor; string tmpPath = Path.GetTempFileName(); File.Delete(tmpPath); Directory.CreateDirectory(tmpPath); try { ZipReader reader = new ZipReader(dialog.FileName); reader.ExtractTo(tmpPath, true); while (Directory.GetFiles(tmpPath).Length == 0 && Directory.GetDirectories(tmpPath).Length == 1) { tmpPath = Directory.GetDirectories(tmpPath)[0]; } string folderName = Path.GetFileNameWithoutExtension(dialog.FileName); string gamePath = Path.Combine(GameFolderPath, folderName); bool canMove = true; if (Directory.Exists(gamePath)) { DialogResult dialogResult = MessageBox.Show(MainForm, "Game Folder already exists, overwrite it?", "DosBlaster", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.Cancel) { canMove = false; } else { Directory.Delete(gamePath, true); } } if (canMove) { Directory.Move(tmpPath, gamePath); Game game = new Game(gamePath); game.Name = folderName; game.Category = "Not Set"; MessageBox.Show(MainForm, "Game Imported Successfully", "DosBlaster", MessageBoxButtons.OK); RemoveGameFromListView(game); ListViewItem item = AddGameToListView(game); item.EnsureVisible(); } } catch (Exception ex) { MessageBox.Show(MainForm, ex.Message, "DosBlaster", MessageBoxButtons.OK); if (Directory.Exists(tmpPath)) { Directory.Delete(tmpPath, true); } } MainForm.Cursor = Cursors.Default; } } }
public static void ImportDOS32AZip(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "Select a ZIP file containing DOS32A.exe..."; dialog.Filter = "Zip Files (*.zip)|*.zip"; if (dialog.ShowDialog(MainForm) == DialogResult.OK) { string tmpPath = Path.GetTempFileName(); File.Delete(tmpPath); Directory.CreateDirectory(tmpPath); try { ZipReader reader = new ZipReader(dialog.FileName); reader.ExtractTo(tmpPath, true); if (Directory.GetFiles(tmpPath, "dos32a.exe", System.IO.SearchOption.AllDirectories).Length >= 1) { string destPath = Path.Combine(Mediator.SysPath, "DOS32A"); if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } FileSystem.CopyDirectory(tmpPath, destPath, true); MessageBox.Show(MainForm, "DOS32A imported successfully.", "DosBlaster", MessageBoxButtons.OK); } else { MessageBox.Show(MainForm, "DOS32A.exe is not found in the ZIP archive.", "DosBlaster", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(MainForm, ex.Message, "DosBlaster", MessageBoxButtons.OK); } } }