|
From: Lasse Kärkkäi. <tr...@us...> - 2009-12-30 07:02:32
|
Module: performous
Branch: master
Commit: f8e2f52818d0f431b0d7ca31c93b7791a08183b4
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Dec 30 09:02:14 2009 +0200
Add songdir config back, modified so that it uses data dirs
---
data/schema.xml | 12 ++++++++++++
game/fs.cc | 34 ++++++++++++++++++++++++++++------
game/fs.hh | 2 ++
game/main.cc | 12 +++++++++++-
game/songs.cc | 3 +--
5 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/data/schema.xml b/data/schema.xml
index 3a8189b..e3099df 100644
--- a/data/schema.xml
+++ b/data/schema.xml
@@ -217,6 +217,18 @@ to save the current settings to XML.
</entry>
<!-- System preferences -->
+ <entry name="system/path_songs" type="string_list">
+ <stringvalue>DATADIR/songs/</stringvalue>
+ <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>~/.ultrastar/songs/</stringvalue>
+ <locale name="C">
+ <short>Song folders</short>
+ <long>Where to recursively look for songs. DATADIR at the beginning means all Performous data folders.</long>
+ </locale>
+ </entry>
<entry name="system/path" type="string_list">
<locale name="C">
<short>Base folders for data</short>
diff --git a/game/fs.cc b/game/fs.cc
index 6b4e015..9e4f665 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -72,13 +72,14 @@ fs::path pathMangle(fs::path const& dir) {
std::string getThemePath(std::string const& filename) {
std::string theme = config["game/theme"].s();
- if (theme.empty()) throw std::runtime_error("Configuration value game/theme is empty");
- // Figure out theme folder (if theme name rather than path was given)
- if (theme.find('/') == std::string::npos) {
+ static const std::string defaultTheme = "default";
+ if (theme.empty()) theme = defaultTheme;
+ // Try current theme and if that fails, try default theme.
+ try {
return getPath(fs::path("themes") / theme / filename);
- } else {
- if (*theme.rbegin() == '/') theme.erase(theme.size() - 1); // Remove trailing slash
- return theme + "/" + filename;
+ } catch (std::runtime_error&) {
+ if (theme == defaultTheme) throw;
+ return getPath(fs::path("themes") / defaultTheme / filename);
}
}
@@ -146,3 +147,24 @@ Paths const& getPaths(bool refresh) {
return paths;
}
+Paths getPathsConfig(std::string const& confOption) {
+ Paths ret;
+ Paths const& paths = getPaths();
+ ConfigItem::StringList const& sl = config[confOption].sl();
+ for (ConfigItem::StringList::const_iterator it = sl.begin(), end = sl.end(); it != end; ++it) {
+ fs::path p = pathMangle(*it);
+ if (p.empty()) continue; // Ignore empty paths
+ if (*p.begin() == "DATADIR") {
+ // Remove first element
+ p = p.string().substr(7);
+ // Add all data paths with p appended to them
+ for (Paths::const_iterator it2 = paths.begin(), end2 = paths.end(); it2 != end2; ++it2) {
+ ret.push_back(*it2 / p);
+ }
+ continue;
+ }
+ ret.push_back(p);
+ }
+ return ret;
+}
+
diff --git a/game/fs.hh b/game/fs.hh
index cbf03f8..1377f7c 100644
--- a/game/fs.hh
+++ b/game/fs.hh
@@ -26,3 +26,5 @@ typedef std::vector<fs::path> Paths;
/** Get all shared data paths in preference order **/
Paths const& getPaths(bool refresh = false);
+/** Get all paths listed in a config option **/
+Paths getPathsConfig(std::string const& confOption);
diff --git a/game/main.cc b/game/main.cc
index cfcc02b..204b032 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -223,6 +223,7 @@ 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;
@@ -237,12 +238,20 @@ 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::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
+ po::options_description allopts(cmdline);
+ allopts.add(opt3);
+ po::store(po::command_line_parser(argc, argv).options(allopts).positional(p).run(), vm);
} catch (std::exception& e) {
std::cout << cmdline << std::endl;
std::cout << "ERROR: " << e.what() << std::endl;
@@ -299,6 +308,7 @@ 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 e942796..78609b9 100644
--- a/game/songs.cc
+++ b/game/songs.cc
@@ -39,9 +39,8 @@ void Songs::reload_internal() {
m_songs.clear();
m_dirty = true;
}
- Paths paths = getPaths();
+ Paths paths = getPathsConfig("system/path_songs");
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();
|