Exemplo n.º 1
0
Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
	FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
	bool exists = f && f->is_open();

	String tempFile = get_user_data_dir();
	if (!exists)
		return FAILED;

	if (p_path.begins_with("res://")) {
		if (PackedData::get_singleton()->has_path(p_path)) {
			print("Unable to play %S using the native player as it resides in a .pck file\n", p_path.c_str());
			return ERR_INVALID_PARAMETER;
		} else {
			p_path = p_path.replace("res:/", ProjectSettings::get_singleton()->get_resource_path());
		}
	} else if (p_path.begins_with("user://"))
		p_path = p_path.replace("user:/", get_user_data_dir());

	memdelete(f);

	print("Playing video: %S\n", p_path.c_str());
	if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track))
		return OK;
	return FAILED;
}
create_engine::create_engine(game_display& disp, saved_game& state) :
	current_level_type_(),
	current_level_index_(0),
	current_era_index_(0),
	current_mod_index_(0),
	level_name_filter_(),
	player_count_filter_(1),
	scenarios_(),
	user_maps_(),
	user_scenarios_(),
	campaigns_(),
	sp_campaigns_(),
	random_maps_(),
	user_map_names_(),
	user_scenario_names_(),
	eras_(),
	mods_(),
	state_(state),
	dependency_manager_(resources::config_manager->game_config(), disp.video()),
	generator_(NULL)
{
	DBG_MP << "restoring game config\n";

	// Restore game config for multiplayer.
	state_ = saved_game();
	state_.classification().campaign_type = game_classification::MULTIPLAYER;
	resources::config_manager->
		load_game_config_for_game(state_.classification());

	//TODO the editor dir is already configurable, is the preferences value
	get_files_in_dir(get_user_data_dir() + "/editor/maps", &user_map_names_,
		NULL, FILE_NAME_ONLY);

	get_files_in_dir(get_user_data_dir() + "/editor/scenarios", &user_scenario_names_,
		NULL, FILE_NAME_ONLY);

	DBG_MP << "initializing all levels, eras and mods\n";

	init_all_levels();
	init_extras(ERA);
	init_extras(MOD);

	state_.mp_settings().saved_game = false;

	BOOST_FOREACH (const std::string& str, preferences::modifications()) {
		if (resources::config_manager->
				game_config().find_child("modification", "id", str))
			state_.mp_settings().active_mods.push_back(str);
	}

	if (current_level_type_ != level::CAMPAIGN &&
		current_level_type_ != level::SP_CAMPAIGN) {
		dependency_manager_.try_modifications(state_.mp_settings().active_mods, true);
	}

	reset_level_filters();
}
Exemplo n.º 3
0
gint
writePalettes (void)
{
  gint ret = -1;
  xmlDocPtr doc;
  xmlNodePtr parent, child;
  gchar *localpal = NULL;

  localpal = g_build_filename (get_user_data_dir (TRUE), "actions", "palettes.xml", NULL);

  doc = xmlNewDoc ((xmlChar *) "1.0");
  doc->xmlRootNode = parent = xmlNewDocNode (doc, NULL, (xmlChar *) "Denemo", NULL);
    GList *g;
    for( g = Denemo.palettes; g; g = g->next)
        {
        child = xmlNewChild (parent, NULL, (xmlChar *) "palette", NULL);
        save_palette (child, g->data);
        }
    if (xmlSaveFormatFile (localpal, doc, 1) < 0)
    {
      g_warning ("Could not save file %s", localpal);
      ret = -1;
    } else
    ret = 0;
    xmlFreeDoc (doc);
    return ret;
}
Exemplo n.º 4
0
const std::vector<std::string>& get_binary_paths(const std::string& type)
{
	const paths_map::const_iterator itor = binary_paths_cache.find(type);
	if(itor != binary_paths_cache.end()) {
		return itor->second;
	}

	if (type.find("..") != std::string::npos) {
		// Not an assertion, as language.cpp is passing user data as type.
		ERR_FS << "Invalid WML type '" << type << "' for binary paths\n";
		static std::vector<std::string> dummy;
		return dummy;
	}

	std::vector<std::string>& res = binary_paths_cache[type];

	init_binary_paths();

	BOOST_FOREACH(const std::string &path, binary_paths)
	{
		res.push_back(get_user_data_dir() + "/" + path + type + "/");

		if(!game_config::path.empty()) {
			res.push_back(game_config::path + "/" + path + type + "/");
		}
	}
Exemplo n.º 5
0
gint
installPalettes (void)
{
gint ret;
  gchar *filename = NULL;

  GList* dirs = NULL;
 // if(Denemo.old_user_data_dir)
 //   dirs = g_list_append(dirs, g_build_filename (Denemo.old_user_data_dir, COMMANDS_DIR, NULL));
//  else
    dirs = g_list_append(dirs, g_build_filename (get_user_data_dir (TRUE), COMMANDS_DIR, NULL));
  dirs = g_list_append(dirs, g_build_filename (PACKAGE_SOURCE_DIR, COMMANDS_DIR, NULL));
  dirs = g_list_append(dirs, g_build_filename (get_system_data_dir (), COMMANDS_DIR, NULL));

  filename = find_path_for_file("palettes.xml", dirs);
  if (filename == NULL)
    {
      g_warning ("Could not find palette file.");
      return -1;
    }


  if(Denemo.old_user_data_dir)
  {
    ret = installPalettesFile (filename, TRUE);//install but hide the new standard palettes
    installPalettesFile (g_build_filename (Denemo.old_user_data_dir, COMMANDS_DIR, "palettes.xml", NULL) , FALSE);//merge users previous custom palettes, showing them
   } else
   {
     ret = installPalettesFile (filename, FALSE);//install and show palettes
    }
  return ret;
}
Exemplo n.º 6
0
editor_controller::editor_controller(const config &game_config, CVideo& video, hero_map& heros, int mode)
	: controller_base(SDL_GetTicks(), game_config, video)
	, heros_(heros)
	, mode_(mode)
	, mouse_handler_base()
	, rng_(NULL)
	, rng_setter_(NULL)
	, map_contexts_()
	, current_context_index_(0)
	, gui_(NULL)
	, map_generators_()
	, tods_()
	, palette_()
	, floating_label_manager_(NULL)
	, do_quit_(false)
	, quit_mode_(EXIT_ERROR)
	, brushes_()
	, brush_(NULL)
	, mouse_actions_()
	, mouse_action_hints_()
	, mouse_action_(NULL)
	, toolbar_dirty_(true)
	, foreground_terrain_(t_translation::MOUNTAIN)
	, background_terrain_(t_translation::GRASS_LAND)
	, clipboard_()
	, auto_update_transitions_(preferences::editor::auto_update_transitions())
	, use_mdi_(preferences::editor::use_mdi())
	, default_dir_(preferences::editor::default_dir())
{
	create_default_context();

	if (default_dir_.empty()) {
		default_dir_ = get_dir(get_dir(get_user_data_dir() + "/editor") + "/maps");
	}
	init_gui(video);
	init_brushes(game_config);
	init_mouse_actions(game_config);
	init_map_generators(game_config);
	init_tods(game_config);
	init_sidebar(game_config);
	init_music(game_config);
	hotkey_set_mouse_action(gui2::teditor_theme::HOTKEY_EDITOR_TOOL_PAINT);
	rng_.reset(new rand_rng::rng());
	rng_setter_.reset(new rand_rng::set_random_generator(rng_.get()));
	get_map_context().set_starting_position_labels(gui());
	cursor::set(cursor::NORMAL);
	image::set_color_adjustment(preferences::editor::tod_r(), preferences::editor::tod_g(), preferences::editor::tod_b());
	refresh_all();
	events::raise_draw_event();

	map_type = tmap_type();
	if (mode_ != NONE) {
		BOOST_FOREACH (const config& type, game_config.child_range("map_type")) {
			const std::string& id = type["id"];
			if (mode == SIEGE && id == "siege") {
				map_type = tmap_type(*gui_, type);
			}
		}
	}
Exemplo n.º 7
0
std::string read_map(const std::string& name)
{
	std::string res;
	std::string map_location = get_wml_location("maps/" + name);
	if(!map_location.empty()) {
		res = read_file(map_location);
	}

	if (res.empty()) {
		res = read_file(get_user_data_dir() + "/editor/maps/" + name);
	}

	return res;
}
Exemplo n.º 8
0
const std::string &get_cache_dir()
{
	if (cache_dir.empty())
	{
#if defined(_X11) && !defined(PREFERENCES_DIR)
		char const *xdg_cache = getenv("XDG_CACHE_HOME");
		if (!xdg_cache || xdg_cache[0] == '\0') {
			xdg_cache = getenv("HOME");
			if (!xdg_cache) {
				cache_dir = get_dir(get_user_data_dir() + "/cache");
				return cache_dir;
			}
			cache_dir = xdg_cache;
			cache_dir += "/.cache";
		} else cache_dir = xdg_cache;
		cache_dir += "/wesnoth";
		create_directory_if_missing_recursive(cache_dir);
#else
		cache_dir = get_dir(get_user_data_dir() + "/cache");
#endif
	}
	return cache_dir;
}
Exemplo n.º 9
0
const std::string &get_user_config_dir()
{
	if (user_config_dir.empty())
	{
#if defined(_X11) && !defined(PREFERENCES_DIR)
		char const *xdg_config = getenv("XDG_CONFIG_HOME");
		if (!xdg_config || xdg_config[0] == '\0') {
			xdg_config = getenv("HOME");
			if (!xdg_config) {
				user_config_dir = get_user_data_dir();
				return user_config_dir;
			}
			user_config_dir = xdg_config;
			user_config_dir += "/.config";
		} else user_config_dir = xdg_config;
		user_config_dir += "/wesnoth";
		create_directory_if_missing_recursive(user_config_dir);
#else
		user_config_dir = get_user_data_dir();
#endif
	}
	return user_config_dir;
}
Exemplo n.º 10
0
const file_tree_checksum& data_tree_checksum(bool reset)
{
	static file_tree_checksum checksum;
	if (reset)
		checksum.reset();
	if(checksum.nfiles == 0) {
		get_file_tree_checksum_internal("data/",checksum);
		get_file_tree_checksum_internal(get_user_data_dir() + "/data/",checksum);
		LOG_FS << "calculated data tree checksum: "
			   << checksum.nfiles << " files; "
			   << checksum.sum_size << " bytes\n";
	}

	return checksum;
}
Exemplo n.º 11
0
const std::string &get_user_config_dir()
{
	if (user_config_dir.empty())
	{
#if defined(_X11) && !defined(PREFERENCES_DIR)
		char const *xdg_config = getenv("XDG_CONFIG_HOME");
		std::string path;
		if (!xdg_config || xdg_config[0] == '\0') {
			xdg_config = getenv("HOME");
			if (!xdg_config) {
				user_config_dir = get_user_data_dir();
				return user_config_dir;
			}
			path = xdg_config;
			path += "/.config";
		} else path = xdg_config;
		path += "/wesnoth";
		set_user_config_dir(path);
#else
		user_config_dir = get_user_data_dir();
#endif
	}
	return user_config_dir;
}
Exemplo n.º 12
0
void persist_file_context::load() {
	std::string cfg_dir = get_dir(get_user_data_dir() + "/persist");

	std::string cfg_name = get_persist_cfg_name(namespace_.root_);
	if (file_exists(cfg_name) && !is_directory(cfg_name)) {
		scoped_istream file_stream = istream_file(cfg_name);
		if (!(file_stream->fail())) {
			try {
				read(cfg_,*file_stream);
			} catch (config::error &err) {
				LOG_PERSIST << err.message;
			}
		}
	}
}
Exemplo n.º 13
0
bool CMatchingDlg::SelectFile(char **fpath)
{
	g_free(m_CatFile);
	m_CatFile = NULL;
	g_free(m_SelectionName);
	m_SelectionName = NULL;

	// Set path to catalog files
	gchar *dirpath = g_path_get_dirname(*fpath);
	if (dirpath && *dirpath!='\0' && strcmp(dirpath, ".")!=0 && g_file_test(dirpath, G_FILE_TEST_IS_DIR)) {
		gtk_entry_set_text(GTK_ENTRY(m_PathEntry), dirpath);
	} else {
		gchar *extpath = CConfig::GetStr("MakeCatDlg", "Folder", NULL);
		if (extpath && *extpath!='\0' && g_file_test(extpath, G_FILE_TEST_IS_DIR)) 
			gtk_entry_set_text(GTK_ENTRY(m_PathEntry), extpath);
		else {
			gchar *defpath = g_build_filename(get_user_data_dir(), "Catalog files", NULL);
			if (force_directory(defpath))
				gtk_entry_set_text(GTK_ENTRY(m_PathEntry), defpath);
			g_free(defpath);
		}
		g_free(extpath);
	}
	g_free(dirpath);

	gtk_widget_hide(m_UseFrame);
	SetSelectMode(CATALOG_FILE);
	gchar *basename = g_path_get_basename(*fpath);
	ReadCatalogs(basename);
	g_free(basename);
	UpdatePreview(true);
	UpdateControls();

	if (gtk_dialog_run(GTK_DIALOG(m_pDlg))==GTK_RESPONSE_ACCEPT) {
		g_Project->SetStr("MatchingDlg", "File", m_CatFile);
		CConfig::SetStr("MatchingDlg", "File", m_CatFile);
		g_free(*fpath);
		*fpath = g_strdup(m_CatFile);
		g_free(m_CatFile);
		m_CatFile = NULL;
		g_free(m_SelectionName);
		m_SelectionName = NULL;
		return true;
	}
	return false;
}
Exemplo n.º 14
0
std::string get_screenshot_dir()
{
	const std::string dir_path = get_user_data_dir() + "/screenshots";
	return get_dir(dir_path);
}
Exemplo n.º 15
0
	std::vector<std::string>& res = binary_paths_cache[type];

	init_binary_paths();

	BOOST_FOREACH(const std::string &path, binary_paths)
	{
		res.push_back(get_user_data_dir() + "/" + path + type + "/");

		if(!game_config::path.empty()) {
			res.push_back(game_config::path + "/" + path + type + "/");
		}
	}

	// not found in "/type" directory, try main directory
	res.push_back(get_user_data_dir() + "/");

	if(!game_config::path.empty())
		res.push_back(game_config::path+"/");

	return res;
}

std::string get_binary_file_location(const std::string& type, const std::string& filename)
{
	DBG_FS << "Looking for '" << filename << "'.\n";

	if (filename.empty()) {
		LOG_FS << "  invalid filename (type: " << type <<")\n";
		return std::string();
	}
Exemplo n.º 16
0
void CMatchingDlg::Execute(void)
{
	int res;
	char msg[256];

	m_FrameID = 0;
	g_free(m_CatFile);
	m_CatFile = NULL;
	g_free(m_SelectionName);
	m_SelectionName = NULL;
	m_FileList = NULL;

	// Restore path to catalog files
	gchar *fpath = CConfig::GetStr("MakeCatDlg", "Folder", NULL);
	if (fpath && *fpath!='\0' && g_file_test(fpath, G_FILE_TEST_IS_DIR)) 
		gtk_entry_set_text(GTK_ENTRY(m_PathEntry), fpath);
	else {
		gchar *defpath = g_build_filename(get_user_data_dir(), "Catalog files", NULL);
		if (force_directory(defpath))
			gtk_entry_set_text(GTK_ENTRY(m_PathEntry), defpath);
		g_free(defpath);
	}
	g_free(fpath);

	// Update list of frames
	ReadFrames(false, g_Project->GetInt("MatchingDlg", "Frame", 0));

	// Update list of catalog files
	gchar *path = g_Project->GetStr("MatchingDlg", "File", NULL);
	if (!path)
		path = CConfig::GetStr("MatchingDlg", "File", NULL);
	ReadCatalogs(path);
	g_free(path);

	gtk_widget_show(m_UseFrame);

	// Check inputs
	if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_Frames), NULL)==0) {
		ShowError(m_pParent, "There are no frames usable as a reference frame.");
		return;
	}

	// Select reference frame or the first frame
	SetSelectMode(m_SelectMode);
	SetSortMode(m_FrameSort);
	UpdatePreview(true);
	UpdateControls();

	if (gtk_dialog_run(GTK_DIALOG(m_pDlg))!=GTK_RESPONSE_ACCEPT)
		return;
	gtk_widget_hide(m_pDlg);

	g_Project->SetInt("MatchingDlg", "Select", m_SelectMode);
	if (m_SelectMode == REFERENCE_FRAME)
		g_Project->SetInt("MatchingDlg", "Frame", m_FrameID);
	else {
		g_Project->SetStr("MatchingDlg", "File", m_CatFile);
		CConfig::SetStr("MatchingDlg", "File", m_CatFile);
	}
	g_Project->ClearReference();
	
	// Always all files
	gtk_tree_model_foreach(g_Project->FileList(), GtkTreeModelForeachFunc(make_list), &m_FileList);

	CProgressDlg pDlg(m_pParent, "Matching photometry files");
	pDlg.SetMinMax(0, g_list_length(m_FileList));
	res = pDlg.Execute(ExecuteProc, this);
	if (res!=0) {
		char *msg = cmpack_formaterror(res);
		ShowError(m_pParent, msg, true);
		cmpack_free(msg);
	} else if (m_OutFiles==0) {
		ShowError(m_pParent, "No file was successfully processed.", true);
	} else if (m_OutFiles!=m_InFiles) {
		sprintf(msg, "%d file(s) were successfully processed, %d file(s) failed.", 
			m_OutFiles, m_InFiles-m_OutFiles);
		ShowWarning(m_pParent, msg, true);
	} else {
		sprintf(msg, "All %d file(s) were successfully processed.", m_OutFiles);
		ShowInformation(m_pParent, msg, true);
	}

	// Free allocated memory
	g_list_foreach(m_FileList, (GFunc)gtk_tree_row_reference_free, NULL);
	g_list_free(m_FileList);
	m_FileList = NULL;
	g_free(m_CatFile);
	m_CatFile = NULL;
	g_free(m_SelectionName);
	m_SelectionName = NULL;
}
Exemplo n.º 17
0
static std::string get_persist_cfg_name(const std::string &name_space) {
	return (get_dir(get_user_data_dir() + "/persist/") + name_space + ".cfg");
}
Exemplo n.º 18
0
std::string get_save_index_file()
{
	return get_user_data_dir() + "/save_index";
}
Exemplo n.º 19
0
	std::string get_saves_dir()
	{
		const std::string dir_path = get_user_data_dir() + "/saves";
		return get_dir(dir_path);
	}
Exemplo n.º 20
0
std::string get_addon_campaigns_dir()
{
	const std::string dir_path = get_user_data_dir() + "/data/add-ons";
	return get_dir(dir_path);
}