Пример #1
0
Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flags) {
	List<String> dirs;

	String curdir = get_current_dir();
	list_dir_begin();
	String n = get_next();
	while (n != String()) {

		if (n != "." && n != "..") {

			if (current_is_dir())
				dirs.push_back(n);
			else {
				String rel_path = n;
				if (!n.is_rel_path()) {
					list_dir_end();
					return ERR_BUG;
				}
				Error err = copy(get_current_dir() + "/" + n, p_to + rel_path, p_chmod_flags);
				if (err) {
					list_dir_end();
					return err;
				}
			}
		}

		n = get_next();
	}

	list_dir_end();

	for (List<String>::Element *E = dirs.front(); E; E = E->next()) {
		String rel_path = E->get();
		String target_dir = p_to + rel_path;
		if (!p_target_da->dir_exists(target_dir)) {
			Error err = p_target_da->make_dir(target_dir);
			ERR_FAIL_COND_V(err, err);
		}

		Error err = change_dir(E->get());
		ERR_FAIL_COND_V(err, err);
		err = _copy_dir(p_target_da, p_to + rel_path + "/", p_chmod_flags);
		if (err) {
			change_dir("..");
			ERR_PRINT("Failed to copy recursively");
			return err;
		}
		err = change_dir("..");
		if (err) {
			ERR_PRINT("Failed to go back");
			return err;
		}
	}

	return OK;
}
Пример #2
0
/* Look for a file along PATH. If we find it, look for an enclosing prefix.
 */
static char *
find_file( const char *name )
{
	const char *path = g_getenv( "PATH" );
	char *prefix;
	char full_path[PATH_MAX];

	if( !path )
		return( NULL );

#ifdef DEBUG
	printf( "vips_guess_prefix: g_getenv( \"PATH\" ) == \"%s\"\n", path );
#endif /*DEBUG*/

#ifdef OS_WIN32
	/* Windows always searches '.' first, so prepend cwd to path.
	 */
	vips_snprintf( full_path, PATH_MAX, "%s" G_SEARCHPATH_SEPARATOR_S "%s",
		get_current_dir(), path );
#else /*!OS_WIN32*/
	vips_strncpy( full_path, path, PATH_MAX );
#endif /*OS_WIN32*/

	if( (prefix = scan_path( full_path, name )) ) 
		return( prefix );

	return( NULL );
}
Пример #3
0
void setup_default_options(ConfOptions *options)
{
	gchar *path;
	gint i;

	bookmark_add_default(".", get_current_dir());
	bookmark_add_default(_("Home"), homedir());
	path = g_build_filename(homedir(), "Desktop", NULL);
	bookmark_add_default(_("Desktop"), path);
	g_free(path);
	bookmark_add_default(_("Collections"), get_collections_dir());

	g_free(options->file_ops.safe_delete_path);
	options->file_ops.safe_delete_path = g_strdup(get_trash_dir());

	for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
		{
		options->color_profile.input_file[i] = NULL;
		options->color_profile.input_name[i] = NULL;
		}

	set_default_image_overlay_template_string(&options->image_overlay.template_string);
	options->sidecar.ext = g_strdup(".jpg;%raw;.ufraw;.xmp;%unknown");

	options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
	options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);

	for (i = 0; i < FILEDATA_MARKS_SIZE; i++)
		{
		options->marks_tooltips[i] = g_strdup_printf("%s%d", _("Mark "), i + 1);
		}

	options->help_search_engine = g_strdup(HELP_SEARCH_ENGINE);
}
Пример #4
0
string get_file_full_path(string file_path,string cur_dir)
{
	//xuegang 5种情况
	if(cur_dir=="") cur_dir=get_current_dir();
	if(file_path.size()<2) return file_path;
	if(file_path[0]=='.')
	{
		if(file_path[1]=='.')// ../../dir/file
		{
			if(file_path.size()<3) return "";
			else if(file_path[2]!='\\' && file_path[2]!='/') return "";
			return get_file_full_path(file_path.erase(0,3),get_parent_dir(cur_dir));
		}
		else if(file_path[1]=='\\' || file_path[1]=='/')// ./dir/file
		{
			return cur_dir+file_path.erase(0,1);
		}
		else return "";
	}
	else if(file_path[0]=='\\')// \dir/file
	{
		return cur_dir.substr(0,2)+file_path;
	}
	else if(file_path[1]==':')// c:/dir/file
	{
		return file_path;
	}
	else// dir/file
	{
		return cur_dir+"/"+file_path;
	}
}
Пример #5
0
/* Guess a value for the install PREFIX.
 */
