Skip to content

Commit

Permalink
Merge pull request #639 from g-maxime/ro-home
Browse files Browse the repository at this point in the history
Print error if data directory isn't writable
  • Loading branch information
JeromeMartinez authored Mar 7, 2018
2 parents c6aaffd + 66f8b10 commit f07bdb1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
9 changes: 8 additions & 1 deletion Source/CLI/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ void Log_0(struct MediaInfo_Event_Log_0* Event)

// If no Implementation Schema registered, use one by default
if (!MCL.get_implementation_schema_file().length())
MCL.create_default_implementation_schema();
{
if (MCL.create_default_implementation_schema(err) != 0)
{
if (err == "Unable to write implementation schema file.")
err += " Check write permissions on MediaConch data directory.";
return CLI_RETURN_ERROR;
}
}

if (!MCL.ReportAndFormatCombination_IsValid(files, report_set, display_content,
format, err))
Expand Down
9 changes: 7 additions & 2 deletions Source/Common/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const std::string& Core::get_implementation_schema_file()
}

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

if (!ofs.is_open())
return;
{
err = "Unable to write implementation schema file.";
return -1;
}

ofs << xsl_schema_matroska_schema;
ofs.close();

set_implementation_schema_file(file);

return 0;
}

//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Core
const std::map<std::string, std::string>& get_implementation_options() const;
void set_implementation_schema_file(const std::string& file);
const std::string& get_implementation_schema_file();
void create_default_implementation_schema();
int create_default_implementation_schema(std::string& err);
void set_implementation_verbosity(const std::string& verbosity);
const std::string& get_implementation_verbosity();
void set_compression_mode(MediaConchLib::compression compress);
Expand Down
4 changes: 2 additions & 2 deletions Source/Common/MediaConchLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,9 @@ const std::string& MediaConchLib::get_implementation_schema_file()
}

//---------------------------------------------------------------------------
void MediaConchLib::create_default_implementation_schema()
int MediaConchLib::create_default_implementation_schema(std::string& err)
{
core->create_default_implementation_schema();
return core->create_default_implementation_schema(err);
}

//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/MediaConchLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class MediaConchLib
// Implementation checker arguments
void set_implementation_schema_file(const std::string& file);
const std::string& get_implementation_schema_file();
void create_default_implementation_schema();
int create_default_implementation_schema(std::string& err);
void set_implementation_verbosity(const std::string& verbosity);
const std::string& get_implementation_verbosity();

Expand Down
8 changes: 7 additions & 1 deletion Source/Daemon/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ namespace MediaConch

// If no Implementation Schema registered, use one by default
if (!MCL->get_implementation_schema_file().length())
MCL->create_default_implementation_schema();
{
if (MCL->create_default_implementation_schema(err) != 0)
{
std::clog << err << std::endl;
return -1;
}
}

// Load policy
MCL->load_system_policy();
Expand Down
15 changes: 14 additions & 1 deletion Source/GUI/Qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,20 @@ MainWindow::MainWindow(QWidget *parent) :

// Core configuration
if (!MCL.get_implementation_schema_file().length())
MCL.create_default_implementation_schema();
{
if (MCL.create_default_implementation_schema(err) != 0)
{
if (err == "Unable to write implementation schema file.")
err += "\nCheck write permissions on MediaConch data directory.";

QMessageBox msgBox(QMessageBox::Critical, tr("Initialisation error"),
QString().fromStdString(err), QMessageBox::Abort, parent);

msgBox.exec();
close();
}
}

int nb_threads=QThread::idealThreadCount();
if (nb_threads!=-1)
MCL.set_default_scheduler_max_threads(nb_threads);
Expand Down

0 comments on commit f07bdb1

Please sign in to comment.