Esempio n. 1
0
String DirAccessWindows::get_current_dir() {

	String base = _get_root_path();
	if (base != "") {

		String bd = current_dir.replace("\\", "/").replace_first(base, "");
		if (bd.begins_with("/"))
			return _get_root_string() + bd.substr(1, bd.length());
		else
			return _get_root_string() + bd;

	} else {
	}

	return current_dir;
}
Esempio n. 2
0
Error DirAccessWindows::change_dir(String p_dir) {

	GLOBAL_LOCK_FUNCTION

	p_dir = fix_path(p_dir);

	wchar_t real_current_dir_name[2048];
	GetCurrentDirectoryW(2048, real_current_dir_name);
	String prev_dir = real_current_dir_name;

	SetCurrentDirectoryW(current_dir.c_str());
	bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);

	String base = _get_root_path();
	if (base != "") {

		GetCurrentDirectoryW(2048, real_current_dir_name);
		String new_dir;
		new_dir = String(real_current_dir_name).replace("\\", "/");
		if (!new_dir.begins_with(base)) {
			worked = false;
		}
	}

	if (worked) {

		GetCurrentDirectoryW(2048, real_current_dir_name);
		current_dir = real_current_dir_name; // TODO, utf8 parser
		current_dir = current_dir.replace("\\", "/");

	} //else {

	SetCurrentDirectoryW(prev_dir.c_str());
	//}

	return worked ? OK : ERR_INVALID_PARAMETER;
}