mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
chore: cleanup filesystem functions to use containers directly
This commit is contained in:
parent
05854b5984
commit
0dbd10440c
@ -351,9 +351,6 @@ add_executable(
|
|||||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
|
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
|
||||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h
|
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h
|
||||||
|
|
||||||
src/WallpaperEngine/FileSystem/FileSystem.cpp
|
|
||||||
src/WallpaperEngine/FileSystem/FileSystem.h
|
|
||||||
|
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingValue.cpp
|
src/WallpaperEngine/Core/UserSettings/CUserSettingValue.cpp
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h
|
src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp
|
src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp
|
||||||
|
@ -17,7 +17,7 @@ const ITexture* CContainer::readTexture (const std::string& filename) const {
|
|||||||
// get the texture's filename (usually .tex)
|
// get the texture's filename (usually .tex)
|
||||||
const std::string texture = "materials/" + filename + ".tex";
|
const std::string texture = "materials/" + filename + ".tex";
|
||||||
|
|
||||||
const void* textureContents = this->readFile (texture, nullptr);
|
const uint8_t* textureContents = this->readFile (texture, nullptr);
|
||||||
|
|
||||||
const ITexture* result = new CTexture (textureContents);
|
const ITexture* result = new CTexture (textureContents);
|
||||||
|
|
||||||
@ -25,6 +25,8 @@ const ITexture* CContainer::readTexture (const std::string& filename) const {
|
|||||||
glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, texture.c_str ());
|
glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, texture.c_str ());
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
|
delete textureContents;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ std::string CContainer::readShader (const std::string& filename) const {
|
|||||||
const std::filesystem::path workshopId = *it++;
|
const std::filesystem::path workshopId = *it++;
|
||||||
|
|
||||||
if (++it != shader.end ()) {
|
if (++it != shader.end ()) {
|
||||||
const std::filesystem::path shaderfile = *it;
|
const std::filesystem::path& shaderfile = *it;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile;
|
shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile;
|
||||||
@ -82,6 +84,7 @@ std::string CContainer::readFileAsString (const std::string& filename) const {
|
|||||||
|
|
||||||
// free the intermediate buffer used to generate the std::string
|
// free the intermediate buffer used to generate the std::string
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
|
delete contents;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
@ -25,6 +25,8 @@ class CContainer {
|
|||||||
* Reads the given file from the container and returns it's data
|
* Reads the given file from the container and returns it's data
|
||||||
* Additionally sets a length parameter to return back the file's length
|
* Additionally sets a length parameter to return back the file's length
|
||||||
*
|
*
|
||||||
|
* The returned string must be freed by the called
|
||||||
|
*
|
||||||
* @param filename The file to read
|
* @param filename The file to read
|
||||||
* @param length The file's length after it's been read, null for not getting anything back
|
* @param length The file's length after it's been read, null for not getting anything back
|
||||||
*
|
*
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <WallpaperEngine/Assets/CContainer.h>
|
#include <WallpaperEngine/Assets/CContainer.h>
|
||||||
#include <WallpaperEngine/FileSystem/FileSystem.h>
|
|
||||||
|
|
||||||
#include "CProject.h"
|
#include "CProject.h"
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
||||||
@ -17,7 +16,7 @@ CProject::CProject (std::string title, std::string type, CContainer* container)
|
|||||||
m_container (container) {}
|
m_container (container) {}
|
||||||
|
|
||||||
CProject* CProject::fromFile (const std::string& filename, CContainer* container) {
|
CProject* CProject::fromFile (const std::string& filename, CContainer* container) {
|
||||||
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container));
|
json content = json::parse (container->readFileAsString (filename));
|
||||||
|
|
||||||
std::string dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
|
std::string dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
|
||||||
if (dependency == "No dependency") {
|
if (dependency == "No dependency") {
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine;
|
using namespace WallpaperEngine;
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
@ -33,7 +31,7 @@ CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, CObject* ob
|
|||||||
auto file_it = jsonFindRequired (data, "file", "Object effect must have a file");
|
auto file_it = jsonFindRequired (data, "file", "Object effect must have a file");
|
||||||
auto effectpasses_it = data.find ("passes");
|
auto effectpasses_it = data.find ("passes");
|
||||||
|
|
||||||
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (file_it->get<std::string> (), container));
|
json content = json::parse (container->readFileAsString(file_it->get<std::string> ()));
|
||||||
|
|
||||||
auto name_it = jsonFindRequired (content, "name", "Effect must have a name");
|
auto name_it = jsonFindRequired (content, "name", "Effect must have a name");
|
||||||
auto description = jsonFindDefault<std::string> (content, "description", "");
|
auto description = jsonFindDefault<std::string> (content, "description", "");
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
@ -43,7 +41,7 @@ WallpaperEngine::Core::CObject* CImage::fromJSON (CScene* scene, json data, CCon
|
|||||||
const auto colorBlendMode_val = jsonFindDefault<uint32_t> (data, "colorBlendMode", 0);
|
const auto colorBlendMode_val = jsonFindDefault<uint32_t> (data, "colorBlendMode", 0);
|
||||||
const auto parallaxDepth_val = jsonFindDefault<std::string> (data, "parallaxDepth", "0 0");
|
const auto parallaxDepth_val = jsonFindDefault<std::string> (data, "parallaxDepth", "0 0");
|
||||||
|
|
||||||
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (image_it->get<std::string> (), container));
|
json content = json::parse (container->readFileAsString (image_it->get<std::string> ()));
|
||||||
|
|
||||||
const auto material_it = jsonFindRequired (content, "material", "Image must have a material");
|
const auto material_it = jsonFindRequired (content, "material", "Image must have a material");
|
||||||
const auto fullscreen = jsonFindDefault<bool> (content, "fullscreen", false);
|
const auto fullscreen = jsonFindDefault<bool> (content, "fullscreen", false);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "CParticle.h"
|
#include "CParticle.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
@ -8,7 +7,7 @@ using namespace WallpaperEngine::Core::Objects;
|
|||||||
CParticle* CParticle::fromFile (CScene* scene, const std::string& filename, CContainer* container,
|
CParticle* CParticle::fromFile (CScene* scene, const std::string& filename, CContainer* container,
|
||||||
CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
|
CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
|
||||||
CUserSettingVector3* scale) {
|
CUserSettingVector3* scale) {
|
||||||
json data = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container));
|
json data = json::parse (container->readFileAsString (filename));
|
||||||
const auto controlpoint_it = data.find ("controlpoint");
|
const auto controlpoint_it = data.find ("controlpoint");
|
||||||
const auto starttime_it = jsonFindRequired (data, "starttime", "Particles must have start time");
|
const auto starttime_it = jsonFindRequired (data, "starttime", "Particles must have start time");
|
||||||
const auto maxcount_it = jsonFindRequired (data, "maxcount", "Particles must have maximum count");
|
const auto maxcount_it = jsonFindRequired (data, "maxcount", "Particles must have maximum count");
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
@ -13,11 +11,11 @@ using namespace WallpaperEngine::Core::Objects::Images;
|
|||||||
CMaterial::CMaterial (std::string name) : m_name (std::move (name)) {}
|
CMaterial::CMaterial (std::string name) : m_name (std::move (name)) {}
|
||||||
|
|
||||||
CMaterial* CMaterial::fromFile (const std::string& filename, CContainer* container) {
|
CMaterial* CMaterial::fromFile (const std::string& filename, CContainer* container) {
|
||||||
return fromJSON (filename, json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container)));
|
return fromJSON (filename, json::parse (container->readFileAsString (filename)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CMaterial* CMaterial::fromFile (const std::string& filename, const std::string& target, CContainer* container) {
|
CMaterial* CMaterial::fromFile (const std::string& filename, const std::string& target, CContainer* container) {
|
||||||
return fromJSON (filename, json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container)), target);
|
return fromJSON (filename, json::parse (container->readFileAsString (filename)), target);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMaterial* CMaterial::fromJSON (const std::string& name, json data, const std::string& target) {
|
CMaterial* CMaterial::fromJSON (const std::string& name, json data, const std::string& target) {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
||||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
using namespace WallpaperEngine::Core;
|
||||||
|
|
||||||
@ -36,8 +35,7 @@ CScene::CScene (CProject& project, CContainer* container, Scenes::CCamera* camer
|
|||||||
m_skylightColor (skylightColor) {}
|
m_skylightColor (skylightColor) {}
|
||||||
|
|
||||||
CScene* CScene::fromFile (const std::string& filename, CProject& project, CContainer* container) {
|
CScene* CScene::fromFile (const std::string& filename, CProject& project, CContainer* container) {
|
||||||
std::string stringContent = WallpaperEngine::FileSystem::loadFullFile (filename, container);
|
json content = json::parse (container->readFileAsString (filename));
|
||||||
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container));
|
|
||||||
|
|
||||||
const auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera");
|
const auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera");
|
||||||
const auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
|
const auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
// filesystem includes
|
|
||||||
#include "FileSystem.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine;
|
|
||||||
|
|
||||||
std::string FileSystem::loadFullFile (const std::string& file, const WallpaperEngine::Assets::CContainer* containers) {
|
|
||||||
uint32_t length = 0;
|
|
||||||
const void* contents = containers->readFile (file, &length);
|
|
||||||
|
|
||||||
// build a new buffer that can fit in the string
|
|
||||||
char* filedata = new char [length + 1];
|
|
||||||
// ensure there's a null termination at the end
|
|
||||||
memset (filedata, 0, length + 1);
|
|
||||||
// copy file contents over
|
|
||||||
memcpy (filedata, contents, length);
|
|
||||||
|
|
||||||
std::string content = filedata;
|
|
||||||
|
|
||||||
delete [] filedata;
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
/**
|
|
||||||
* @author Alexis Maiquez Murcia <almamu@almamu.com>
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::FileSystem {
|
|
||||||
/**
|
|
||||||
* Loads a full file into an std::string
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @param containers
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
std::string loadFullFile (const std::string& file, const WallpaperEngine::Assets::CContainer* containers);
|
|
||||||
} // namespace WallpaperEngine::FileSystem
|
|
@ -9,6 +9,17 @@ CSound::CSound (CScene* scene, Core::Objects::CSound* sound) : CObject (scene, T
|
|||||||
this->load ();
|
this->load ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSound::~CSound() {
|
||||||
|
// free all the sound buffers and streams
|
||||||
|
for (const auto& stream : this->m_audioStreams) {
|
||||||
|
delete stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& buffer : this->m_soundBuffer) {
|
||||||
|
delete buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSound::load () {
|
void CSound::load () {
|
||||||
for (const auto& cur : this->m_sound->getSounds ()) {
|
for (const auto& cur : this->m_sound->getSounds ()) {
|
||||||
uint32_t filesize = 0;
|
uint32_t filesize = 0;
|
||||||
|
@ -11,6 +11,7 @@ namespace WallpaperEngine::Render::Objects {
|
|||||||
class CSound final : public CObject {
|
class CSound final : public CObject {
|
||||||
public:
|
public:
|
||||||
CSound (CScene* scene, Core::Objects::CSound* sound);
|
CSound (CScene* scene, Core::Objects::CSound* sound);
|
||||||
|
~CSound ();
|
||||||
|
|
||||||
void render () override;
|
void render () override;
|
||||||
|
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
// filesystem
|
|
||||||
#include <WallpaperEngine/FileSystem/FileSystem.h>
|
|
||||||
|
|
||||||
// shader compiler
|
// shader compiler
|
||||||
#include <WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h>
|
#include <WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h>
|
||||||
#include <WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h>
|
#include <WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h>
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include "WallpaperEngine/Assets/ITexture.h"
|
#include "WallpaperEngine/Assets/ITexture.h"
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
#include "WallpaperEngine/Core/Core.h"
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
||||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
||||||
|
|
||||||
#include "CGLSLContext.h"
|
#include "CGLSLContext.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user