Example #1
0
void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) {

	static const uint64_t MAX_SECS = 5 * 86400;

	DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	ERR_FAIL_COND(!da);

	Error err = da->change_dir(p_logs_dir);
	ERR_FAIL_COND(err != OK);

	ERR_FAIL_COND(da->list_dir_begin() != OK);

	String current;
	while ((current = da->get_next()).length()) {
		if (da->current_is_dir())
			continue;
		if (!current.ends_with(".txt"))
			continue;

		String name = current.get_basename();
		uint64_t unixtime = (uint64_t)name.to_int64();

		if (OS::get_singleton()->get_unix_time() - unixtime > MAX_SECS) {
			da->remove(current);
		}
	}

	da->list_dir_end();
}
Example #2
0
MonoAssembly *gdmono_MonoAssemblyPreLoad(MonoAssemblyName *aname, char **assemblies_path, void *user_data) {

	(void)user_data; // UNUSED

	MonoAssembly *assembly_loaded = mono_assembly_loaded(aname);
	if (assembly_loaded) // Already loaded
		return assembly_loaded;

	static Vector<String> search_dirs;

	if (search_dirs.empty()) {
		search_dirs.push_back(GodotSharpDirs::get_res_temp_assemblies_dir());
		search_dirs.push_back(GodotSharpDirs::get_res_assemblies_dir());
		search_dirs.push_back(OS::get_singleton()->get_resource_dir());
		search_dirs.push_back(OS::get_singleton()->get_executable_path().get_base_dir());

		const char *rootdir = mono_assembly_getrootdir();
		if (rootdir) {
			search_dirs.push_back(String(rootdir).plus_file("mono").plus_file("4.5"));
		}

		while (assemblies_path) {
			if (*assemblies_path)
				search_dirs.push_back(*assemblies_path);
			++assemblies_path;
		}
	}

	String name = mono_assembly_name_get_name(aname);
	bool has_extension = name.ends_with(".dll") || name.ends_with(".exe");

	String path;

	for (int i = 0; i < search_dirs.size(); i++) {
		const String &search_dir = search_dirs[i];

		if (has_extension) {
			path = search_dir.plus_file(name);
			if (FileAccess::exists(path))
				return gdmono_load_assembly_from(name.get_basename(), path);
		} else {
			path = search_dir.plus_file(name + ".dll");
			if (FileAccess::exists(path))
				return gdmono_load_assembly_from(name, path);

			path = search_dir.plus_file(name + ".exe");
			if (FileAccess::exists(path))
				return gdmono_load_assembly_from(name, path);
		}
	}

	return NULL;
}
Example #3
0
String EditorData::get_scene_title(int p_idx) const {
	ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
	if (!edited_scene[p_idx].root)
		return TTR("[empty]");
	if (edited_scene[p_idx].root->get_filename() == "")
		return TTR("[unsaved]");
	bool show_ext = EDITOR_DEF("interface/scene_tabs/show_extension", false);
	String name = edited_scene[p_idx].root->get_filename().get_file();
	if (!show_ext) {
		name = name.get_basename();
	}
	return name;
}
Example #4
0
void ProjectExportDialog::_export_project_to_path(const String &p_path) {
	// Save this name for use in future exports (but drop the file extension)
	default_filename = p_path.get_basename().get_file();
	EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename);

	Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
	ERR_FAIL_COND(current.is_null());
	Ref<EditorExportPlatform> platform = current->get_platform();
	ERR_FAIL_COND(platform.is_null());

	Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0);
	if (err != OK) {
		error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted: ") + platform->get_name());
		error_dialog->show();
		error_dialog->popup_centered_minsize(Size2(300, 80));
		ERR_PRINT("Failed to export project");
	}
}
Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) {

	bool compress = p_options["compress"];

	String delimiter;
	switch ((int)p_options["delimiter"]) {
		case 0: delimiter = ","; break;
		case 1: delimiter = ";"; break;
		case 2: delimiter = "\t"; break;
	}

	FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ);

	ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER);

	Vector<String> line = f->get_csv_line(delimiter);
	ERR_FAIL_COND_V(line.size() <= 1, ERR_PARSE_ERROR);

	Vector<String> locales;
	Vector<Ref<Translation> > translations;

	for (int i = 1; i < line.size(); i++) {

		String locale = line[i];
		ERR_EXPLAIN("Error importing CSV translation: '" + locale + "' is not a valid locale");
		ERR_FAIL_COND_V(!TranslationServer::is_locale_valid(locale), ERR_PARSE_ERROR);

		locales.push_back(locale);
		Ref<Translation> translation;
		translation.instance();
		translation->set_locale(locale);
		translations.push_back(translation);
	}

	line = f->get_csv_line(delimiter);

	while (line.size() == locales.size() + 1) {

		String key = line[0];
		if (key != "") {

			for (int i = 1; i < line.size(); i++) {
				translations.write[i - 1]->add_message(key, line[i]);
			}
		}

		line = f->get_csv_line(delimiter);
	}

	for (int i = 0; i < translations.size(); i++) {
		Ref<Translation> xlt = translations[i];

		if (compress) {
			Ref<PHashTranslation> cxl = memnew(PHashTranslation);
			cxl->generate(xlt);
			xlt = cxl;
		}

		String save_path = p_source_file.get_basename() + "." + translations[i]->get_locale() + ".translation";

		ResourceSaver::save(save_path, xlt);
		if (r_gen_files) {
			r_gen_files->push_back(save_path);
		}
	}

	return OK;
}