// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
+#include <config.h>
+
#include <assert.h>
+#include <unistd.h>
#include "app/setup.h"
#include "level.h"
#include "app/globals.h"
new_subset.name = subset_name;
new_subset.title = "Unknown Title";
new_subset.description = "No description so far.";
+ new_subset.hide_from_contribs = false;
new_subset.save();
}
void LevelSubset::read_info_file(const std::string& info_file)
{
lisp_object_t* root_obj = lisp_read_from_file(info_file);
+ if (root_obj == NULL)
+ return;
lisp_object_t* cur = lisp_car(root_obj);
if (lisp_symbol_p(cur) && strcmp(lisp_symbol(cur), "supertux-level-subset") == 0)
reader.read_string("title", title, true);
reader.read_string("description", description, true);
reader.read_string_vector("levels", levels);
+ hide_from_contribs = false;
+ reader.read_bool("hide-from-contribs", hide_from_contribs);
}
else
{
lisp_free(root_obj);
}
-void LevelSubset::load(const char* subset)
+void LevelSubset::load(const std::string& subset)
{
name = subset;
// Check in which directory our subset is located (ie. ~/.supertux/
// or SUPERTUX_DATADIR)
- char filename[1024];
- snprintf(filename, 1024, "%s/levels/%s/", st_dir, subset);
- if (access(filename, R_OK) == 0)
- {
- directory = filename;
- }
- else
+ std::string filename;
+ filename = st_dir + "/levels/" + subset + "/info";
+ if (access(filename.c_str(), R_OK) != 0)
{
- snprintf(filename, 1024, "%s/levels/%s/", datadir.c_str(), subset);
- if (access(filename, R_OK) == 0)
- directory = filename;
- else
+ filename = datadir + "/levels/" + subset + "/info";
+ if (access(filename.c_str(), R_OK) != 0)
std::cout << "Error: LevelSubset: couldn't find subset: " << subset << std::endl;
}
- read_info_file(directory + "info");
+ read_info_file(filename);
if (levels.empty())
{ // Level info file doesn't define any levels, so read the
// directory to see what we can find
- std::vector<std::string> files;
+ std::set<std::string> files;
- snprintf(filename, 1024, "%s/levels/%s/", st_dir, subset);
- if(access(filename, R_OK) == 0)
- {
- files = FileSystem::read_directory(filename);
- }
- else
- {
- snprintf(filename, 1024, "%s/levels/%s/", datadir.c_str(), subset);
- files = FileSystem::read_directory(filename);
- }
+ filename = datadir + "/levels/" + subset + "/";
+ files = FileSystem::read_directory(filename);
+
+ filename = st_dir + "/levels/" + subset + "/";
+ std::set<std::string> user_files = FileSystem::read_directory(filename);
+ files.insert(user_files.begin(), user_files.end());
- for(std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i)
+ for(std::set<std::string>::iterator i = files.begin(); i != files.end(); ++i)
{
if (has_suffix(*i, ".stl"))
- levels.push_back(*i);
+ levels.push_back(subset+ "/" + *i);
}
}
}
/* Save the description: */
fprintf(fi," (description \"%s\")\n", description.c_str());
+ /* Save the hide from Contrbis menu boolean: */
+ fprintf(fi," (hide-from-contribs %s)\n", hide_from_contribs ? "#t" : "#f");
+
fprintf( fi,")");
fclose(fi);
}
LevelSubset::get_level_filename(unsigned int num)
{
assert(num < levels.size());
-
- return directory + levels[num];
+ return levels[num];
}
int