static const char *
guess_prefix( const char *argv0, const char *name )
{
	char *prefix;

	/* Try to guess from argv0.
	 */
	if( argv0 ) {
		if( g_path_is_absolute( argv0 ) ) {
			/* Must point to our executable.
			 */
			if( (prefix = extract_prefix( argv0, name )) ) {
#ifdef DEBUG
				printf( "vips_guess_prefix: found \"%s\" from "
					"argv0\n", prefix );
#endif /*DEBUG*/
				return( prefix );
			} 
		}

		/* Look along path for name.
		 */
		if( (prefix = find_file( name )) ) {
#ifdef DEBUG
			printf( "vips_guess_prefix: found \"%s\" from "
				"PATH\n", prefix );
#endif /*DEBUG*/
			return( prefix );
		}
        }

#ifdef HAVE_REALPATH
	/* Try to guess from cwd. Only if this is a relative path, though. No
 	 * realpath on winders, but fortunately it seems to always generate
 	 * a full path in argv[0].
	 */
	if( !g_path_is_absolute( argv0 ) ) {
		char full_path[PATH_MAX];
		char resolved[PATH_MAX];

		vips_snprintf( full_path, PATH_MAX, 
			"%s" G_DIR_SEPARATOR_S "%s", get_current_dir(), argv0 );

		if( realpath( full_path, resolved ) ) {
			if( (prefix = extract_prefix( resolved, name )) ) {

#ifdef DEBUG
				printf( "vips_guess_prefix: found \"%s\" "
					"from cwd\n", prefix );
#endif /*DEBUG*/
				return( prefix );
			}
		}
	}
#endif /*HAVE_REALPATH*/

	/* Fall back to the configure-time prefix.
	 */
	return( VIPS_PREFIX );
}
Пример #6
0
void EditorFileDialog::_save_to_recent() {

	String dir = get_current_dir();
	Vector<String> recent = EditorSettings::get_singleton()->get_recent_dirs();

	const int max=20;
	int count=0;
	bool res=dir.begins_with("res://");

	for(int i=0;i<recent.size();i++) {
		bool cres=recent[i].begins_with("res://");
		if (recent[i]==dir || (res==cres && count>max)) {
			recent.remove(i);
			i--;
		} else {
			count++;
		}
	}

	recent.insert(0,dir);

	EditorSettings::get_singleton()->set_recent_dirs(recent);


}
Пример #7
0
void EditorFileDialog::_favorite_toggled(bool p_toggle) {
	bool res = access==ACCESS_RESOURCES;

	String cd = get_current_dir();

	Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();

	bool found = false;
	for(int i=0;i<favorited.size();i++) {
		bool cres = favorited[i].begins_with("res://");
		if (cres!=res)
			continue;

		if (favorited[i]==cd) {
			found=true;
			break;
		}
	}

	if (found) {
		favorited.erase(cd);
		favorite->set_pressed(false);
	} else {
		favorited.push_back(cd);
		favorite->set_pressed(true);
	}

	EditorSettings::get_singleton()->set_favorite_dirs(favorited);

	_update_favorites();

}
Пример #8
0
void EditorFileDialog::_update_favorites() {

	bool res = access == ACCESS_RESOURCES;

	String current = get_current_dir();
	Ref<Texture> star = get_icon("Favorites", "EditorIcons");
	favorites->clear();

	favorite->set_pressed(false);

	Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
	for (int i = 0; i < favorited.size(); i++) {
		bool cres = favorited[i].begins_with("res://");
		if (cres != res)
			continue;
		String name = favorited[i];

		bool setthis = name == current;

		if (res && name == "res://") {
			name = "/";
		} else {
			name = name.get_file() + "/";
		}

		//print_line("file: "+name);
		favorites->add_item(name, star);
		favorites->set_item_metadata(favorites->get_item_count() - 1, favorited[i]);

		if (setthis) {
			favorite->set_pressed(true);
			favorites->set_current(favorites->get_item_count() - 1);
		}
	}
}
Пример #9
0
static char* get_current_short_dir()
{
	static char path[STR_PATH_SIZE];

	char *home_dir;
	char *current_dir;
	int home_dir_len;
	int current_dir_len;

	home_dir = get_home_dir();
	current_dir = get_current_dir();

	home_dir_len = strlen(home_dir);
	current_dir_len = strlen(current_dir);

	if( current_dir_len >= home_dir_len && strncmp(home_dir, current_dir, home_dir_len) == 0 )
	{
		path[0] = '~';
		strcpy(path+1, current_dir+home_dir_len);
	}
	else
	{
		strcpy(path, current_dir);
	}

	return path;
}
Пример #10
0
/* Find the prefix part of a dir ... name is the name of this prog from argv0.
 *
 * dir					name		guess prefix
 *
 * /home/john/vips-7.6.4/bin/vips-7.6	vips-7.6	/home/john/vips-7.6.4
 * /usr/local/bin/ip			ip		/usr/local
 *
 * all other forms ... return NULL.
 */
