Show reason a file couldn't be loaded.

This commit is contained in:
Leonardo Zide 2019-03-10 13:41:21 -07:00
parent d0e411f0a5
commit d084d11b5a
3 changed files with 11 additions and 10 deletions

View file

@ -198,7 +198,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
QString ModelName; QString ModelName;
QString CameraName; QString CameraName;
QString ViewpointName; QString ViewpointName;
QString ProjectName = lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT) ? lcGetProfileString(LC_PROFILE_RECENT_FILE1) : QString(); QString ProjectName;
QString SaveWavefrontName; QString SaveWavefrontName;
QString Save3DSName; QString Save3DSName;
QString SaveCOLLADAName; QString SaveCOLLADAName;
@ -436,6 +436,9 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
Project* NewProject = new Project(); Project* NewProject = new Project();
SetProject(NewProject); SetProject(NewProject);
if (ShowWindow && ProjectName.isEmpty() && lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT))
ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1);
if (!ProjectName.isEmpty() && gMainWindow->OpenProject(ProjectName)) if (!ProjectName.isEmpty() && gMainWindow->OpenProject(ProjectName))
{ {
if (!ModelName.isEmpty()) if (!ModelName.isEmpty())

View file

@ -931,11 +931,6 @@ void lcMainWindow::ProjectFileChanged(const QString& Path)
RestoreTabLayout(TabLayout); RestoreTabLayout(TabLayout);
UpdateAllViews(); UpdateAllViews();
} }
else
{
QMessageBox::critical(this, tr("LeoCAD"), tr("Error loading '%1'.").arg(Path));
delete NewProject;
}
} }
else else
{ {
@ -2188,7 +2183,6 @@ bool lcMainWindow::OpenProject(const QString& FileName)
return true; return true;
} }
QMessageBox::critical(this, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName));
delete NewProject; delete NewProject;
return false; return false;
@ -2223,8 +2217,6 @@ void lcMainWindow::MergeProject()
UpdateModels(); UpdateModels();
} }
else
QMessageBox::critical(this, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName));
delete NewProject; delete NewProject;
} }

View file

@ -355,7 +355,10 @@ bool Project::Load(const QString& FileName)
QFile File(FileName); QFile File(FileName);
if (!File.open(QIODevice::ReadOnly)) if (!File.open(QIODevice::ReadOnly))
{
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error reading file '%1':\n%2").arg(FileName, File.errorString()));
return false; return false;
}
mModels.DeleteAll(); mModels.DeleteAll();
SetFileName(FileName); SetFileName(FileName);
@ -370,7 +373,7 @@ bool Project::Load(const QString& FileName)
else if (Extension == QLatin1String("lcd") || Extension == QLatin1String("leocad")) else if (Extension == QLatin1String("lcd") || Extension == QLatin1String("leocad"))
LoadDAT = false; LoadDAT = false;
else else
LoadDAT = memcmp(FileData, "LeoCAD ", 7); LoadDAT = FileData.size() > 7 && memcmp(FileData, "LeoCAD ", 7);
if (LoadDAT) if (LoadDAT)
{ {
@ -419,7 +422,10 @@ bool Project::Load(const QString& FileName)
} }
if (mModels.IsEmpty()) if (mModels.IsEmpty())
{
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error loading file '%1':\nFile format is not recognized.").arg(FileName));
return false; return false;
}
if (mModels.GetSize() == 1) if (mModels.GetSize() == 1)
{ {