|
From: Markus R. <god...@us...> - 2009-07-29 15:36:01
|
Module: performous
Branch: master
Commit: 5206710e9ecbe137118ca071fc1c25e908c21bca
Author: Markus Raab <un...@ma...>
Date: Wed Jul 29 10:03:12 2009 +0200
use share path
---
data/performous.xml | 9 +++++++++
game/fs.cc | 13 +++++++++++++
game/fs.hh | 3 +++
game/main.cc | 3 ++-
game/players.cc | 3 +--
5 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/data/performous.xml b/data/performous.xml
index 3760fa7..0183814 100644
--- a/data/performous.xml
+++ b/data/performous.xml
@@ -198,6 +198,15 @@
<long>Where to recursively look for songs.</long>
</locale>
</entry>
+ <entry name="system/path_share" type="string_list">
+ <stringvalue>~/.local/share</stringvalue>
+ <stringvalue>../share</stringvalue><!-- For Windows where the program is started in bin/ -->
+ <stringvalue>~/.performous/share</stringvalue>
+ <locale name="C">
+ <short>Data folders</short>
+ <long>Where Performous data are stored.</long>
+ </locale>
+ </entry>
<entry name="system/path_pictures" type="string_list">
<stringvalue>/usr/local/share/games/performous/pictures</stringvalue>
<stringvalue>/usr/share/games/performous/pictures</stringvalue>
diff --git a/game/fs.cc b/game/fs.cc
index f504fc1..82a5f93 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -49,6 +49,19 @@ std::string getDataPath(std::string const& filename) {
ConfigItem::StringList sd = config["system/path_data"].sl();
for (std::vector<std::string>::const_iterator it = sd.begin(); it != sd.end(); ++it) {
fs::path p = *it;
+ p = pathMangle(p);
+ if (fs::is_directory(p)) { data_dir = p.string(); break; }
+ }
+ return data_dir + "/" + filename;
+}
+
+std::string getSharePath(std::string const& filename) {
+ // Figure out theme folder (if theme name rather than path was given)
+ std::string data_dir;
+ ConfigItem::StringList sd = config["system/path_share"].sl();
+ for (std::vector<std::string>::const_iterator it = sd.begin(); it != sd.end(); ++it) {
+ fs::path p = *it;
+ p = pathMangle(p);
if (fs::is_directory(p)) { data_dir = p.string(); break; }
}
return data_dir + "/" + filename;
diff --git a/game/fs.hh b/game/fs.hh
index ea02bbe..6500baa 100644
--- a/game/fs.hh
+++ b/game/fs.hh
@@ -16,3 +16,6 @@ std::string getThemePath(std::string const& filename);
/** Get full path to a data file **/
std::string getDataPath(std::string const& filename);
+
+/** Get full path to a share file **/
+std::string getSharePath(std::string const& filename);
diff --git a/game/main.cc b/game/main.cc
index 4d80e8c..d8f5848 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -134,7 +134,8 @@ void mainLoop() {
Audio audio;
audioSetup(capture, audio);
Songs songs(songlist);
- Players players("players.xml"); // TODO: retrieve from configuration
+ Players players(getSharePath("performous.xml"));
+ try {players.load();} catch(...) {std::cerr << "Could not load players" << std::endl;}
ScreenManager sm;
Window window(config["graphic/window_width"].i(), config["graphic/window_height"].i(), config["graphic/fullscreen"].b(), config["graphic/fs_width"].i(), config["graphic/fs_height"].i());
sm.addScreen(new ScreenIntro("Intro", audio, capture));
diff --git a/game/players.cc b/game/players.cc
index 9eeb442..fa00013 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -17,12 +17,11 @@ Players::Players(std::string filename):
m_dirty(false),
cur()
{
- load();
m_filtered = m_players;
}
Players::~Players() {
- save();
+ try { save(); } catch (...) { std::cerr << "Could not save players to " << m_filename << std::endl; }
}
void Players::load() {
|