static char *
extract_prefix( const char *dir, const char *name )
{
	char edir[PATH_MAX];
	char vname[PATH_MAX];
	int i;

#ifdef DEBUG
	printf( "extract_prefix: trying for dir = \"%s\", name = \"%s\"\n", 
		dir, name );
#endif /*DEBUG*/

	/* Is dir relative? Prefix with cwd.
	 */
	if( !g_path_is_absolute( dir ) ) {
		vips_snprintf( edir, PATH_MAX, "%s" G_DIR_SEPARATOR_S "%s",
			get_current_dir(), dir );
	}
	else {
		vips_strncpy( edir, dir, PATH_MAX );
	}

	/* Chop off the trailing prog name, plus the trailing
	 * G_DIR_SEPARATOR_S.
	 */
	if( !vips_ispostfix( edir, name ) ) 
		return( NULL );
	vips_strncpy( vname, edir, PATH_MAX );
	vname[strlen( edir ) - strlen( name ) - 1] = '\0';

	/* Remove any "/./", any trailing "/.", any trailing "/".
	 */
	for( i = 0; i < (int) strlen( vname ); i++ ) 
		if( vips_isprefix( G_DIR_SEPARATOR_S "." G_DIR_SEPARATOR_S, 
			vname + i ) )
			memcpy( vname + i, vname + i + 2, 
				strlen( vname + i + 2 ) + 1 );
	if( vips_ispostfix( vname, G_DIR_SEPARATOR_S "." ) )
		vname[strlen( vname ) - 2] = '\0';
	if( vips_ispostfix( vname, G_DIR_SEPARATOR_S ) )
		vname[strlen( vname ) - 1] = '\0';

#ifdef DEBUG
	printf( "extract_prefix: canonicalised path = \"%s\"\n", vname );
#endif /*DEBUG*/

	/* Ought to be a "/bin" at the end now.
	 */
	if( !vips_ispostfix( vname, G_DIR_SEPARATOR_S "bin" ) ) 
		return( NULL );
	vname[strlen( vname ) - strlen( G_DIR_SEPARATOR_S "bin" )] = '\0';

#ifdef DEBUG
	printf( "extract_prefix: found \"%s\"\n", vname );
#endif /*DEBUG*/

	return( vips_strdup( NULL, vname ) );
}
Пример #11
0
int DirAccess::get_current_drive() {

	String path = get_current_dir().to_lower();
	for(int i=0;i<get_drive_count();i++) {
		String d = get_drive(i).to_lower();
		if (path.begins_with(d))
			return i;
	}

	return 0;
}
Пример #12
0
Файл: files.c Проект: badcodes/c
int directory_exists(const TCHAR* filename)
{
	TCHAR* save = get_current_dir();
	if(_tchdir(filename)) {
		_tchdir(save);
		free(save);
		return 1;
	}
	else {
		return 0;
	}
}
Пример #13
0
atf::fs::path
impl::change_directory(const atf::fs::path& dir)
{
    atf::fs::path olddir = get_current_dir();

    if (olddir != dir) {
        if (::chdir(dir.c_str()) == -1)
            throw system_error(IMPL_NAME "::chdir(" + dir.str() + ")",
                               "chdir(2) failed", errno);
    }

