summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/app.cpp44
-rw-r--r--src/app/app.h14
-rw-r--r--src/app/gamedata.cpp123
-rw-r--r--src/app/gamedata.h66
-rw-r--r--src/app/main.cpp3
-rw-r--r--src/app/system.cpp16
-rw-r--r--src/app/system.h9
-rw-r--r--src/app/system_linux.cpp28
-rw-r--r--src/app/system_linux.h1
-rw-r--r--src/app/system_macosx.cpp20
-rw-r--r--src/app/system_macosx.h3
-rw-r--r--src/app/system_windows.cpp19
-rw-r--r--src/app/system_windows.h1
13 files changed, 9 insertions, 338 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 1efabb5..5b495c3 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -19,7 +19,6 @@
#include "app/app.h"
-#include "app/gamedata.h"
#include "app/system.h"
#include "common/logger.h"
@@ -27,6 +26,7 @@
#include "common/image.h"
#include "common/key.h"
#include "common/stringutils.h"
+#include "common/resources/resourcemanager.h"
#include "graphics/engine/modelmanager.h"
#include "graphics/opengl/gldevice.h"
@@ -101,7 +101,6 @@ CApplication::CApplication()
m_objMan = new CObjectManager();
m_eventQueue = new CEventQueue();
m_profile = new CProfile();
- m_gameData = new CGameData();
m_engine = nullptr;
m_device = nullptr;
@@ -112,7 +111,6 @@ CApplication::CApplication()
m_exitCode = 0;
m_active = false;
m_debugModes = 0;
- m_customDataPath = false;
m_windowTitle = "COLOBOT GOLD";
@@ -149,9 +147,6 @@ CApplication::CApplication()
m_mouseButtonsState = 0;
m_trackedKeys = 0;
- m_dataPath = GetSystemUtils()->GetDataPath();
- m_langPath = GetSystemUtils()->GetLangPath();
-
m_runSceneName = "";
m_runSceneRank = 0;
@@ -266,8 +261,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Message(" -scenetest win every mission right after it's loaded\n");
GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n");
GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl, ru)\n");
- GetLogger()->Message(" -datadir path set custom data directory path\n");
- GetLogger()->Message(" -mod path run mod\n");
GetLogger()->Message(" -langdir path set custom language directory path\n");
GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n");
return PARSE_ARGS_HELP;
@@ -331,25 +324,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
m_language = language;
break;
}
- case OPT_DATADIR:
- {
- m_dataPath = optarg;
- m_customDataPath = true;
- GetLogger()->Info("Using datadir: '%s'\n", optarg);
- break;
- }
- case OPT_MOD:
- {
- m_gameData->AddMod(std::string(optarg));
- GetLogger()->Info("Running mod from path: '%s'\n", optarg);
- break;
- }
- case OPT_LANGDIR:
- {
- m_langPath = optarg;
- GetLogger()->Info("Using language dir: '%s'\n", m_langPath.c_str());
- break;
- }
case OPT_VBO:
{
std::string vbo;
@@ -388,25 +362,17 @@ bool CApplication::Create()
GetLogger()->Warn("Config not found. Default values will be used!\n");
defaultValues = true;
}
- else
- {
- if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Data", path))
- m_dataPath = path;
- }
- boost::filesystem::path dataPath(m_dataPath);
+ boost::filesystem::path dataPath(COLOBOT_DEFAULT_DATADIR);
if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
{
- GetLogger()->Error("Data directory '%s' doesn't exist or is not a directory\n", m_dataPath.c_str());
+ GetLogger()->Error("Data directory '%s' doesn't exist or is not a directory\n", COLOBOT_DEFAULT_DATADIR);
m_errorMessage = std::string("Could not read from data directory:\n") +
- std::string("'") + m_dataPath + std::string("'\n") +
+ std::string("'") + COLOBOT_DEFAULT_DATADIR + std::string("'\n") +
std::string("Please check your installation, or supply a valid data directory by -datadir option.");
m_exitCode = 1;
return false;
}
-
- m_gameData->SetDataDir(std::string(m_dataPath));
- m_gameData->Init();
if (GetProfile().GetLocalProfileString("Language", "Lang", path)) {
Language language;
@@ -1724,7 +1690,7 @@ void CApplication::SetLanguage(Language language)
setlocale(LC_ALL, "");
- bindtextdomain("colobot", m_langPath.c_str());
+ bindtextdomain("colobot", CResourceManager::GetLanguageLocation().c_str());
bind_textdomain_codeset("colobot", "UTF-8");
textdomain("colobot");
diff --git a/src/app/app.h b/src/app/app.h
index 86a757f..66b8900 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -42,7 +42,6 @@ class CInstanceManager;
class CEventQueue;
class CRobotMain;
class CSoundInterface;
-class CGameData;
namespace Gfx {
class CModelManager;
@@ -402,8 +401,6 @@ protected:
CRobotMain* m_robotMain;
//! Profile (INI) reader/writer
CProfile* m_profile;
- //! Game data
- CGameData* m_gameData;
//! Code to return at exit
int m_exitCode;
@@ -467,16 +464,7 @@ protected:
std::vector<int> m_joyAxeState;
//! Current state of joystick buttons; may be updated from another thread
std::vector<bool> m_joyButtonState;
-
- //! Path to directory with data files
- std::string m_dataPath;
-
- //! True if datadir was passed in command line
- bool m_customDataPath;
-
- //! Path to directory with language files
- std::string m_langPath;
-
+
//@{
//! Scene to run on startup
std::string m_runSceneName;
diff --git a/src/app/gamedata.cpp b/src/app/gamedata.cpp
deleted file mode 100644
index 1bf3f36..0000000
--- a/src/app/gamedata.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2014, Polish Portal of Colobot (PPC)
-// *
-// * This program is free software: you can redistribute it and/or modify
-// * it under the terms of the GNU General Public License as published by
-// * the Free Software Foundation, either version 3 of the License, or
-// * (at your option) any later version.
-// *
-// * This program is distributed in the hope that it will be useful,
-// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// * GNU General Public License for more details.
-// *
-// * You should have received a copy of the GNU General Public License
-// * along with this program. If not, see http://www.gnu.org/licenses/.
-
-#include "app/gamedata.h"
-
-
-#include "app/app.h"
-
-#include <boost/filesystem.hpp>
-
-template<> CGameData* CSingleton<CGameData>::m_instance = nullptr;
-
-CGameData::CGameData()
-{
- m_dataDirSet = false;
-
- for (int i = 0; i < DIR_MAX; ++i)
- m_standardDataDirs[i] = nullptr;
-
- m_standardDataDirs[DIR_AI] = "ai";
- m_standardDataDirs[DIR_FONT] = "fonts";
- m_standardDataDirs[DIR_HELP] = "help";
- m_standardDataDirs[DIR_ICON] = "icons";
- m_standardDataDirs[DIR_LEVEL] = "levels";
- m_standardDataDirs[DIR_MODEL] = "models";
- m_standardDataDirs[DIR_MUSIC] = "music";
- m_standardDataDirs[DIR_SOUND] = "sounds";
- m_standardDataDirs[DIR_TEXTURE] = "textures";
-}
-
-CGameData::~CGameData()
-{
-}
-
-void CGameData::SetDataDir(std::string path)
-{
- assert(!m_dataDirSet);
- m_dataDirSet = true;
-
- m_dataDirs.insert(m_dataDirs.begin(), path);
-}
-
-void CGameData::AddMod(std::string path)
-{
- m_dataDirs.push_back(path);
-}
-
-void CGameData::Init()
-{
- std::string out = "Using datadirs: ";
- bool first = true;
- for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
- if(!first) out += ", ";
- first = false;
- out += *rit;
- }
- out += "\n";
- CLogger::GetInstancePointer()->Info(out.c_str());
-}
-
-std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath)
-{
- int index = static_cast<int>(dir);
- assert(index >= 0 && index < DIR_MAX);
-
- for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
- std::stringstream str;
- str << *rit;
- str << "/";
- str << m_standardDataDirs[index];
- if (dir == DIR_HELP)
- {
- str << "/";
- str << CApplication::GetInstancePointer()->GetLanguageChar();
- }
- str << "/";
- str << subpath;
- boost::filesystem::path path(str.str());
- if(boost::filesystem::exists(path))
- {
- return str.str();
- }
- }
-
- std::stringstream str;
- str << m_dataDirs[0];
- str << "/";
- str << m_standardDataDirs[index];
- if (dir == DIR_HELP)
- {
- str << "/";
- str << CApplication::GetInstancePointer()->GetLanguageChar();
- }
- str << "/";
- str << subpath;
- return str.str();
-}
-
-std::string CGameData::GetDataPath(const std::string &subpath)
-{
- for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
- std::string path = *rit + "/" + subpath;
- boost::filesystem::path boostPath(path);
- if(boost::filesystem::exists(boostPath))
- {
- return path;
- }
- }
- return m_dataDirs[0] + "/" + subpath;
-}
diff --git a/src/app/gamedata.h b/src/app/gamedata.h
deleted file mode 100644
index b7536a2..0000000
--- a/src/app/gamedata.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2014, Polish Portal of Colobot (PPC)
-// *
-// * This program is free software: you can redistribute it and/or modify
-// * it under the terms of the GNU General Public License as published by
-// * the Free Software Foundation, either version 3 of the License, or
-// * (at your option) any later version.
-// *
-// * This program is distributed in the hope that it will be useful,
-// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// * GNU General Public License for more details.
-// *
-// * You should have received a copy of the GNU General Public License
-// * along with this program. If not, see http://www.gnu.org/licenses/.
-
-/**
- * \file app/gamedata.h
- * \brief Game data
- */
-
-#pragma once
-
-#include "common/singleton.h"
-
-#include <string>
-#include <vector>
-
-/**
- * \enum DataDir
- * \brief Directories in data directory
- */
-enum DataDir
-{
- DIR_AI, //! < ai scripts
- DIR_FONT, //! < fonts
- DIR_HELP, //! < help files
- DIR_ICON, //! < icons & images
- DIR_LEVEL, //! < levels
- DIR_MODEL, //! < models
- DIR_MUSIC, //! < music
- DIR_SOUND, //! < sounds
- DIR_TEXTURE, //! < textures
-
- DIR_MAX //! < number of dirs
-};
-
-class CGameData : public CSingleton<CGameData>
-{
-public:
- CGameData();
- ~CGameData();
-
- void Init();
- void SetDataDir(std::string path);
- void AddMod(std::string path);
-
- std::string GetFilePath(DataDir dir, const std::string &subpath);
- std::string GetDataPath(const std::string &subpath);
-
-private:
- bool m_dataDirSet;
- std::vector<std::string> m_dataDirs;
- const char* m_standardDataDirs[DIR_MAX];
-};
-
diff --git a/src/app/main.cpp b/src/app/main.cpp
index 5c0afd3..324acc2 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -69,6 +69,7 @@ The current layout is the following:
- src/script - link with the CBot library
*/
+#include "common/resources/resourcemanager.h"
//! Entry point to the program
extern "C"
@@ -77,6 +78,8 @@ extern "C"
int SDL_MAIN_FUNC(int argc, char *argv[])
{
CLogger logger; // single istance of logger
+ CResourceManager manager(argv[0]);
+ manager.AddLocation(COLOBOT_DEFAULT_DATADIR);
// Initialize static string arrays
InitializeRestext();
diff --git a/src/app/system.cpp b/src/app/system.cpp
index eaa9e4c..b2e6b47 100644
--- a/src/app/system.cpp
+++ b/src/app/system.cpp
@@ -192,23 +192,7 @@ float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *afte
return result;
}
-std::string CSystemUtils::GetDataPath()
-{
- return COLOBOT_DEFAULT_DATADIR;
-}
-
-std::string CSystemUtils::GetLangPath()
-{
- return COLOBOT_I18N_DIR;
-}
-
std::string CSystemUtils::GetProfileFileLocation()
{
return std::string("colobot.ini");
}
-
-std::string CSystemUtils::GetSavegameDirectoryLocation()
-{
- return std::string("savegame");
-}
-
diff --git a/src/app/system.h b/src/app/system.h
index c2125fe..01f2672 100644
--- a/src/app/system.h
+++ b/src/app/system.h
@@ -130,17 +130,8 @@ public:
/** The difference is \a after - \a before. */
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0;
- //! Returns the data path (containing textures, levels, helpfiles, etc)
- virtual std::string GetDataPath();
-
- //! Returns the translations path
- virtual std::string GetLangPath();
-
//! Returns the profile (colobot.ini) file location
virtual std::string GetProfileFileLocation();
-
- //! Returns the savegame directory location
- virtual std::string GetSavegameDirectoryLocation();
};
//! Global function to get CSystemUtils instance
diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp
index 492af7d..e584cd1 100644
--- a/src/app/system_linux.cpp
+++ b/src/app/system_linux.cpp
@@ -121,31 +121,3 @@ std::string CSystemUtilsLinux::GetProfileFileLocation()
return profileFile;
}
-
-std::string CSystemUtilsLinux::GetSavegameDirectoryLocation()
-{
- std::string savegameDir;
-
- // Determine savegame dir according to XDG Base Directory Specification
- char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA");
- if (envXDG_DATA_HOME == NULL)
- {
- char *envHOME = getenv("HOME");
- if (envHOME == NULL)
- {
- savegameDir = "/tmp/colobot-savegame";
- }
- else
- {
- savegameDir = std::string(envHOME) + "/.local/share/colobot";
- }
- }
- else
- {
- savegameDir = std::string(envXDG_DATA_HOME) + "/colobot";
- }
- GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
-
- return savegameDir;
-}
-
diff --git a/src/app/system_linux.h b/src/app/system_linux.h
index 212d840..ad26454 100644
--- a/src/app/system_linux.h
+++ b/src/app/system_linux.h
@@ -47,7 +47,6 @@ public:
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
virtual std::string GetProfileFileLocation() override;
- virtual std::string GetSavegameDirectoryLocation() override;
private:
bool m_zenityAvailable;
diff --git a/src/app/system_macosx.cpp b/src/app/system_macosx.cpp
index 68f5c79..38885eb 100644
--- a/src/app/system_macosx.cpp
+++ b/src/app/system_macosx.cpp
@@ -87,16 +87,6 @@ void CSystemUtilsMacOSX::Init()
m_dataPath += "/Contents/Resources";
}
-std::string CSystemUtilsMacOSX::GetDataPath()
-{
- return m_dataPath;
-}
-
-std::string CSystemUtilsMacOSX::GetLangPath()
-{
- return m_dataPath + "/i18n";
-}
-
std::string CSystemUtilsMacOSX::GetProfileFileLocation()
{
std::string profileFile = m_ASPath + "/colobot.ini";
@@ -104,13 +94,3 @@ std::string CSystemUtilsMacOSX::GetProfileFileLocation()
GetLogger()->Trace("Profile file is %s\n", profileFile.c_str());
return profileFile;
}
-
-std::string CSystemUtilsMacOSX::GetSavegameDirectoryLocation()
-{
- std::string savegameDir = m_ASPath + "/savegame";
- boost::filesystem::create_directories(savegameDir.c_str());
- GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
-
- return savegameDir;
-}
-
diff --git a/src/app/system_macosx.h b/src/app/system_macosx.h
index b6a044b..7360af1 100644
--- a/src/app/system_macosx.h
+++ b/src/app/system_macosx.h
@@ -28,10 +28,7 @@ class CSystemUtilsMacOSX : public CSystemUtilsOther
public:
virtual void Init() override;
- virtual std::string GetDataPath() override;
- virtual std::string GetLangPath() override;
virtual std::string GetProfileFileLocation() override;
- virtual std::string GetSavegameDirectoryLocation() override;
private:
std::string m_ASPath;
std::string m_dataPath;
diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp
index f48d4e0..ffaa18a 100644
--- a/src/app/system_windows.cpp
+++ b/src/app/system_windows.cpp
@@ -128,22 +128,3 @@ std::string CSystemUtilsWindows::GetProfileFileLocation()
return profileFile;
}
-
-std::string CSystemUtilsWindows::GetSavegameDirectoryLocation()
-{
- std::string savegameDir;
-
- char* envUSERPROFILE = getenv("USERPROFILE");
- if (envUSERPROFILE == NULL)
- {
- savegameDir = "savegame";
- }
- else
- {
- savegameDir = std::string(envUSERPROFILE) + "\\colobot\\savegame";
- }
- GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
-
- return savegameDir;
-}
-
diff --git a/src/app/system_windows.h b/src/app/system_windows.h
index fbc71a1..0a41c1a 100644
--- a/src/app/system_windows.h
+++ b/src/app/system_windows.h
@@ -45,7 +45,6 @@ public:
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
virtual std::string GetProfileFileLocation() override;
- virtual std::string GetSavegameDirectoryLocation() override;
private:
std::string UTF8_Encode(const std::wstring &wstr);