1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        ProcessIsoImage.h
3 // Author:      Alex Thuering
4 // Created:     3.10.2014 (refactored)
5 // RCS-ID:      $Id: ProcessIsoImage.cpp,v 1.4 2016/12/11 10:34:21 ntalex Exp $
6 // Copyright:   (c) Alex Thuering
7 // Licence:     GPL
8 /////////////////////////////////////////////////////////////////////////////
9 
10 #include "ProcessIsoImage.h"
11 #include "ProcessExecute.h"
12 #include "BurnDlg.h"
13 #include "Cache.h"
14 #include "Config.h"
15 #include <wxVillaLib/utils.h>
16 #include <wx/filename.h>
17 
18 /** Constructor */
ProcessIsoImage(ProgressDlg * progressDlg,BurnDlg * burnDlg,DVD * dvd,Cache * cache,const wxString & dvdOutDir,const wxString & tmpDir)19 ProcessIsoImage::ProcessIsoImage(ProgressDlg* progressDlg, BurnDlg* burnDlg, DVD* dvd, Cache* cache,
20 		const wxString& dvdOutDir, const wxString& tmpDir): Process(progressDlg) {
21 	this->burnDlg = burnDlg;
22 	this->dvd = dvd;
23 	this->cache = cache;
24 	this->dvdOutDir = dvdOutDir;
25 	this->tmpDir = tmpDir;
26 }
27 
GetFreeSpaceOn(wxString dir)28 long GetFreeSpaceOn(wxString dir) {
29 	wxDiskspaceSize_t pFree;
30 	wxGetDiskSpace(dir, NULL, &pFree);
31 	return (long) (pFree.ToDouble() / 1024);
32 }
33 
34 /** Executes process */
Execute()35 bool ProcessIsoImage::Execute() {
36 	if (progressDlg->WasCanceled())
37 		return false;
38 	wxString isoFile = burnDlg->DoCreateIso() ? burnDlg->GetIsoFile() : tmpDir + TMP_ISO;
39 	// check if there is enough space
40 	long size = 0;
41 	wxString cmd = s_config.GetIsoSizeCmd();
42 	cmd.Replace(_T("$DIR"), dvdOutDir.Mid(0, dvdOutDir.length() - 1));
43 #if defined(__WXMSW__) || defined(__WXMAC__)
44 		cmd = wxGetAppPath() + wxString(wxFILE_SEP_PATH) + cmd;
45 #endif
46 	wxArrayString output;
47 	wxExecute(cmd, output, wxEXEC_SYNC | wxEXEC_NODISABLE);
48 	if (output.Count() > 0 && output[0].length() > 0) {
49 		output[0].ToLong(&size);
50 		size = (size + 254)*2;
51 	}
52 	long freeSpace = GetFreeSpaceOn(wxFileName(isoFile).GetPath());
53 	if (size > freeSpace && freeSpace == GetFreeSpaceOn(cache->GetTempDir())) {
54 		progressDlg->AddDetailMsg(_("There is not enough space to store ISO: cache emptying."));
55 		cache->Clear();
56 	}
57 	progressDlg->AddSummaryMsg(_("Creating ISO image"));
58 	progressDlg->SetSubSteps(100);
59 	cmd = s_config.GetIsoCmd();
60 	wxString label = dvd->GetLabel();
61 	label.Replace(wxT("\""), wxT("\\\""));
62 	cmd.Replace(_T("$VOL_ID"), label);
63 	cmd.Replace(_T("$DIR"), dvdOutDir.Mid(0, dvdOutDir.length() - 1));
64 	cmd.Replace(_T("$FILE"), isoFile);
65 	ProgressExecute exec(progressDlg, wxT(".*"));
66 	if (!exec.Execute(cmd)) {
67 		progressDlg->Failed();
68 		return false;
69 	}
70 	progressDlg->IncStep();
71 	return true;
72 }
73 
74 /** Returns true, if process need be executed */
IsNeedExecute()75 bool ProcessIsoImage::IsNeedExecute() {
76 #ifdef __WXMAC__
77 	return burnDlg->DoCreateIso() || burnDlg->DoBurn();
78 #else
79 	return burnDlg->DoCreateIso() || (burnDlg->DoBurn() && burnDlg->DoAddECC());
80 #endif
81 }
82