Explorar o código

~ Better error handling to show relevant messages when a package load doesn't work
+ Added support for loading PKGV0014

Signed-off-by: Alexis Maiquez <almamu@almamu.com>

Alexis Maiquez %!s(int64=4) %!d(string=hai) anos
pai
achega
d041e6455e
Modificáronse 2 ficheiros con 16 adicións e 11 borrados
  1. 12 9
      main.cpp
  2. 4 2
      src/WallpaperEngine/Assets/CPackage.cpp

+ 12 - 9
main.cpp

@@ -7,11 +7,9 @@
 
 #include <GL/glew.h>
 #include <GL/glx.h>
+#include <filesystem>
 #include "GLFW/glfw3.h"
 
-#include <glm/glm.hpp>
-#include <glm/gtc/matrix_transform.hpp>
-
 #include "WallpaperEngine/Core/CProject.h"
 #include "WallpaperEngine/Render/CWallpaper.h"
 #include "WallpaperEngine/Render/CContext.h"
@@ -22,8 +20,6 @@
 #include "WallpaperEngine/Assets/CDirectory.h"
 #include "WallpaperEngine/Assets/CCombinedContainer.h"
 
-#include "WallpaperEngine/Core/Types/FloatColor.h"
-
 enum BACKGROUND_RUN_MODE
 {
     RUN_MODE_UNKNOWN = 0,
@@ -39,11 +35,11 @@ using namespace WallpaperEngine::Core::Types;
 void print_help (const char* route)
 {
     std::cout
-        << "Usage:" << route << " [options] " << std::endl
+        << "Usage:" << route << " [options] background_path" << std::endl
         << "options:" << std::endl
         << "  --silent\t\tMutes all the sound the wallpaper might produce" << std::endl
-        << "  --dir <folder>\tLoads an uncompressed background from the given <folder>" << std::endl
-        << "  --pkg <folder>\tLoads a scene.pkg file from the given <folder>" << std::endl
+        << "  --dir <folder>\tLoads an uncompressed background from the given <folder> [deprecated]" << std::endl
+        << "  --pkg <folder>\tLoads a scene.pkg file from the given <folder> [deprecated]" << std::endl
         << "  --screen-root <screen name>\tDisplay as screen's background" << std::endl
         << "  --fps <maximum-fps>\tLimits the FPS to the given number, useful to keep battery consumption low" << std::endl;
 }
@@ -158,10 +154,17 @@ int main (int argc, char* argv[])
         // add the package to the list
         containers->add (new WallpaperEngine::Assets::CPackage (scene_path));
     }
+    catch(std::filesystem::filesystem_error ex)
+    {
+        // ignore this error, the package file was not found
+    }
     catch (std::runtime_error ex)
     {
-        // ignore the exception, this is to be expected of normal backgrounds
+        // the package was found but there was an error loading it (wrong header or something)
+        fprintf (stderr, "Failed to load scene.pkg file: %s\n", ex.what());
+        return 4;
     }
+
     // add containers to the list
     containers->add (new WallpaperEngine::Assets::CDirectory ("./assets/"));
 

+ 4 - 2
src/WallpaperEngine/Assets/CPackage.cpp

@@ -5,6 +5,7 @@
 #include "CPackage.h"
 
 #include <utility>
+#include <filesystem>
 
 using namespace WallpaperEngine::Assets;
 
@@ -53,7 +54,7 @@ void CPackage::init ()
     FILE* fp = fopen (this->m_path.c_str (), "rb+");
 
     if (fp == nullptr)
-        throw std::runtime_error ("Cannot find package file");
+        throw std::filesystem::filesystem_error ("Cannot find package file", std::error_code());
 
     // first validate header
     this->validateHeader (fp);
@@ -109,7 +110,8 @@ void CPackage::validateHeader (FILE* fp)
         strcmp ("PKGV0004", pointer) != 0 &&
         strcmp ("PKGV0005", pointer) != 0 &&
         strcmp ("PKGV0006", pointer) != 0 &&
-        strcmp ("PKGV0013", pointer) != 0)
+        strcmp ("PKGV0013", pointer) != 0 &&
+        strcmp ("PKGV0014", pointer) != 0)
     {
         delete[] pointer;
         throw std::runtime_error ("Unsupported package version");