    return olddir;
}
Пример #14
0
Error DirAccess::make_dir_recursive(String p_dir) {

	if (p_dir.length() < 1) {
		return OK;
	};

	String full_dir;

	if (p_dir.is_rel_path()) {
		//append current		
		full_dir=get_current_dir().plus_file(p_dir);

	} else {
		full_dir=p_dir;
	}

	full_dir=full_dir.replace("\\","/");

	//int slices = full_dir.get_slice_count("/");

	String base;

	if (full_dir.begins_with("res://"))
		base="res://";
	else if (full_dir.begins_with("user://"))
		base="user://";
	else if (full_dir.begins_with("/"))
		base="/";
	else if (full_dir.find(":/")!=-1) {
		base=full_dir.substr(0,full_dir.find(":/")+2);
	} else {
		ERR_FAIL_V(ERR_INVALID_PARAMETER);
	}

	full_dir=full_dir.replace_first(base,"").simplify_path();

	Vector<String> subdirs=full_dir.split("/");

	String curpath=base;
	for(int i=0;i<subdirs.size();i++) {

		curpath=curpath.plus_file(subdirs[i]);
		Error err = make_dir(curpath);
		if (err != OK && err != ERR_ALREADY_EXISTS) {

			ERR_FAIL_V(err);
		}
	}

	return OK;
}
Пример #15
0
void EditorFileDialog::set_current_file(const String &p_file) {

	file->set_text(p_file);
	update_dir();
	invalidate();
	int lp = p_file.find_last(".");
	if (lp != -1) {
		file->select(0, lp);
		file->grab_focus();
	}

	if (is_visible_in_tree())
		_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
}
Пример #16
0
void EditorFileDialog::_item_selected(int p_item) {

	int current = p_item;
	if (current<0 || current>=item_list->get_item_count())
		return;

	Dictionary d=item_list->get_item_metadata(current);

	if (!d["dir"]) {

		file->set_text(d["name"]);
		_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
	}
}
Пример #17
0
void EditorFileDialog::_post_popup() {

	ConfirmationDialog::_post_popup();
	if (invalidated) {
		update_file_list();
		invalidated=false;
	}
	if (mode==MODE_SAVE_FILE)
		file->grab_focus();
	else
		item_list->grab_focus();

	if (is_visible() && get_current_file()!="")
		_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));

	if (is_visible()) {
		Ref<Texture> folder = get_icon("folder","FileDialog");
		recent->clear();


		bool res = access==ACCESS_RESOURCES;
		Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs();
		for(int i=0;i<recentd.size();i++) {
			bool cres = recentd[i].begins_with("res://");
			if (cres!=res)
				continue;
			String name = recentd[i];
			if (res && name=="res://") {
				name="/";
			} else {
				name=name.get_file()+"/";
			}

			//print_line("file: "+name);
			recent->add_item(name,folder);
			recent->set_item_metadata( recent->get_item_count()-1,recentd[i]);
		}

		local_history.clear();
		local_history_pos=-1;
		_push_history();

		_update_favorites();
	}

	set_process_unhandled_input(true);

}
Пример #18
0
/** 
 * vips_guess_prefix:
 * @argv0: program name (typically argv[0])
 * @env_name: save prefix in this environment variable
 *
 * vips_guess_prefix() tries to guess the install directory. You should pass 
 * in the value of argv[0] (the name your program was run as) as a clue to 
 * help it out, plus the name of the environment variable you let the user 
 * override your package install area with (eg. "VIPSHOME"). 
 *
 * On success, vips_guess_prefix() returns the prefix it discovered, and as a 
 * side effect, sets the environment variable (if it's not set).
 *
 * Don't free the return string!
 * 
 * See also: vips_guess_libdir().
 *
 * Returns: the install prefix as a static string, do not free.
 */
const char *
vips_guess_prefix( const char *argv0, const char *env_name )
{
        const char *prefix;
        const char *p;
        char name[PATH_MAX];

	/* Already set?
	 */
        if( (prefix = g_getenv( env_name )) ) {
#ifdef DEBUG
		printf( "vips_guess_prefix: found \"%s\" in environment\n", 
			prefix );
#endif /*DEBUG*/
                return( prefix );
	}

	/* Get the program name from argv0.
	 */
	p = vips_skip_dir( argv0 );

	/* Add the exe suffix, if it's missing.
	 */
	if( strlen( VIPS_EXEEXT ) > 0 ) {
		const char *olds[] = { VIPS_EXEEXT };

		vips__change_suffix( p, name, PATH_MAX, VIPS_EXEEXT, olds, 1 );
	}
	else
		vips_strncpy( name, p, PATH_MAX );

#ifdef DEBUG
	printf( "vips_guess_prefix: argv0 = %s\n", argv0 );
	printf( "vips_guess_prefix: name = %s\n", name );
	printf( "vips_guess_prefix: cwd = %s\n", get_current_dir() );
#endif /*DEBUG*/

	prefix = guess_prefix( argv0, name );
	g_setenv( env_name, prefix, TRUE );

	return( prefix );
}
Пример #19
0
// Relative path
static int process_image(char *filename)
{
	char dir[PATH_MAX];
	
	char source[PATH_MAX];
	char dest[PATH_MAX];

	if (get_current_dir(filename, dir) != 0)
		return -1;

	sprintf(source,  "%s/%s", config_site.source_directory, filename);
	sprintf(dest, "%s/%s", config_site.dest_directory, dir);

	if (cp_file(source, dest) == 0) {
		// printf("Processing IMG file : %s\n", filename);
		return 0;
	} else {
		return -1;
	}
}
Пример #20
0
bool sil_load(string file_path)
{
	string cur_dir=get_current_dir();
	string file_full_path=get_file_full_path(file_path);
	set_current_dir(get_file_dir(file_path));
	int ip=get_new_code_addr(true);
	grammar_parser parser;
	parser.load_file(file_full_path);
	parser.complie();
	bool b_result=false;
	if(error_printer::get_error_count()==0)
	{
		//print_code();
		interpret vm(get_top_gener());
		vm.run(ip);
		b_result=true;
	}
	set_current_dir(cur_dir);
	return b_result;
}
Пример #21
0
bool ngspice::LoadCircuit( const char* sourceFile /*= NULL*/ )
{
	PRINT("ngspice::LoadCircuit(%s)\n", sourceFile ? sourceFile : "null empty");
	m_errMsgCircuit.clear();
	if (!sourceFile)
		return false;

	string fullname = get_path_fullname(sourceFile);
	string cd = get_current_dir();
	string dstFile = cd + fullname;
	CopyFileA(sourceFile, dstFile.c_str(), FALSE);

	string cmd = FormatString(256, "source %s", fullname.c_str());
	m_flagCheckLoadCircuit = true;
	int ret = ngSpice_Command((char*)cmd.c_str());
	m_flagCheckLoadCircuit = false;

	Do("listing");

	return 0 == m_errMsgCircuit.size();
}
Пример #22
0
			return _get_root_string() + bd.substr(1, bd.length());
		else
			return _get_root_string() + bd;

	} else {
	}

	return current_dir;
}

