|
From: Lasse Kärkkäi. <tr...@us...> - 2009-12-30 06:20:50
|
Module: performous
Branch: master
Commit: 703a87327c9ed03c7a8f3d726403b92b825bf191
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Dec 30 08:19:50 2009 +0200
Simplified data folder configuration. This removes some features such as being able to specify songdirs from command line.
---
data/schema.xml | 24 ------------------------
game/backgrounds.cc | 8 +++-----
game/backgrounds.hh | 2 --
game/fs.cc | 32 +++++++++++++++++++-------------
game/fs.hh | 7 +++++++
game/main.cc | 12 +-----------
game/songs.cc | 8 +++-----
game/songs.hh | 2 --
8 files changed, 33 insertions(+), 62 deletions(-)
diff --git a/data/schema.xml b/data/schema.xml
index 47ad73d..3a8189b 100644
--- a/data/schema.xml
+++ b/data/schema.xml
@@ -217,30 +217,6 @@ to save the current settings to XML.
</entry>
<!-- System preferences -->
- <entry name="system/path_songs" type="string_list">
- <stringvalue>/usr/local/share/games/ultrastar/songs/</stringvalue>
- <stringvalue>/usr/local/share/games/fretsonfire/data/songs/</stringvalue>
- <stringvalue>/usr/share/games/ultrastar/songs/</stringvalue>
- <stringvalue>/usr/share/games/fretsonfire/data/songs/</stringvalue>
- <stringvalue>../songs/</stringvalue><!-- For Windows where the program is started in bin/ -->
- <stringvalue>~/.local/share/games/performous/songs/</stringvalue>
- <stringvalue>~/.ultrastar/songs/</stringvalue>
- <stringvalue>~/.fretsonfire/songs/</stringvalue>
- <locale name="C">
- <short>Song folders</short>
- <long>Where to recursively look for songs.</long>
- </locale>
- </entry>
- <entry name="system/path_backgrounds" type="string_list">
- <stringvalue>/usr/local/share/games/performous/backgrounds/</stringvalue>
- <stringvalue>/usr/share/games/performous/backgrounds/</stringvalue>
- <stringvalue>../backgrounds/</stringvalue><!-- For Windows where the program is started in bin/ -->
- <stringvalue>~/.local/share/games/performous/backgrounds/</stringvalue>
- <locale name="C">
- <short>Background folders</short>
- <long>Where to look for backgrounds.</long>
- </locale>
- </entry>
<entry name="system/path" type="string_list">
<locale name="C">
<short>Base folders for data</short>
diff --git a/game/backgrounds.cc b/game/backgrounds.cc
index 22a3e99..4aaf895 100644
--- a/game/backgrounds.cc
+++ b/game/backgrounds.cc
@@ -15,10 +15,6 @@
void Backgrounds::reload() {
if (m_loading) return;
- // Copy backgrounddirs from config into m_bgdirs
- ConfigItem::StringList sd = config["system/path_backgrounds"].sl();
- m_bgs.clear();
- std::transform(sd.begin(), sd.end(), std::inserter(m_bgdirs, m_bgdirs.end()), pathMangle);
// Run loading thread
m_loading = true;
m_thread.reset(new boost::thread(boost::bind(&Backgrounds::reload_internal, boost::ref(*this))));
@@ -30,7 +26,9 @@ void Backgrounds::reload_internal() {
m_bgs.clear();
m_dirty = true;
}
- for (BGDirs::const_iterator it = m_bgdirs.begin(); m_loading && it != m_bgdirs.end(); ++it) {
+ Paths paths = getPaths();
+ for (Paths::iterator it = paths.begin(); m_loading && it != paths.end(); ++it) {
+ *it /= "backgrounds";
if (!fs::is_directory(*it)) { std::cout << ">>> Not scanning for backgrounds: " << *it << " (no such directory)" << std::endl; continue; }
std::cout << ">>> Scanning " << *it << " (for backgrounds)" << std::endl;
size_t count = m_bgs.size();
diff --git a/game/backgrounds.hh b/game/backgrounds.hh
index f25e2aa..b687dc4 100644
--- a/game/backgrounds.hh
+++ b/game/backgrounds.hh
@@ -34,9 +34,7 @@ class Backgrounds: boost::noncopyable {
std::string getRandom();
private:
- typedef std::set<fs::path> BGDirs;
typedef std::vector<std::string> BGVector;
- BGDirs m_bgdirs;
BGVector m_bgs;
int m_bgiter;
void reload_internal();
diff --git a/game/fs.cc b/game/fs.cc
index 89e1f9f..6b4e015 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -5,7 +5,6 @@
#include <plugin++/execname.hpp>
#include <cstdlib>
#include <iostream>
-#include <list>
#include <sstream>
#ifdef _WIN32
@@ -95,13 +94,23 @@ namespace {
}
std::string getPath(fs::path const& filename) {
- typedef std::list<fs::path> Dirs;
- static Dirs dirs;
+ Paths const& paths = getPaths();
+ for (Paths::const_iterator it = paths.begin(); it != paths.end(); ++it) {
+ fs::path p = *it;
+ p /= filename;
+ if( fs::exists(p) ) return p.string();
+ }
+ throw std::runtime_error("Cannot find file \"" + filename.string() + "\" in any of Performous data folders");
+}
+
+Paths const& getPaths(bool refresh) {
+ static Paths paths;
static bool initialized = false;
- if (!initialized) {
+ if (!initialized || refresh) {
initialized = true;
fs::path shortDir = "performous";
fs::path shareDir = SHARED_DATA_DIR;
+ Paths dirs;
#ifdef _WIN32
// Add APPLIC~1 (user-specific application data) FIXME: Not tested
{
@@ -128,15 +137,12 @@ std::string getPath(fs::path const& filename) {
}
#endif
// Adding paths from config file
- std::vector<std::string> pathes = config["system/path"].sl();
- std::transform(pathes.begin(), pathes.end(), std::inserter(dirs, dirs.end()), pathMangle);
+ std::vector<std::string> const& confPaths = config["system/path"].sl();
+ std::transform(confPaths.begin(), confPaths.end(), std::inserter(dirs, dirs.end()), pathMangle);
// Check if they actually exist and print debug
- dirs.remove_if(pathNotExist);
+ paths.clear();
+ std::remove_copy_if(dirs.begin(), dirs.end(), std::inserter(paths, paths.end()), pathNotExist);
}
- for (Dirs::const_iterator it = dirs.begin(); it != dirs.end(); ++it) {
- fs::path p = *it;
- p /= filename;
- if( fs::exists(p) ) return p.string();
- }
- throw std::runtime_error("Cannot find file \"" + filename.string() + "\" in any of Performous data folders");
+ return paths;
}
+
diff --git a/game/fs.hh b/game/fs.hh
index 2756e8d..cbf03f8 100644
--- a/game/fs.hh
+++ b/game/fs.hh
@@ -1,6 +1,7 @@
#pragma once
#include <boost/filesystem.hpp>
+#include <vector>
// Define this useful alias for the overlong namespace name (yes, for everyone who includes this header)
namespace fs = boost::filesystem;
@@ -19,3 +20,9 @@ std::string getThemePath(std::string const& filename);
/** Get full path to a share file **/
std::string getPath(fs::path const& filename);
+
+typedef std::vector<fs::path> Paths;
+
+/** Get all shared data paths in preference order **/
+Paths const& getPaths(bool refresh = false);
+
diff --git a/game/main.cc b/game/main.cc
index 204b032..cfcc02b 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -223,7 +223,6 @@ int main(int argc, char** argv) {
// Parse commandline options
std::vector<std::string> mics;
std::vector<std::string> pdevs;
- std::vector<std::string> songdirs;
namespace po = boost::program_options;
po::options_description opt1("Generic options");
std::string songlist;
@@ -238,20 +237,12 @@ int main(int argc, char** argv) {
("michelp", "detailed help and device list for --mics")
("pdevhelp", "detailed help and device list for --pdev")
("theme", po::value<std::string>(), "set theme (name or absolute path)");
- po::options_description opt3("Hidden options");
- opt3.add_options()
- ("songdir", po::value<std::vector<std::string> >(&songdirs)->composing(), "");
- // Process flagless options as songdirs
- po::positional_options_description p;
- p.add("songdir", -1);
po::options_description cmdline;
cmdline.add(opt1).add(opt2);
po::variables_map vm;
// Load the arguments
try {
- po::options_description allopts(cmdline);
- allopts.add(opt3);
- po::store(po::command_line_parser(argc, argv).options(allopts).positional(p).run(), vm);
+ po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
} catch (std::exception& e) {
std::cout << cmdline << std::endl;
std::cout << "ERROR: " << e.what() << std::endl;
@@ -308,7 +299,6 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
// Override XML config for options that were specified from commandline or performous.conf
- confOverride(songdirs, "system/path_songs");
confOverride(mics, "audio/capture");
confOverride(pdevs, "audio/playback");
// Run the game init and main loop
diff --git a/game/songs.cc b/game/songs.cc
index e0c3732..e942796 100644
--- a/game/songs.cc
+++ b/game/songs.cc
@@ -27,10 +27,6 @@ Songs::~Songs() {
void Songs::reload() {
if (m_loading) return;
- // Copy songdirs from config into m_songdirs
- ConfigItem::StringList const& sd = config["system/path_songs"].sl();
- m_songdirs.clear();
- std::transform(sd.begin(), sd.end(), std::inserter(m_songdirs, m_songdirs.end()), pathMangle);
// Run loading thread
m_needShuffle = false;
m_loading = true;
@@ -43,7 +39,9 @@ void Songs::reload_internal() {
m_songs.clear();
m_dirty = true;
}
- for (SongDirs::const_iterator it = m_songdirs.begin(); m_loading && it != m_songdirs.end(); ++it) {
+ Paths paths = getPaths();
+ for (Paths::iterator it = paths.begin(); m_loading && it != paths.end(); ++it) {
+ *it /= "songs";
if (!fs::is_directory(*it)) { std::cout << ">>> Not scanning: " << *it << " (no such directory)" << std::endl; continue; }
std::cout << ">>> Scanning " << *it << std::endl;
size_t count = m_songs.size();
diff --git a/game/songs.hh b/game/songs.hh
index 7ae1545..849709d 100644
--- a/game/songs.hh
+++ b/game/songs.hh
@@ -66,8 +66,6 @@ class Songs: boost::noncopyable {
private:
class RestoreSel;
typedef std::vector<boost::shared_ptr<Song> > SongVector;
- typedef std::set<fs::path> SongDirs;
- SongDirs m_songdirs;
std::string m_songlist;
SongVector m_songs, m_filtered;
AnimAcceleration math_cover;
|