1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        ProcessFormatDvd.cpp
3 // Author:      Alex Thuering
4 // Created:     3.10.2014 (refactored)
5 // RCS-ID:      $Id: ProcessFormatDvd.cpp,v 1.4 2015/11/29 17:29:29 ntalex Exp $
6 // Copyright:   (c) Alex Thuering
7 // Licence:     GPL
8 /////////////////////////////////////////////////////////////////////////////
9 
10 #include "ProcessFormatDvd.h"
11 #include "BurnDlg.h"
12 #include "ProgressDlg.h"
13 #include "Config.h"
14 #include "SysUtils.h"
15 #include <wx/msgdlg.h>
16 
17 /** Constructor */
ProcessFormatDvd(ProgressDlg * progressDlg,BurnDlg * burnDlg)18 ProcessFormatDvd::ProcessFormatDvd(ProgressDlg* progressDlg, BurnDlg* burnDlg): Process(progressDlg) {
19 	this->burnDlg = burnDlg;
20 }
21 
22 /** Returns true, if process need be executed */
IsNeedExecute()23 bool ProcessFormatDvd::IsNeedExecute() {
24 	return burnDlg->DoBurn() && burnDlg->DoFormat();
25 }
26 
27 /** Executes process */
Execute()28 bool ProcessFormatDvd::Execute() {
29 	if (!burnDlg->DoBurn() || !burnDlg->DoFormat())
30 		return true;
31 	if (progressDlg->WasCanceled())
32 		return false;
33 	progressDlg->AddSummaryMsg(_("Formatting DVD-RW"));
34 	while (1) {
35 		progressDlg->SetSubSteps(100);
36 		wxString cmd = s_config.GetFormatCmd();
37 		wxString device = burnDlg->GetDevice();
38 #ifdef __WXMAC__
39 		if (device.Mid(0,5) != wxT("/dev/")) {
40 			while (!IsMediaPresent(device) || !IsMediaErasable(device)) {
41 				if (IsMediaBlank(device))
42 					return true;
43 				if (wxMessageBox(wxString::Format(_("Please insert a rewritable DVD into the device %s."),
44 						GetDeviceName(device).c_str()), _("Burn"), wxOK|wxCANCEL, progressDlg) == wxCANCEL) {
45 					progressDlg->AddSummaryMsg(_("Aborted"), wxEmptyString, *wxRED);
46 					return false;
47 				}
48 			}
49 		}
50 #endif
51 		cmd.Replace(wxT("$DEV"), device);
52 		if (!Exec(cmd)) {
53 			int repeat = wxMessageBox(_("Formatting DVD-RW failed. Try again?"), _("Burn"),
54 					wxYES_NO|wxCANCEL | wxICON_QUESTION, progressDlg);
55 			if (repeat == wxYES) {
56 				continue;
57 			} else if (repeat == wxNO) {
58 				progressDlg->AddSummaryMsg(_("-> skipped <-"), wxEmptyString, wxColour(128, 64, 64));
59 				break;
60 			} else {
61 				progressDlg->Failed();
62 				return false;
63 			}
64 		}
65 		break;
66 	}
67 	progressDlg->IncStep();
68 	return true;
69 }
70