refactor code and support utf8 strings rendering

This commit is contained in:
ohyzha
2024-08-02 23:08:24 +03:00
parent 875ad80337
commit 9589b4d39f
11 changed files with 70 additions and 30 deletions

View File

@@ -40,9 +40,13 @@ namespace OpenVulkano
}
}
Array<char> ResourceLoaderAppDirLinux::GetResource(const std::string& resourceName, std::string& resourcePath)
std::string ResourceLoaderAppDirLinux::GetResourcePath(const std::string& resourceName)
{
resourcePath = GetAppDir() + resourceName;
return Utils::ReadFile(resourcePath, true);
return GetAppDir() + resourceName;
}
Array<char> ResourceLoaderAppDirLinux::GetResource(const std::string& resourceName)
{
return Utils::ReadFile(resourceName, true);
}
}

View File

@@ -13,6 +13,7 @@ namespace OpenVulkano
class ResourceLoaderAppDirLinux final : public ResourceLoader
{
public:
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override;
std::string GetResourcePath(const std::string& resourceName) override;
Array<char> GetResource(const std::string& resourceName) override;
};
}

View File

@@ -15,13 +15,13 @@ namespace OpenVulkano
std::vector<std::unique_ptr<ResourceLoader>> m_loaders;
public:
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override
Array<char> GetResource(const std::string& resourceName) override
{
for(auto& loader : m_loaders)
{
try
{
auto res = loader->GetResource(resourceName, resourcePath);
auto res = loader->GetResource(resourceName);
if (!res.Empty()) return res;
}
catch (const std::exception& e)
@@ -54,6 +54,30 @@ namespace OpenVulkano
}
return false;
}
std::string GetResourcePath(const std::string& resourceName) override
{
try
{
for (auto& loader: m_loaders)
{
auto res = loader->GetResourcePath(resourceName);
if (!res.empty())
{
return res;
}
}
}
catch (const std::exception& e)
{
Logger::FILESYS->error("Error trying to get resource path for '{}'! Error: {}", resourceName, e.what());
}
catch (...)
{
Logger::FILESYS->error("Unknown error trying to get resource path for '{}'!", resourceName);
}
return "";
}
};
ResourceLoader& ResourceLoader::GetInstance()

View File

@@ -15,7 +15,9 @@ namespace OpenVulkano
public:
virtual ~ResourceLoader() = default;
virtual Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) = 0;
virtual Array<char> GetResource(const std::string& resourceName) = 0;
virtual std::string GetResourcePath(const std::string& resourceName) { return ""; }
static ResourceLoader& GetInstance();

View File

@@ -90,12 +90,11 @@ namespace OpenVulkano
return Array<char>(buffer);
}
Array<char> WebResourceLoader::GetResource(const std::string& resourceName, std::string& resourcePath)
Array<char> WebResourceLoader::GetResource(const std::string& resourceName)
{
if (IsUrl(resourceName))
{
std::filesystem::path cacheFilePath = GetCacheFilePath(resourceName);
resourcePath = resourceName;
if (std::filesystem::exists(cacheFilePath)) { return Utils::ReadFile(cacheFilePath.string()); }
else { return DownloadResource(resourceName); }
}

View File

@@ -24,6 +24,6 @@ namespace OpenVulkano
WebResourceLoader();
~WebResourceLoader();
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override;
Array<char> GetResource(const std::string& resourceName) override;
};
}

View File

@@ -38,9 +38,13 @@ namespace OpenVulkano
}
}
Array<char> ResourceLoaderAppDirWindows::GetResource(const std::string& resourceName, std::string& resourcePath)
std::string ResourceLoaderAppDirWindows::GetResourcePath(const std::string& resourceName)
{
resourcePath = GetAppDir() + resourceName;
return Utils::ReadFile(resourcePath);
return GetAppDir() + resourceName;
}
Array<char> ResourceLoaderAppDirWindows::GetResource(const std::string& resourceName)
{
return Utils::ReadFile(resourceName);
}
}

View File

@@ -13,6 +13,7 @@ namespace OpenVulkano
class ResourceLoaderAppDirWindows final : public ResourceLoader
{
public:
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override;
std::string GetResourcePath(const std::string& resourceName) override;
Array<char> GetResource(const std::string& resourceName) override;
};
}