From f633d50903272af3c945bbe7aef704d7d03cc593 Mon Sep 17 00:00:00 2001 From: Phil Hoffmann <18755316+PhilInTheGaps@users.noreply.github.com> Date: Sun, 5 Jan 2025 17:27:11 +0100 Subject: [PATCH] character tool: do not attempt to read files if they do not exist --- src/tools/characters/charactertool.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tools/characters/charactertool.cpp b/src/tools/characters/charactertool.cpp index a4dccd05..0cd9c4fa 100644 --- a/src/tools/characters/charactertool.cpp +++ b/src/tools/characters/charactertool.cpp @@ -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" @@ -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()); }); }); } @@ -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; }