This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch upstream/latest
in repository colobot.

commit f0b38721e05dbda1d3562abc06fec535d1aa5a07
Author: krzys-h <krzy...@interia.pl>
Date:   Wed Aug 6 12:59:27 2014 +0200

    Loading all mods found in "mods" directory
---
 data                                     |  2 +-
 src/app/app.cpp                          | 24 +++++++++++++++++++++++-
 src/app/app.h                            |  3 +++
 src/common/resources/resourcemanager.cpp | 15 +++++++++++++++
 src/common/resources/resourcemanager.h   |  2 ++
 5 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/data b/data
index bacf4c9..b457f36 160000
--- a/data
+++ b/data
@@ -1 +1 @@
-Subproject commit bacf4c9dac9efc817907ab4e172231d3396a421d
+Subproject commit b457f36f0667997c2e1d30e556e933d19c781006
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 429a9d4..628b7a9 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -401,8 +401,13 @@ bool CApplication::Create()
         return false;
     }
     
-    CResourceManager::AddLocation(m_dataPath, false);
     boost::filesystem::create_directories(m_savePath);
+    boost::filesystem::create_directories(m_savePath+"/mods");
+    
+    LoadModsFromDir(m_dataPath+"/mods");
+    LoadModsFromDir(m_savePath+"/mods");
+    
+    CResourceManager::AddLocation(m_dataPath, false);
     CResourceManager::SetSaveLocation(m_savePath);
     CResourceManager::AddLocation(m_savePath, true);
 
@@ -595,6 +600,23 @@ bool CApplication::CreateVideoSurface()
     return true;
 }
 
+void CApplication::LoadModsFromDir(const std::string &dir)
+{
+    try {
+        boost::filesystem::directory_iterator iterator(dir);
+        for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
+        {
+            std::string fn = iterator->path().string();
+            CLogger::GetInstancePointer()->Info("Loading mod: '%s'\n", 
fn.c_str());
+            CResourceManager::AddLocation(fn, false);
+        }
+    }
+    catch(std::exception &e)
+    {
+        CLogger::GetInstancePointer()->Warn("Unable to load mods from 
directory '%s': %s\n", dir.c_str(), e.what());
+    }
+}
+
 void CApplication::Destroy()
 {
     m_joystickEnabled = false;
diff --git a/src/app/app.h b/src/app/app.h
index 0df3096..2049fb2 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -354,6 +354,9 @@ public:
 protected:
     //! Creates the window's SDL_Surface
     bool CreateVideoSurface();
+    
+    //! Loads all mods from given directory
+    void LoadModsFromDir(const std::string &dir);
 
     //! Processes the captured SDL event to Event struct
     Event       ProcessSystemEvent();
diff --git a/src/common/resources/resourcemanager.cpp 
b/src/common/resources/resourcemanager.cpp
index 8119a6b..0741c70 100644
--- a/src/common/resources/resourcemanager.cpp
+++ b/src/common/resources/resourcemanager.cpp
@@ -130,6 +130,21 @@ bool CResourceManager::Exists(const std::string &filename)
     return PHYSFS_exists(filename.c_str());
 }
 
+std::vector<std::string> CResourceManager::ListFiles(const std::string 
&directory)
+{
+    std::vector<std::string> result;
+    
+    char **files = PHYSFS_enumerateFiles(directory.c_str());
+    
+    for (char **i = files; *i != nullptr; i++) {
+        result.push_back(*i);
+    }
+    
+    PHYSFS_freeList(files);
+    
+    return result;
+}
+
 
 int CResourceManager::SDLClose(SDL_RWops *context)
 {
diff --git a/src/common/resources/resourcemanager.h 
b/src/common/resources/resourcemanager.h
index 4052047..b222048 100644
--- a/src/common/resources/resourcemanager.h
+++ b/src/common/resources/resourcemanager.h
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include <vector>
 #include <string>
 #include <SDL.h>
 
@@ -33,6 +34,7 @@ public:
     static SDL_RWops* GetSDLFileHandler(const std::string &filename);
     static CSNDFile* GetSNDFileHandler(const std::string &filename);
     static bool Exists(const std::string &filename);
+    static std::vector<std::string> ListFiles(const std::string &directory);
 
 private:
     static int SDLSeek(SDL_RWops *context, int offset, int whence);

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/colobot.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to