Skip to content

Commit

Permalink
Merge pull request SuperTux#425 from SuperTux/addon-mountpoint
Browse files Browse the repository at this point in the history
Add support for 'custom/{addon_id}' mountpoint
  • Loading branch information
maths22 committed May 29, 2016
2 parents c386655 + 70ef5e2 commit 74d428e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/addon/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Addon::parse(const ReaderMapping& lisp)
lisp.get("license", addon->m_license);
lisp.get("url", addon->m_url);
lisp.get("md5", addon->m_md5);
lisp.get("format", addon->m_format);

return addon;
}
Expand Down Expand Up @@ -133,6 +134,7 @@ Addon::Addon() :
m_title(),
m_author(),
m_license(),
m_format(0),
m_url(),
m_md5(),
m_install_filename(),
Expand Down
7 changes: 7 additions & 0 deletions src/addon/addon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Addon

enum Type { WORLD, WORLDMAP, LEVELSET, LANGUAGEPACK };

enum Format {
ORIGINAL = 0,
WITH_MOUNTPOINT = 1
};

private:
// fields provided by the addon.zip itself
std::string m_id;
Expand All @@ -40,6 +45,7 @@ class Addon
std::string m_title;
std::string m_author;
std::string m_license;
int m_format;

// additional fields provided for addons from an addon repository
std::string m_url;
Expand All @@ -55,6 +61,7 @@ class Addon
public:
std::string get_id() const { return m_id; }
int get_version() const { return m_version; }
int get_format() const { return m_format; }

Type get_type() const { return m_type; }
std::string get_title() const { return m_title; }
Expand Down
13 changes: 12 additions & 1 deletion src/addon/addon_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,18 @@ AddonManager::enable_addon(const AddonId& addon_id)
{
log_debug << "Adding archive \"" << addon.get_install_filename() << "\" to search path" << std::endl;
//int PHYSFS_mount(addon.installed_install_filename.c_str(), "addons/", 0)
if (PHYSFS_mount(addon.get_install_filename().c_str(), NULL, 0) == 0)

std::string mountpoint;
switch (addon.get_format()) {
case Addon::ORIGINAL:
mountpoint = "";
break;
default:
mountpoint = "custom/" + addon_id;
break;
}

if (PHYSFS_mount(addon.get_install_filename().c_str(), mountpoint.c_str(), 0) == 0)
{
log_warning << "Could not add " << addon.get_install_filename() << " to search path: "
<< PHYSFS_getLastError() << std::endl;
Expand Down
8 changes: 8 additions & 0 deletions src/physfs/physfs_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ PhysFSFileSystem::open_file(const std::string& filename)
return std::unique_ptr<std::istream>(new IFileStream(filename));
}

bool
PhysFSFileSystem::is_directory(const std::string& filename)
{
PHYSFS_Stat statbuf;
PHYSFS_stat(filename.c_str(), &statbuf);
return statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY;
}

/* EOF */
2 changes: 1 addition & 1 deletion src/physfs/physfs_file_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class PhysFSFileSystem : public tinygettext::FileSystem

std::vector<std::string> open_directory(const std::string& pathname);
std::unique_ptr<std::istream> open_file(const std::string& filename);
static bool is_directory(const std::string& filename);
};

#endif

/* EOF */

31 changes: 28 additions & 3 deletions src/supertux/menu/contrib_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "physfs/physfs_file_system.hpp"
#include "supertux/game_manager.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/menu/contrib_levelset_menu.hpp"
Expand All @@ -42,14 +43,38 @@ ContribMenu::ContribMenu() :
for(const char* const* filename = files.get(); *filename != 0; ++filename)
{
std::string filepath = FileSystem::join("levels", *filename);
PHYSFS_Stat statbuf;
PHYSFS_stat(filepath.c_str(), &statbuf);
if(statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY)
if(PhysFSFileSystem::is_directory(filepath))
{
level_worlds.push_back(filepath);
}
}

std::unique_ptr<char*, decltype(&PHYSFS_freeList)>
addons(PHYSFS_enumerateFiles("custom"),
PHYSFS_freeList);
for(const char* const* addondir = addons.get(); *addondir != 0; ++addondir)
{
std::string addonpath = FileSystem::join("custom", *addondir);
if(PhysFSFileSystem::is_directory(addonpath))
{
std::string addonlevelpath = FileSystem::join(addonpath.c_str(), "levels");
if(PhysFSFileSystem::is_directory(addonlevelpath))
{
std::unique_ptr<char*, decltype(&PHYSFS_freeList)>
addonfiles(PHYSFS_enumerateFiles(addonlevelpath.c_str()),
PHYSFS_freeList);
for(const char* const* filename = addonfiles.get(); *filename != 0; ++filename)
{
std::string filepath = FileSystem::join(addonlevelpath.c_str(), *filename);
if(PhysFSFileSystem::is_directory(filepath))
{
level_worlds.push_back(filepath);
}
}
}
}
}

add_label(_("Contrib Levels"));
add_hl();

Expand Down

0 comments on commit 74d428e

Please sign in to comment.