bool DirAccessWindows::file_exists(String p_file) {

	GLOBAL_LOCK_FUNCTION

	if (!p_file.is_abs_path())
		p_file = get_current_dir().plus_file(p_file);

	p_file = fix_path(p_file);

	//p_file.replace("/","\\");

	//WIN32_FILE_ATTRIBUTE_DATA    fileInfo;

	DWORD fileAttr;

	fileAttr = GetFileAttributesW(p_file.c_str());
	if (INVALID_FILE_ATTRIBUTES == fileAttr)
		return false;

	return !(fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
Пример #23
0
		current_dir = current_dir.replace("\\", "/");

	} //else {

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

	return worked ? OK : ERR_INVALID_PARAMETER;
}

Error DirAccessWindows::make_dir(String p_dir) {

	GLOBAL_LOCK_FUNCTION

	if (p_dir.is_rel_path())
		p_dir = get_current_dir().plus_file(p_dir);

	p_dir = fix_path(p_dir);
	p_dir = p_dir.replace("/", "\\");

	bool success;
	int err;

	p_dir = "\\\\?\\" + p_dir; //done according to
	// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx

	success = CreateDirectoryW(p_dir.c_str(), NULL);
	err = GetLastError();

	if (success) {
		return OK;
Пример #24
0
void MultiObjectSeg::nCutProcess(HFrame& curFrame)
{
	Loggger<<"Start Graph Cut!.\n";

	IndexType nbCluster = 8;
	Loggger<<"segment number = "<<nbCluster<<endl;


	Engine*	ep;
	if (! (ep = engOpen(NULL)) )
	{
		Loggger<< "Can't not start Matlab engine.\n";
		return;
	}

	//	///set buffer to display result
	IndexType	result_buffer_size = 1024*1000;
	char*		result_buffer = new char[result_buffer_size];
	engOutputBuffer(ep, result_buffer, result_buffer_size);

	///Get the executable file's path
	char cur_path[FILENAME_MAX];
	if (!get_current_dir(cur_path, sizeof(cur_path)))
	{
		return;
	}
	cur_path[sizeof(cur_path) - 1] = '\0';
	strcat(cur_path,"\\nCut");
	char cd_cur_path[FILENAME_MAX + 3] = "cd ";
	strcat(cd_cur_path, cur_path);
	engEvalString(ep, cd_cur_path );

	IndexType fId = curFrame.frame_id;
	IndexType n = boost::num_vertices(*curFrame.pcGraph);  //cur_graph_index_;
	//	//

	//	//
	mxArray *mx_distMat = NULL;
	numeric::float64* dm_buffer;
	dm_buffer = new numeric::float64[n*n];
	mx_distMat = mxCreateDoubleMatrix(n,n,mxREAL);

	//	///all
	for (int rowId = 0; rowId < n; rowId++)
	{
		/*dm_buffer[rowId*(n+1)] = 0;*/
		for (int colId = 0; colId < n; colId++)
		{
			ScalarType dist = 0.;//weight2nodes_smooth(node_vec[rowId],node_vec[colId]);
			dm_buffer[rowId * n + colId] = (numeric::float64)dist;
		}
	}

	memcpy((char*)mxGetPr(mx_distMat),(char*)dm_buffer,n*n*sizeof(numeric::float64));
	delete [] dm_buffer;
	engPutVariable(ep,"W",mx_distMat);

	char cmd_buf[128];
	sprintf(cmd_buf,"[NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(W,%d);",nbCluster);
	engEvalString(ep,cmd_buf);

	//	///Display output information
	//		Loggger<<result_buffer<<std::endl;

	mxArray *mx_NcutDiscrete = NULL;
	mx_NcutDiscrete = engGetVariable(ep,"NcutDiscrete");

	numeric::float64 *ncutDiscrete = mxGetPr(mx_NcutDiscrete);

	Loggger<<"End for each nCut.\n";
}
Пример #25
0
void EditorFileDialog::_action_pressed() {

	if (mode==MODE_OPEN_FILES) {


		String fbase=dir_access->get_current_dir();

		DVector<String> files;
		for(int i=0;i<item_list->get_item_count();i++) {
			if (item_list->is_selected(i))
				files.push_back( fbase.plus_file(item_list->get_item_text(i) ));
		}

		if (files.size()) {
			_save_to_recent();
			emit_signal("files_selected",files);
			hide();
		}

		return;
	}

	String f=dir_access->get_current_dir().plus_file(file->get_text());

	if ((mode==MODE_OPEN_ANY || mode==MODE_OPEN_FILE) && dir_access->file_exists(f)) {
		_save_to_recent();
		emit_signal("file_selected",f);
		hide();
	}else if (mode==MODE_OPEN_ANY || mode==MODE_OPEN_DIR) {


		String path=dir_access->get_current_dir();
		/*if (tree->get_selected()) {
			Dictionary d = tree->get_selected()->get_metadata(0);
			if (d["dir"]) {
				path=path+"/"+String(d["name"]);
			}
		}*/
		path=path.replace("\\","/");
		_save_to_recent();
		emit_signal("dir_selected",path);
		hide();
	}

	if (mode==MODE_SAVE_FILE) {

		bool valid=false;

		if (filter->get_selected()==filter->get_item_count()-1) {
			valid=true; //match none
		} else if (filters.size()>1 && filter->get_selected()==0) {
			// match all filters
			for (int i=0;i<filters.size();i++) {

				String flt=filters[i].get_slice(";",0);
				for (int j=0;j<flt.get_slice_count(",");j++) {

					String str = flt.get_slice(",",j).strip_edges();
					if (f.match(str)) {
						valid=true;
						break;
					}
				}
				if (valid)
					break;
			}
		} else {
			int idx=filter->get_selected();
			if (filters.size()>1)
				idx--;
			if (idx>=0 && idx<filters.size()) {

				String flt=filters[idx].get_slice(";",0);
				int filterSliceCount=flt.get_slice_count(",");
				for (int j=0;j<filterSliceCount;j++) {

					String str = (flt.get_slice(",",j).strip_edges());
					if (f.match(str)) {
						valid=true;
						break;
					}
				}

				if (!valid && filterSliceCount>0) {
					String str = (flt.get_slice(",",0).strip_edges());
					f+=str.substr(1, str.length()-1);
					_request_single_thumbnail(get_current_dir().plus_file(f.get_file()));
					file->set_text(f.get_file());
					valid=true;
				}
			} else {
				valid=true;
			}
		}


		if (!valid) {

			exterr->popup_centered_minsize(Size2(250,80));
			return;

		}

		if (dir_access->file_exists(f)) {
			confirm_save->set_text(TTR("File Exists, Overwrite?"));
			confirm_save->popup_centered(Size2(200,80));
		} else {

			_save_to_recent();
			emit_signal("file_selected",f);
			hide();
		}
	}
}
Пример #26
0
    list_append(cp->completions, zstrdup(bp->name));

  return cp;
}

DEFUN("find-file", find_file)
/*+
Edit the specified file.
Switch to a buffer visiting the file,
creating one if none already exists.
+*/
{
  char *ms;
  astr buf;

  buf = get_current_dir();
  if ((ms = minibuf_read_dir("Find file: ", astr_cstr(buf))) == NULL) {
    astr_delete(buf);
    return cancel();
  }
  astr_delete(buf);

  if (ms[0] != '\0') {
    int ret_value = find_file(ms);
    free(ms);
    return ret_value;
  }

  free(ms);
  return FALSE;
}
Пример #27
0
void GraphNodeCtr::run()
{
	Logger<<"Start!.\n";

	IndexType nbCluster = 5;

	//read_label_file("labelInfo.txt");
	//read_label_file("labelInfo_edit.txt");
	//read_label_file("labelInfo_28.txt");
	//read_corres_file("corInfo.txt");

	//read_label_file("labelInfo_456.txt");
	//read_corres_file("corInfo_456.txt");


	read_label_file("tot_labels_dancer.txt");//dancer girl_f(91-110)

	read_corres_file("tot_cor_dancer.txt");

	pca_box_ctr();


	Engine*	ep;
	if (! (ep = engOpen(NULL)) )
	{
		Logger<< "Can't not start Matlab engine.\n";
		return;
	}

	// set buffer to display result
	IndexType	result_buffer_size = 1024*1000;
	char*		result_buffer = new char[result_buffer_size];
	engOutputBuffer(ep, result_buffer, result_buffer_size);

	//Get the executable file's path
	char cur_path[FILENAME_MAX];
	if (!get_current_dir(cur_path, sizeof(cur_path)))
	{
		return;
	}
	cur_path[sizeof(cur_path) - 1] = '\0';
	strcat(cur_path,"\\nCut");
	char cd_cur_path[FILENAME_MAX + 3] = "cd ";
	strcat(cd_cur_path, cur_path);
	engEvalString(ep, cd_cur_path );
	  
	IndexType n = cur_graph_index_;
	mxArray *mx_distMat = NULL;
	numeric::float64* dm_buffer;
	dm_buffer = new numeric::float64[n*n];
	mx_distMat = mxCreateDoubleMatrix(n,n,mxREAL);
	
	ScalarType a_w = 0.01f;

	//ScalarType avg_a_dis ,a_mid;
	//compute_mid_and_avg(avg_a_dis,a_mid,&GraphNodeCtr::dist_inside_frame);
	//Logger<<"avg and mid of adjacency"<<avg_a_dis<<" "<<a_mid<<endl;
	//ScalarType avg_cor_dis,cor_dis;
	//compute_mid_and_avg(avg_cor_dis,cor_dis,&GraphNodeCtr::dist_between_frame);
	//Logger<<"avg and mid of corresponcdence"<<avg_cor_dis<<" "<<cor_dis<<endl;

	for (int i=0; i<n;i++)
	{
		//dm_buffer[i*(n+1)] = exp(-a_w * a_w);
		dm_buffer[i*(n+1)] = a_w;
		for (int j=i+1; j<n; j++)
		{
			//ScalarType dist = weight2nodes(node_vec[i],node_vec[j]);
			ScalarType dist = weight2nodes(node_vec[i],node_vec[j],a_w);
			dm_buffer[i*n+j] = dm_buffer[j*n+i] = (numeric::float64)dist;

		}

	}


	//FILE *out_file = fopen("disMat","w");
	//for (int i=0;i<n;i++)
	//{
	//	for (int j=0;j<n;j++)
	//	{
	//		//fprintf(out_file,"%lf ",dm_buffer[i*n+j]);
	//		fprintf(out_file,"%lf ",disMat(i,j));
	//	}
	//	fprintf(out_file,"\n");
	//}
	//fclose(out_file);


	//FILE *in_file = fopen("weight_1_9","r");
	//for (int i=0;i<n;i++)
	//{
	//	for (int j=0;j<n;j++)
	//	{
	//		fscanf(in_file,"%lf",&dm_buffer[i*n+j]);
	//	}
	//}
	//fclose(in_file);

	

	memcpy((char*)mxGetPr(mx_distMat),(char*)dm_buffer,n*n*sizeof(numeric::float64));
	delete [] dm_buffer;
	engPutVariable(ep,"W",mx_distMat);

	char cmd_buf[128];
	sprintf(cmd_buf,"[NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(W,%d);",nbCluster);
	engEvalString(ep,cmd_buf);

	//Display output information
	Logger<<result_buffer<<std::endl;

	mxArray *mx_NcutDiscrete = NULL;
	mx_NcutDiscrete = engGetVariable(ep,"NcutDiscrete");

	numeric::float64 *ncutDiscrete = mxGetPr(mx_NcutDiscrete);
	IndexType k=0;
	for ( IndexType i=0;i<nbCluster;i++ )
	{
		for (IndexType j=0;j<n;j++)
		{
			if ( ncutDiscrete[k++]!=0 )
			{
				node_vec[j]->graph_label = i;
			}
		}
	}
	//Visualize
	SampleSet &smp_set = SampleSet::get_instance();
	IndexType frames[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
	for ( IndexType i=0; i<3;i++ )
	{
		for (IndexType j=0; j<smp_set[frames[i]].num_vertices(); j++)
		{
			smp_set[frames[i]][j].set_visble(false);
		}
	}
	for ( IndexType i=0; i<n;i++ )
	{
		GraphCutNode &node = *(node_vec[i]);
		smp_set[node.frame][node.index].set_label(node.graph_label);
		smp_set[node.frame][node.index].set_visble(true);
	}

	Logger<<"finished\n";
}
Пример #28
0
/**
 * Main
 */
int main (int argc, char **argv)
{
    const char *libver;
    const char  *progver;

#if defined(_ANDROID)
    int tempIsAndroid = 1 ;
#else
    int tempIsAndroid = 0 ;
#endif

    char consoleBuffer[200];
    fwl_init_instance(); //before setting any structs we need a struct allocated
    fwl_ConsoleSetup(MC_DEF_AQUA , MC_TARGET_AQUA , MC_HAVE_MOTIF , MC_TARGET_MOTIF , MC_MSC_HAVE_VER , tempIsAndroid);

    /* first, get the FreeWRL shared lib, and verify the version. */
    libver = libFreeWRL_get_version();
    progver = freewrl_get_version();
    if (strcmp(progver, libver)) {
        sprintf(consoleBuffer ,"FreeWRL expected library version %s, got %s...\n",progver, libver);
        fwl_StringConsoleMessage(consoleBuffer);
    }

#ifdef _MSC_VER
    /*
    Set fonts directory
    ideally we would check if we are in a) projectfiles go ../../fonts b) else c:/windows/Fonts
    */
    if(strstr(argv[0],"projectfiles"))
    {
        /* we are testing - use local fonts (may be obsolete someday) */
        static char *fdir;
        fdir = malloc(MAX_PATH);
        strcpy(fdir,"FREEWRL_FONTS_DIR=");
        strcat(fdir,"C:/fonts");
        _putenv( fdir );
    }
    else
    {
        /* deployed system (with intalled fonts) - use system fonts
        we plan to use a professional installer to install the fonts to %windir%\Fonts directory
        where all the system fonts already are.
        Then in this program we will get the %windir%\Fonts directory, and set it as temporary
        environment variable for InputFunctions.C > makeFontsDirectory() to fetch.
        */
        static char *fdir;
        char *syspath;
        syspath = getenv("windir");
        printf("windir path=[%s]\n",syspath);
        fdir = malloc(MAX_PATH);
        strcpy(fdir,"FREEWRL_FONTS_DIR=");
        strcat(fdir,syspath);
        strcat(fdir,"/Fonts");
        _putenv( fdir );
    }
    get_current_dir();
    /* VBO preference - comment out for vbos (vertex buffer objects - a rendering optimization) */
    _putenv("FREEWRL_NO_VBOS=1");
    //_putenv("FREEWRL_USE_VBOS=1");


#endif

    /* install the signal handlers */

    signal(SIGTERM, (void(*)(int)) fv_catch_SIGQUIT);
    signal(SIGSEGV, (void(*)(int)) fv_catch_SIGSEGV);

#if !defined(CYGWIN)
    signal(SIGQUIT, (void(*)(int)) fv_catch_SIGQUIT);
    signal(SIGALRM, (void(*)(int)) fv_catch_SIGALRM);
    signal(SIGHUP,  (void(*)(int)) fv_catch_SIGHUP);
#endif

    /* Before we parse the command line, setup the FreeWRL default parameters */
    fv_params = calloc(1, sizeof(freewrl_params_t));

    /* Default values */
    fv_params->width = 600;
    fv_params->height = 400;
    fv_params->eai = FALSE;
    fv_params->fullscreen = FALSE;
    fv_params->winToEmbedInto = -1;
    fv_params->verbose = FALSE;
//   fv_params->collision = 1; // if you set it, you need to update ui button with a call
    //setMenuButton_collision(fv_params->collision);
    //fwl_init_StereoDefaults();

    /* parse command line arguments */
    if (fv_parseCommandLine(argc, argv)) {
        if(argc > 1) {
            start_url = argv[optind];
#ifdef _MSC_VER
            start_url = strBackslash2fore(start_url);
#endif
        } else {
            start_url = NULL;
        }
    }


    /* doug- redirect stdout to a file - works, useful for sending bug reports */
    /*freopen("freopen.txt", "w", stdout ); */

    /* Put env parse here, because this gives systems that do not have env vars the chance to do it their own way. */
    fv_parseEnvVars();

    /* start threads, parse initial scene, etc */
    if ( 1 == 1) {
        /* give control to the library */
        if (!fwl_initFreeWRL(fv_params)) {
            ERROR_MSG("main: aborting during initialization.\n");
            exit(1);
        }
        fwl_startFreeWRL(start_url);
    } else {
        /* keep control
        if (!fv_initFreeWRL(fv_params)) {
            ERROR_MSG("main: aborting during initialization.\n");
            exit(1);
        }
        fv_startFreeWRL(start_url); */
    }
    return 0;
}