summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-02-17 09:47:51 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-02-17 14:53:14 +0100
commit5c12ec8153cd401a99f505e39389f8450a625eab (patch)
treedcbb4495ef1fda11b90c1463474c5c37860d9059 /src
parentd6b9d10defba85456939d71044132eb164a78790 (diff)
downloadmana-5c12ec8153cd401a99f505e39389f8450a625eab.tar.gz
mana-5c12ec8153cd401a99f505e39389f8450a625eab.tar.bz2
mana-5c12ec8153cd401a99f505e39389f8450a625eab.tar.xz
mana-5c12ec8153cd401a99f505e39389f8450a625eab.zip
Further ResourceManager and PhysFS cleanups
* Wrapped remaining PhysFS API calls and set PHYSFS_DEPRECATED to suppress deprecation warnings for PHYSFS_getUserDir, since no alternative is available for now. * Removed support for decompressing .gz files, since it has been unused for years and doesn't seem useful when updates are anyway served in an archive. * Use SDL_LoadFile and SDL_LoadFile_RW convenience functions (raises minimum SDL version to 2.0.10). * Removed ResourceManager::copyFile, since it was unused and will likely stay unused. * Removed ResourceManager::loadTextFile. Instead, split up the string in BrowserBox::addRows without making additional copies.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/client.cpp16
-rw-r--r--src/game.cpp5
-rw-r--r--src/gui/gui.cpp3
-rw-r--r--src/gui/helpwindow.cpp19
-rw-r--r--src/gui/updaterwindow.cpp6
-rw-r--r--src/gui/widgets/browserbox.cpp40
-rw-r--r--src/gui/widgets/browserbox.h7
-rw-r--r--src/resources/resourcemanager.cpp141
-rw-r--r--src/resources/resourcemanager.h52
-rw-r--r--src/resources/theme.cpp2
-rw-r--r--src/utils/filesystem.h43
-rw-r--r--src/utils/xml.cpp24
-rw-r--r--src/utils/zlib.cpp52
-rw-r--r--src/utils/zlib.h13
15 files changed, 117 insertions, 308 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fffecab7..d5131529 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,6 @@
include(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED
- sdl2>=2.0.5
+ sdl2>=2.0.10
SDL2_image
SDL2_mixer
SDL2_net
diff --git a/src/client.cpp b/src/client.cpp
index 9e41976f..02d5e292 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -967,7 +967,7 @@ void Client::action(const gcn::ActionEvent &event)
void Client::initRootDir()
{
- mRootDir = PHYSFS_getBaseDir();
+ mRootDir = FS::getBaseDir();
#ifdef _WIN32
std::string portableName = mRootDir + "portable.xml";
struct stat statbuf;
@@ -1027,15 +1027,15 @@ void Client::initHomeDir()
if (mLocalDataDir.empty())
{
#if defined __HAIKU__
- mLocalDataDir = PHYSFS_getUserDir();
+ mLocalDataDir = FS::getUserDir();
mLocalDataDir += "/config/data/Mana";
#elif defined _WIN32
mLocalDataDir = getSpecialFolderLocation(FOLDERID_LocalAppData);
if (mLocalDataDir.empty())
- mLocalDataDir = PHYSFS_getUserDir();
+ mLocalDataDir = FS::getUserDir();
mLocalDataDir += "/Mana";
#else
- mLocalDataDir = PHYSFS_getPrefDir("manasource.org", "mana");
+ mLocalDataDir = FS::getPrefDir("manasource.org", "mana");
#endif
}
@@ -1053,12 +1053,12 @@ void Client::initHomeDir()
#ifdef __APPLE__
mConfigDir = mLocalDataDir + "/" + app;
#elif defined __HAIKU__
- mConfigDir = PHYSFS_getPrefDir("manasource.org", "Mana");
+ mConfigDir = FS::getPrefDir("manasource.org", "Mana");
mConfigDir += app;
#elif defined _WIN32
- mConfigDir = PHYSFS_getPrefDir("Mana", app.c_str());
+ mConfigDir = FS::getPrefDir("Mana", app.c_str());
#else
- mConfigDir = std::string(PHYSFS_getUserDir()) + ".config/mana/" + app;
+ mConfigDir = std::string(FS::getUserDir()) + ".config/mana/" + app;
#endif
}
@@ -1170,7 +1170,7 @@ void Client::initScreenshotDir()
if (mScreenshotDir.empty())
mScreenshotDir = getSpecialFolderLocation(FOLDERID_Desktop);
#else
- mScreenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop";
+ mScreenshotDir = std::string(FS::getUserDir()) + "Desktop";
#endif
if (config.useScreenshotDirectorySuffix)
diff --git a/src/game.cpp b/src/game.cpp
index 8d3db19f..8694402d 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -302,7 +302,7 @@ static bool saveScreenshot()
logger->log("Directory %s doesn't exist and can't be created! "
"Setting screenshot directory to home.",
screenshotDirectory.c_str());
- screenshotDirectory = PHYSFS_getUserDir();
+ screenshotDirectory = FS::getUserDir();
}
do
@@ -927,9 +927,6 @@ void Game::changeMap(const std::string &mapPath)
std::string fullMap = paths.getValue("maps", "maps/")
+ mMapName + ".tmx";
- if (!FS::exists(fullMap))
- fullMap += ".gz";
-
// Attempt to load the new map
Map *newMap = MapReader::readMap(fullMap);
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index a59242dc..e6eed8f2 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -37,6 +37,7 @@
#include "resources/resourcemanager.h"
#include "resources/theme.h"
+#include "utils/filesystem.h"
#include <guichan/exception.hpp>
#include <guichan/image.hpp>
@@ -258,7 +259,7 @@ void Gui::handleTextInput(const TextInput &textInput)
static SDL_Surface *loadSurface(const std::string &path)
{
- if (SDL_RWops *file = ResourceManager::getInstance()->open(path))
+ if (SDL_RWops *file = FS::openRWops(path))
return IMG_Load_RW(file, 1);
return nullptr;
}
diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp
index 7bb31188..e687e817 100644
--- a/src/gui/helpwindow.cpp
+++ b/src/gui/helpwindow.cpp
@@ -29,9 +29,10 @@
#include "gui/widgets/layout.h"
#include "gui/widgets/scrollarea.h"
-#include "resources/resourcemanager.h"
#include "configuration.h"
+#include "log.h"
+#include "utils/filesystem.h"
#include "utils/gettext.h"
HelpWindow::HelpWindow():
@@ -88,12 +89,20 @@ void HelpWindow::loadHelp(const std::string &helpFile)
void HelpWindow::loadFile(const std::string &file)
{
- ResourceManager *resman = ResourceManager::getInstance();
std::string helpPath = branding.getStringValue("helpPath");
if (helpPath.empty())
helpPath = paths.getStringValue("help");
- const auto lines = resman->loadTextFile(helpPath + file + ".txt");
- for (auto &line : lines)
- mBrowserBox->addRow(line);
+ const std::string fileName = helpPath + file + ".txt";
+
+ size_t contentsLength;
+ char *fileContents = (char *) FS::loadFile(fileName, contentsLength);
+ if (!fileContents)
+ {
+ logger->log("Couldn't load text file: %s", fileName.c_str());
+ return;
+ }
+
+ mBrowserBox->addRows(std::string_view(fileContents, contentsLength));
+ SDL_free(fileContents);
}
diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp
index 772df725..bd98637b 100644
--- a/src/gui/updaterwindow.cpp
+++ b/src/gui/updaterwindow.cpp
@@ -358,8 +358,6 @@ void UpdaterWindow::download()
void UpdaterWindow::loadUpdates()
{
- ResourceManager *resman = ResourceManager::getInstance();
-
if (mUpdateFiles.empty())
{
// updates not downloaded
@@ -374,9 +372,7 @@ void UpdaterWindow::loadUpdates()
}
for (const UpdateFile &file : mUpdateFiles)
- {
- resman->addToSearchPath(mUpdatesDir + "/" + file.name, false);
- }
+ ResourceManager::addToSearchPath(mUpdatesDir + "/" + file.name, false);
}
void UpdaterWindow::logic()
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 9eee9448..d27e843c 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -75,28 +75,38 @@ BrowserBox::BrowserBox(Mode mode):
BrowserBox::~BrowserBox() = default;
-void BrowserBox::addRow(const std::string &row)
+void BrowserBox::addRows(std::string_view rows)
+{
+ std::string_view::size_type start = 0;
+ std::string_view::size_type end = 0;
+ while (end != std::string::npos)
+ {
+ end = rows.find('\n', start);
+ addRow(rows.substr(start, end - start));
+ start = end + 1;
+ }
+}
+
+void BrowserBox::addRow(std::string_view row)
{
TextRow &newRow = mTextRows.emplace_back();
// Use links and user defined colors
if (mUseLinksAndUserColors)
{
- std::string tmp = row;
-
// Check for links in format "@@link|Caption@@"
- auto idx1 = tmp.find("@@");
- while (idx1 != std::string::npos)
+ auto linkStart = row.find("@@");
+ while (linkStart != std::string::npos)
{
- const auto idx2 = tmp.find("|", idx1);
- const auto idx3 = tmp.find("@@", idx2);
+ const auto linkSep = row.find("|", linkStart);
+ const auto linkEnd = row.find("@@", linkSep);
- if (idx2 == std::string::npos || idx3 == std::string::npos)
+ if (linkSep == std::string::npos || linkEnd == std::string::npos)
break;
BrowserLink &link = newRow.links.emplace_back();
- link.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
- link.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
+ link.link = row.substr(linkStart + 2, linkSep - (linkStart + 2));
+ link.caption = row.substr(linkSep + 1, linkEnd - (linkSep + 1));
if (link.caption.empty())
{
@@ -107,18 +117,18 @@ void BrowserBox::addRow(const std::string &row)
link.caption = link.link;
}
- newRow.text += tmp.substr(0, idx1);
+ newRow.text += row.substr(0, linkStart);
newRow.text += "##<" + link.caption;
- tmp.erase(0, idx3 + 2);
- if (!tmp.empty())
+ row = row.substr(linkEnd + 2);
+ if (!row.empty())
{
newRow.text += "##>";
}
- idx1 = tmp.find("@@");
+ linkStart = row.find("@@");
}
- newRow.text += tmp;
+ newRow.text += row;
}
// Don't use links and user defined colors
else
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index c2a2853d..d327b533 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -117,9 +117,14 @@ class BrowserBox : public gcn::Widget,
void disableLinksAndUserColors() { mUseLinksAndUserColors = false; }
/**
+ * Adds one or more text rows to the browser, separated by '\n'.
+ */
+ void addRows(std::string_view rows);
+
+ /**
* Adds a text row to the browser.
*/
- void addRow(const std::string &row);
+ void addRow(std::string_view row);
/**
* Remove all rows.
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 80b3ae82..fa7ac0e3 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -32,8 +32,6 @@
#include "resources/spritedef.h"
#include "utils/filesystem.h"
-#include "utils/zlib.h"
-#include "utils/physfsrwops.h"
#include <SDL_image.h>
@@ -158,7 +156,7 @@ void ResourceManager::searchAndAddArchives(const std::string &path,
const std::string &ext,
bool append)
{
- const char *dirSep = PHYSFS_getDirSeparator();
+ const char *dirSep = FS::getDirSeparator();
for (auto fileName : FS::enumerateFiles(path))
{
@@ -195,11 +193,6 @@ std::string ResourceManager::getPath(const std::string &file)
return path;
}
-SDL_RWops *ResourceManager::open(const std::string &path)
-{
- return PHYSFSRWOPS_openRead(path.c_str());
-}
-
Resource *ResourceManager::get(const std::string &idPath,
const std::function<Resource *()> &generator)
{
@@ -238,7 +231,7 @@ Resource *ResourceManager::get(const std::string &idPath,
Resource *ResourceManager::get(const std::string &path, loader fun)
{
return get(path, [&] () -> Resource * {
- if (SDL_RWops *rw = open(path))
+ if (SDL_RWops *rw = FS::openRWops(path))
return fun(rw);
return nullptr;
});
@@ -265,7 +258,7 @@ Image *ResourceManager::getImage(const std::string &idPath)
d = std::make_unique<Dye>(path.substr(p + 1));
path = path.substr(0, p);
}
- SDL_RWops *rw = open(path);
+ SDL_RWops *rw = FS::openRWops(path);
if (!rw)
return nullptr;
@@ -342,131 +335,3 @@ void ResourceManager::deleteInstance()
delete instance;
instance = nullptr;
}
-
-void *ResourceManager::loadFile(const std::string &filename, int &filesize,
- bool inflate)
-{
- // Attempt to open the specified file using PhysicsFS
- auto file = FS::openRead(filename);
- if (!file)
- {
- logger->log("Warning: Failed to load %s: %s",
- filename.c_str(), FS::getLastError());
- return nullptr;
- }
-
- // Log the real dir of the file
- logger->log("Loaded %s/%s", FS::getRealDir(filename).value_or("<null>"),
- filename.c_str());
-
- // Get the size of the file
- auto maybeFilesize = file.fileLength();
- if (!maybeFilesize)
- {
- logger->log("Error getting file size: %s", FS::getLastError());
- return nullptr;
- }
-
- filesize = *maybeFilesize;
-
- // Allocate memory and load the file
- void *buffer = malloc(filesize);
- auto readSize = file.read(buffer, filesize);
- if (!readSize || *readSize != filesize)
- {
- logger->log("Error reading file: %s", FS::getLastError());
- free(buffer);
- return nullptr;
- }
-
- // Close the file and let the user deallocate the memory
- file.close();
-
- if (inflate && filename.find(".gz", filename.length() - 3)
- != std::string::npos)
- {
- unsigned char *inflated;
-
- // Inflate the gzipped map data
- filesize = inflateMemory((unsigned char*) buffer, filesize, inflated);
- free(buffer);
-
- buffer = inflated;
-
- if (!buffer)
- {
- logger->log("Could not decompress file: %s", filename.c_str());
- }
- }
-
- return buffer;
-}
-
-bool ResourceManager::copyFile(const std::string &src, const std::string &dst)
-{
- auto srcFile = FS::openRead(src);
- if (!srcFile)
- {
- logger->log("Read error: %s", FS::getLastError());
- return false;
- }
- auto dstFile = FS::openWrite(dst);
- if (!dstFile)
- {
- logger->log("Write error: %s", FS::getLastError());
- return false;
- }
-
- char buffer[1024];
-
- while (true)
- {
- auto len = srcFile.read(buffer, sizeof(buffer));
- if (!len)
- {
- logger->log("Read error: %s", FS::getLastError());
- return false;
- }
-
- if (!dstFile.write(buffer, *len))
- {
- logger->log("Write error: %s", FS::getLastError());
- return false;
- }
-
- if (srcFile.eof())
- break;
- }
-
- // Explicit close to flush the file and check for errors
- if (!dstFile.close())
- {
- logger->log("Write error: %s", FS::getLastError());
- return false;
- }
-
- return true;
-}
-
-std::vector<std::string> ResourceManager::loadTextFile(
- const std::string &fileName)
-{
- int contentsLength;
- char *fileContents = (char*)loadFile(fileName, contentsLength);
- std::vector<std::string> lines;
-
- if (!fileContents)
- {
- logger->log("Couldn't load text file: %s", fileName.c_str());
- return lines;
- }
-
- std::istringstream iss(std::string(fileContents, contentsLength));
- std::string line;
-
- while (getline(iss, line))
- lines.push_back(line);
-
- free(fileContents);
- return lines;
-}
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index b72920cf..5464ff3d 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -27,7 +27,6 @@
#include <functional>
#include <map>
#include <string>
-#include <vector>
class Image;
class ImageSet;
@@ -63,14 +62,14 @@ class ResourceManager
*
* @return <code>true</code> on success, <code>false</code> otherwise.
*/
- bool addToSearchPath(const std::string &path, bool append);
+ static bool addToSearchPath(const std::string &path, bool append);
/**
* Searches for zip files and adds them to the search path.
*/
- void searchAndAddArchives(const std::string &path,
- const std::string &ext,
- bool append);
+ static void searchAndAddArchives(const std::string &path,
+ const std::string &ext,
+ bool append);
/**
* Returns the real path to a file. Note that this method will always
@@ -79,17 +78,7 @@ class ResourceManager
* @param file The file to get the real path to.
* @return The real path.
*/
- std::string getPath(const std::string &file);
-
- /**
- * Opens a file for reading. The caller is responsible for closing the
- * file.
- *
- * @param path The file name.
- * @return A valid SDL_RWops pointer or <code>NULL</code> if the file
- * could not be opened.
- */
- SDL_RWops *open(const std::string &path);
+ static std::string getPath(const std::string &file);
/**
* Creates a resource and adds it to the resource map.
@@ -150,37 +139,6 @@ class ResourceManager
SpriteDef *getSprite(const std::string &path, int variant = 0);
/**
- * Allocates data into a buffer pointer for raw data loading. The
- * returned data is expected to be freed using <code>free()</code>.
- *
- * @param filename The name of the file to be loaded.
- * @param filesize The size of the file that was loaded.
- * @param inflate True to uncompress the file if the filename ends in
- * ".gz", false to ignore that.
- *
- * @return An allocated byte array containing the data that was loaded,
- * or <code>NULL</code> on fail.
- */
- void *loadFile(const std::string &filename, int &filesize,
- bool inflate = true);
-
- /**
- * Copies a file from one place to another (useful for extracting
- * raw files from a zip archive, for example)
- *
- * @param src Source file name
- * @param dst Destination file name
- * @return true on success, false on failure. An error message should be
- * in the log file.
- */
- bool copyFile(const std::string &src, const std::string &dst);
-
- /**
- * Retrieves the contents of a text file.
- */
- std::vector<std::string> loadTextFile(const std::string &fileName);
-
- /**
* Returns an instance of the class, creating one if it does not
* already exist.
*/
diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp
index 1eb2f87c..26ab3aed 100644
--- a/src/resources/theme.cpp
+++ b/src/resources/theme.cpp
@@ -565,7 +565,7 @@ void Theme::loadColors(std::string file)
if (type < 0) // invalid or no type given
continue;
- mProgressColors[type] = new DyePalette(node.getProperty( "color", ""));
+ mProgressColors[type] = new DyePalette(node.getProperty("color", ""));
}
}
}
diff --git a/src/utils/filesystem.h b/src/utils/filesystem.h
index 68b3d82a..796bc906 100644
--- a/src/utils/filesystem.h
+++ b/src/utils/filesystem.h
@@ -20,7 +20,10 @@
#pragma once
-#include <physfs.h>
+// Suppress deprecation warnings for PHYSFS_getUserDir
+#define PHYSFS_DEPRECATED
+
+#include "utils/physfsrwops.h"
#include <optional>
#include <string>
@@ -41,6 +44,26 @@ inline void deinit()
PHYSFS_deinit();
}
+inline const char *getDirSeparator()
+{
+ return PHYSFS_getDirSeparator();
+}
+
+inline const char *getBaseDir()
+{
+ return PHYSFS_getBaseDir();
+}
+
+inline const char *getUserDir()
+{
+ return PHYSFS_getUserDir();
+}
+
+inline const char *getPrefDir(const char *org, const char *app)
+{
+ return PHYSFS_getPrefDir(org, app);
+}
+
/**
* Sets the write directory.
*
@@ -231,4 +254,22 @@ inline const char *getLastError()
return PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
}
+//
+// Helper functions for loading files through SDL_RWops
+//
+
+inline SDL_RWops *openRWops(const std::string &path)
+{
+ return PHYSFSRWOPS_openRead(path.c_str());
+}
+
+inline void *loadFile(const std::string &path, size_t &datasize)
+{
+ auto file = openRWops(path);
+ if (!file)
+ return nullptr;
+
+ return SDL_LoadFile_RW(file, &datasize, 1);
+}
+
} // namespace FS
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 7ea5b9d6..c408c9c2 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -25,16 +25,13 @@
#include "log.h"
-#include "resources/resourcemanager.h"
-
-#include "utils/zlib.h"
+#include "utils/filesystem.h"
namespace XML
{
struct XMLContext
{
std::string file;
- bool resman;
};
#if LIBXML_VERSION >= 21200
@@ -49,7 +46,7 @@ namespace XML
logger->log("Error in XML file '%s' on line %d",
context->file.c_str(), error->line);
else
- logger->log("Error in unknown xml file on line %d",
+ logger->log("Error in unknown XML file on line %d",
error->line);
logger->log("%s", error->message);
@@ -63,32 +60,27 @@ namespace XML
{
XMLContext ctx;
ctx.file = filename;
- ctx.resman = useResman;
xmlSetStructuredErrorFunc(&ctx, xmlLogger);
- int size;
+ size_t size;
char *data = nullptr;
+
if (useResman)
- {
- ResourceManager *resman = ResourceManager::getInstance();
- data = (char*) resman->loadFile(filename, size);
- }
+ data = (char *) FS::loadFile(filename, size);
else
- {
- data = (char *) loadCompressedFile(filename, size);
- }
+ data = (char *) SDL_LoadFile(filename.c_str(), &size);
if (data)
{
mDoc = xmlParseMemory(data, size);
- free(data);
+ SDL_free(data);
if (!mDoc)
logger->log("Error parsing XML file %s", filename.c_str());
}
else
{
- logger->log("Error loading %s", filename.c_str());
+ logger->log("Error loading %s: %s", filename.c_str(), SDL_GetError());
}
xmlSetStructuredErrorFunc(nullptr, xmlLogger);
diff --git a/src/utils/zlib.cpp b/src/utils/zlib.cpp
index 773c7484..f78b235e 100644
--- a/src/utils/zlib.cpp
+++ b/src/utils/zlib.cpp
@@ -25,8 +25,6 @@
#include <cassert>
#include <cstdlib>
-#include <fstream>
-#include <iostream>
#include <zlib.h>
/**
@@ -131,53 +129,3 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
return outLength;
}
-
-void *loadCompressedFile(const std::string &filename, int &filesize)
-{
- std::ifstream file;
- file.open(filename, std::ios::in);
-
- if (file.is_open())
- {
- // Get length of file
- file.seekg (0, std::ios::end);
- filesize = file.tellg();
- file.seekg(0, std::ios::beg);
-
- char *buffer = (char *) malloc(filesize);
-
- file.read(buffer, filesize);
- file.close();
-
- unsigned char *inflated;
- unsigned int inflatedSize;
-
- if (filename.find(".gz", filename.length() - 3) != std::string::npos)
- {
- // Inflate the gzipped map data
- inflatedSize =
- inflateMemory((unsigned char*) buffer, filesize, inflated);
- free(buffer);
-
- if (!inflated)
- {
- logger->log("Could not decompress file: %s",
- filename.c_str());
- return nullptr;
- }
-
- filesize = inflatedSize;
- return inflated;
- }
- else
- {
- return buffer;
- }
- }
- else
- {
- logger->log("Error loading file from drive: %s", filename.c_str());
- }
-
- return nullptr;
-}
diff --git a/src/utils/zlib.h b/src/utils/zlib.h
index 74853bd6..46429c0b 100644
--- a/src/utils/zlib.h
+++ b/src/utils/zlib.h
@@ -21,8 +21,6 @@
#pragma once
-#include <string>
-
/**
* Inflates either zlib or gzip deflated memory. The inflated memory is
* expected to be freed by the caller.
@@ -32,14 +30,3 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
int inflateMemory(unsigned char *in, unsigned int inLength,
unsigned char *&out);
-
-/**
- * Loads the given file from the filesystem, uncompressing if it ends in ".gz".
- *
- * @param filename The name of the file to be loaded and uncompressed
- * @param filesize The size of the file that was loaded and uncompressed.
- *
- * @return An allocated byte array containing the data that was loaded and
- * uncompressed, or <code>NULL</code> on fail.
- */
-void *loadCompressedFile(const std::string &filename, int &filesize);