a few fixes to prevent crash

This commit is contained in:
Skarn
2021-12-25 18:54:24 +03:00
parent 595a4c2fcd
commit 8d4ccad024
2 changed files with 19 additions and 11 deletions

View File

@@ -58,7 +58,7 @@ namespace Noggit::Project
public:
ApplicationProjectReader() = default;
NoggitProject ReadProject(std::filesystem::path const& projectPath)
std::optional<NoggitProject> ReadProject(std::filesystem::path const& projectPath)
{
for (const auto& entry : std::filesystem::directory_iterator(projectPath))
{
@@ -109,6 +109,8 @@ namespace Noggit::Project
return project;
}
}
return {};
}
};
@@ -245,33 +247,35 @@ namespace Noggit::Project
auto projectReader = ApplicationProjectReader();
auto project = projectReader.ReadProject(projectPath);
assert (project.has_value());
std::string dbcFileDirectory = (projectPath / "workspace" / "DBFilesClient").generic_string();
std::string dbdFileDirectory = _configuration->ApplicationDatabaseDefinitionsPath;
auto clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
auto clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
auto clientArchiveLocale = BlizzardArchive::Locale::AUTO;
if (project.ProjectVersion == ProjectVersion::SL)
if (project->ProjectVersion == ProjectVersion::SL)
{
clientArchiveVersion = BlizzardArchive::ClientVersion::SL;
clientBuild = BlizzardDatabaseLib::Structures::Build("9.1.0.39584");
clientArchiveLocale = BlizzardArchive::Locale::enUS;
}
if (project.ProjectVersion == ProjectVersion::WOTLK)
if (project->ProjectVersion == ProjectVersion::WOTLK)
{
clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
clientArchiveLocale = BlizzardArchive::Locale::AUTO;
}
project.ClientDatabase = std::make_shared<BlizzardDatabaseLib::BlizzardDatabase>(
project->ClientDatabase = std::make_shared<BlizzardDatabaseLib::BlizzardDatabase>(
dbcFileDirectory, dbdFileDirectory, clientBuild);
project.ClientData = std::make_shared<BlizzardArchive::ClientData>(
project.ClientPath, clientArchiveVersion, clientArchiveLocale, std::string(""));
project->ClientData = std::make_shared<BlizzardArchive::ClientData>(
project->ClientPath, clientArchiveVersion, clientArchiveLocale, std::string(""));
return std::make_shared<NoggitProject>(project);
return std::make_shared<NoggitProject>(project.value());
}
};
}

View File

@@ -81,14 +81,18 @@ namespace Noggit::Ui::Windows
auto applicationConfiguration = _noggitApplication->GetConfiguration();
for (const auto& dirEntry : std::filesystem::directory_iterator(applicationConfiguration->ApplicationProjectPath))
{
auto item = new QListWidgetItem(ui->listView);
auto projectReader = Noggit::Project::ApplicationProjectReader();
auto project = projectReader.ReadProject(dirEntry);
if (!project.has_value())
continue;
auto item = new QListWidgetItem(ui->listView);
auto projectData = Noggit::Ui::Component::ProjectListItemData();
projectData.ProjectVersion = project.ProjectVersion;
projectData.ProjectVersion = project->ProjectVersion;
projectData.ProjectDirectory = QString::fromStdString(dirEntry.path().generic_string());
projectData.ProjectName = QString::fromStdString(project.ProjectName);
projectData.ProjectName = QString::fromStdString(project->ProjectName);
projectData.ProjectLastEdited = QDateTime::currentDateTime().date().toString();
auto projectListItem = new Noggit::Ui::Component::ProjectListItem(projectData, ui->listView);