mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 13:22:23 +08:00
+ Added better logging for asset loading errors and some extra information, should help get better information on #59
Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
a66bc26f1d
commit
20c4ad3652
@ -39,6 +39,8 @@ add_executable(
|
|||||||
wallengine
|
wallengine
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
|
src/WallpaperEngine/Assets/CAssetLoadException.cpp
|
||||||
|
src/WallpaperEngine/Assets/CAssetLoadException.h
|
||||||
src/WallpaperEngine/Assets/CContainer.h
|
src/WallpaperEngine/Assets/CContainer.h
|
||||||
src/WallpaperEngine/Assets/CContainer.cpp
|
src/WallpaperEngine/Assets/CContainer.cpp
|
||||||
src/WallpaperEngine/Assets/CCombinedContainer.h
|
src/WallpaperEngine/Assets/CCombinedContainer.h
|
||||||
|
3
main.cpp
3
main.cpp
@ -151,10 +151,12 @@ int main (int argc, char* argv[])
|
|||||||
|
|
||||||
// add the package to the list
|
// add the package to the list
|
||||||
containers->add (new WallpaperEngine::Assets::CPackage (scene_path));
|
containers->add (new WallpaperEngine::Assets::CPackage (scene_path));
|
||||||
|
std::cout << "Detected scene.pkg file at " << scene_path << ". Adding to list of searchable paths" << std::endl;
|
||||||
}
|
}
|
||||||
catch(std::filesystem::filesystem_error ex)
|
catch(std::filesystem::filesystem_error ex)
|
||||||
{
|
{
|
||||||
// ignore this error, the package file was not found
|
// ignore this error, the package file was not found
|
||||||
|
std::cout << "No scene.pkg file found at " << path << ". Defaulting to normal folder storage" << std::endl;
|
||||||
}
|
}
|
||||||
catch (std::runtime_error ex)
|
catch (std::runtime_error ex)
|
||||||
{
|
{
|
||||||
@ -208,7 +210,6 @@ int main (int argc, char* argv[])
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (project->getType () == "scene")
|
if (project->getType () == "scene")
|
||||||
{
|
{
|
||||||
WallpaperEngine::Core::CScene* scene = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> ();
|
WallpaperEngine::Core::CScene* scene = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> ();
|
||||||
|
14
src/WallpaperEngine/Assets/CAssetLoadException.cpp
Normal file
14
src/WallpaperEngine/Assets/CAssetLoadException.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "CAssetLoadException.h"
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Assets;
|
||||||
|
|
||||||
|
CAssetLoadException::CAssetLoadException(const std::string& filename, const std::string& extrainfo)
|
||||||
|
: m_message("Cannot find file " + filename + ": " + extrainfo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *CAssetLoadException::what() const noexcept
|
||||||
|
{
|
||||||
|
return this->m_message.c_str ();
|
||||||
|
}
|
17
src/WallpaperEngine/Assets/CAssetLoadException.h
Normal file
17
src/WallpaperEngine/Assets/CAssetLoadException.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Assets
|
||||||
|
{
|
||||||
|
class CAssetLoadException : public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CAssetLoadException(const std::string& filename, const std::string& extrainfo = "");
|
||||||
|
const char* what() const noexcept override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_message;
|
||||||
|
};
|
||||||
|
};
|
@ -1,4 +1,5 @@
|
|||||||
#include "CCombinedContainer.h"
|
#include "CCombinedContainer.h"
|
||||||
|
#include "CAssetLoadException.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
|
|
||||||
@ -20,12 +21,12 @@ void* CCombinedContainer::readFile (std::string filename, uint32_t* length)
|
|||||||
// an exception will be thrown
|
// an exception will be thrown
|
||||||
return (*cur)->readFile (filename, length);
|
return (*cur)->readFile (filename, length);
|
||||||
}
|
}
|
||||||
catch (std::exception& ex)
|
catch (CAssetLoadException& ex)
|
||||||
{
|
{
|
||||||
// not found in this container, next try
|
// not found in this container, next try
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no container was able to load the file, abort!
|
// no container was able to load the file, abort!
|
||||||
throw std::runtime_error ("Cannot find the file in any of the containers");
|
throw CAssetLoadException (filename, "Cannot find file in any of the containers");
|
||||||
}
|
}
|
@ -1,10 +1,21 @@
|
|||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "CDirectory.h"
|
#include "CDirectory.h"
|
||||||
|
#include "CAssetLoadException.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
|
|
||||||
CDirectory::CDirectory (std::string basepath) :
|
CDirectory::CDirectory (std::string basepath) :
|
||||||
m_basepath (std::move (basepath))
|
m_basepath (std::move (basepath))
|
||||||
{
|
{
|
||||||
|
// ensure the specified path exists
|
||||||
|
struct stat buffer;
|
||||||
|
|
||||||
|
if (stat (this->m_basepath.c_str (), &buffer) != 0)
|
||||||
|
throw std::runtime_error ("Cannot find " + this->m_basepath + ". This folder is required for wallpaper engine to work");
|
||||||
|
|
||||||
|
if (!S_ISDIR(buffer.st_mode))
|
||||||
|
throw std::runtime_error ("Cannot find " + this->m_basepath + ". There's an assets file in it's place");
|
||||||
}
|
}
|
||||||
|
|
||||||
CDirectory::~CDirectory ()
|
CDirectory::~CDirectory ()
|
||||||
@ -30,7 +41,7 @@ void* CDirectory::readFile (std::string filename, uint32_t* length)
|
|||||||
FILE* fp = fopen (final.c_str (), "rb");
|
FILE* fp = fopen (final.c_str (), "rb");
|
||||||
|
|
||||||
if (fp == nullptr)
|
if (fp == nullptr)
|
||||||
throw std::runtime_error ("Cannot find requested file");
|
throw CAssetLoadException(filename, "Cannot find file");
|
||||||
|
|
||||||
// go to the end, get the position and return to the beginning
|
// go to the end, get the position and return to the beginning
|
||||||
fseek (fp, 0, SEEK_END);
|
fseek (fp, 0, SEEK_END);
|
||||||
@ -43,7 +54,7 @@ void* CDirectory::readFile (std::string filename, uint32_t* length)
|
|||||||
if (fread (contents, size, 1, fp) != 1)
|
if (fread (contents, size, 1, fp) != 1)
|
||||||
{
|
{
|
||||||
delete[] contents;
|
delete[] contents;
|
||||||
throw std::runtime_error ("Unexpected error when reading the file");
|
throw CAssetLoadException (filename, "Unexpected error when reading the file");
|
||||||
}
|
}
|
||||||
|
|
||||||
// store it in the cache too
|
// store it in the cache too
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "CPackage.h"
|
#include "CPackage.h"
|
||||||
|
#include "CAssetLoadException.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@ -40,7 +41,7 @@ void* CPackage::readFile (std::string filename, uint32_t* length)
|
|||||||
auto it = this->m_contents.find (filename);
|
auto it = this->m_contents.find (filename);
|
||||||
|
|
||||||
if (it == this->m_contents.end ())
|
if (it == this->m_contents.end ())
|
||||||
throw std::runtime_error ("Cannot find file in file list");
|
throw CAssetLoadException(filename, "Cannot find the file in the package");
|
||||||
|
|
||||||
// set file length if required
|
// set file length if required
|
||||||
if (length != nullptr)
|
if (length != nullptr)
|
||||||
|
Loading…
Reference in New Issue
Block a user