Skip to content

Commit f07bdb1

Browse files
Merge pull request #639 from g-maxime/ro-home
Print error if data directory isn't writable
2 parents c6aaffd + 66f8b10 commit f07bdb1

7 files changed

Lines changed: 40 additions & 9 deletions

File tree

Source/CLI/CLI.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ void Log_0(struct MediaInfo_Event_Log_0* Event)
123123

124124
// If no Implementation Schema registered, use one by default
125125
if (!MCL.get_implementation_schema_file().length())
126-
MCL.create_default_implementation_schema();
126+
{
127+
if (MCL.create_default_implementation_schema(err) != 0)
128+
{
129+
if (err == "Unable to write implementation schema file.")
130+
err += " Check write permissions on MediaConch data directory.";
131+
return CLI_RETURN_ERROR;
132+
}
133+
}
127134

128135
if (!MCL.ReportAndFormatCombination_IsValid(files, report_set, display_content,
129136
format, err))

Source/Common/Core.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const std::string& Core::get_implementation_schema_file()
224224
}
225225

226226
//---------------------------------------------------------------------------
227-
void Core::create_default_implementation_schema()
227+
int Core::create_default_implementation_schema(std::string& err)
228228
{
229229
std::string path = get_local_data_path();
230230
std::string file = path + "MatroskaSchema.xml";
@@ -233,12 +233,17 @@ void Core::create_default_implementation_schema()
233233
ofs.open(file.c_str(), std::ofstream::out | std::ofstream::binary);
234234

235235
if (!ofs.is_open())
236-
return;
236+
{
237+
err = "Unable to write implementation schema file.";
238+
return -1;
239+
}
237240

238241
ofs << xsl_schema_matroska_schema;
239242
ofs.close();
240243

241244
set_implementation_schema_file(file);
245+
246+
return 0;
242247
}
243248

244249
//---------------------------------------------------------------------------

Source/Common/Core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class Core
160160
const std::map<std::string, std::string>& get_implementation_options() const;
161161
void set_implementation_schema_file(const std::string& file);
162162
const std::string& get_implementation_schema_file();
163-
void create_default_implementation_schema();
163+
int create_default_implementation_schema(std::string& err);
164164
void set_implementation_verbosity(const std::string& verbosity);
165165
const std::string& get_implementation_verbosity();
166166
void set_compression_mode(MediaConchLib::compression compress);

Source/Common/MediaConchLib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,9 @@ const std::string& MediaConchLib::get_implementation_schema_file()
733733
}
734734

735735
//---------------------------------------------------------------------------
736-
void MediaConchLib::create_default_implementation_schema()
736+
int MediaConchLib::create_default_implementation_schema(std::string& err)
737737
{
738-
core->create_default_implementation_schema();
738+
return core->create_default_implementation_schema(err);
739739
}
740740

741741
//---------------------------------------------------------------------------

Source/Common/MediaConchLib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class MediaConchLib
369369
// Implementation checker arguments
370370
void set_implementation_schema_file(const std::string& file);
371371
const std::string& get_implementation_schema_file();
372-
void create_default_implementation_schema();
372+
int create_default_implementation_schema(std::string& err);
373373
void set_implementation_verbosity(const std::string& verbosity);
374374
const std::string& get_implementation_verbosity();
375375

Source/Daemon/Daemon.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ namespace MediaConch
7373

7474
// If no Implementation Schema registered, use one by default
7575
if (!MCL->get_implementation_schema_file().length())
76-
MCL->create_default_implementation_schema();
76+
{
77+
if (MCL->create_default_implementation_schema(err) != 0)
78+
{
79+
std::clog << err << std::endl;
80+
return -1;
81+
}
82+
}
7783

7884
// Load policy
7985
MCL->load_system_policy();

Source/GUI/Qt/mainwindow.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,20 @@ MainWindow::MainWindow(QWidget *parent) :
8989

9090
// Core configuration
9191
if (!MCL.get_implementation_schema_file().length())
92-
MCL.create_default_implementation_schema();
92+
{
93+
if (MCL.create_default_implementation_schema(err) != 0)
94+
{
95+
if (err == "Unable to write implementation schema file.")
96+
err += "\nCheck write permissions on MediaConch data directory.";
97+
98+
QMessageBox msgBox(QMessageBox::Critical, tr("Initialisation error"),
99+
QString().fromStdString(err), QMessageBox::Abort, parent);
100+
101+
msgBox.exec();
102+
close();
103+
}
104+
}
105+
93106
int nb_threads=QThread::idealThreadCount();
94107
if (nb_threads!=-1)
95108
MCL.set_default_scheduler_max_threads(nb_threads);

0 commit comments

Comments
 (0)