Skip to content

Commit

Permalink
character tool: do not attempt to read files if they do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilInTheGaps committed Jan 5, 2025
1 parent 1eed4f0 commit f633d50
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/tools/characters/charactertool.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "charactertool.h"
#include "filesystem/file.h"
#include "filesystem/results/filecheckresult.h"
#include "filesystem/results/filedataresult.h"
#include "filesystem/results/filelistresult.h"
#include "settings/settingsmanager.h"
Expand Down Expand Up @@ -115,8 +116,12 @@ void CharacterTool::loadData()
setIsDataLoaded(true);

const auto filePath = FileUtils::fileInDir(u"inactive.json"_s, SettingsManager::getPath(u"characters"_s));
Files::File::getDataAsync(filePath, Files::Option::AllowCache).then([this](const Files::FileDataResult &result) {
loadInactiveCharacters(result.data());

Files::File::checkAsync(filePath).then([this, filePath](const Files::FileCheckResult &checkResult) {
if (!checkResult.success() || !checkResult.exists()) return;

Files::File::getDataAsync(filePath, Files::Option::AllowCache)
.then([this](const Files::FileDataResult &result) { loadInactiveCharacters(result.data()); });
});
}

Expand Down Expand Up @@ -158,8 +163,14 @@ void CharacterTool::loadInactiveCharacters(const QByteArray &data)
<< "Inactive characters file data is empty, maybe old .ini file exists, trying to convert ...";

const auto filePath = FileUtils::fileInDir(u"settings.ini"_s, SettingsManager::getPath(u"characters"_s));
Files::File::getDataAsync(filePath, Files::Option::AllowCache)
.then([this](const Files::FileDataResult &result) { convertSettingsFile(result.data()); });

Files::File::checkAsync(filePath).then([this, filePath](const Files::FileCheckResult &checkResult) {
if (!checkResult.success() || !checkResult.exists()) return;

Files::File::getDataAsync(filePath, Files::Option::AllowCache)
.then([this](const Files::FileDataResult &result) { convertSettingsFile(result.data()); });
});

return;
}

Expand Down

0 comments on commit f633d50

Please sign in to comment.