[hatari-devel] SDL GUI file and directory selection

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


I just noticed some weird behavior from SDLGui_FileConfSelect() and new SdlGui_DirSelect():

It seems these functions also return true, if a non-existent file or directory is selected. That does not make very much sense. I suggest to change the functions like this (note that there are some minor differences regarding title and readonly from Previous):

bool SDLGui_FileConfSelect(char *dlgname, char *confname, int maxlen, bool *readonly, bool bAllowNew)
{
	char *selname;

	selname = SDLGui_FileSelect("Choose a file", confname, NULL, readonly, bAllowNew);
	if (selname)
	{
		if (!File_DoesFileNameEndWithSlash(selname) &&
		    (bAllowNew || File_Exists(selname)))
		{
			strncpy(confname, selname, FILENAME_MAX);
			confname[FILENAME_MAX-1] = '\0';
			File_ShrinkName(dlgname, selname, maxlen);
			free(selname);
			return true;
		}
		dlgname[0] = confname[0] = 0;
		free(selname);
	}
	return false;
}


bool SDLGui_DirSelect(char *dlgname, char *confname, int maxlen)
{
	char *selname;
	
	selname = SDLGui_FileSelect("Choose a folder", confname, NULL, NULL, false);
	if (selname)
	{
		File_MakeValidPathName(selname);
		
		if (File_DirExists(selname))
		{
			strncpy(confname, selname, FILENAME_MAX);
			File_ShrinkName(dlgname, selname, maxlen);
			free(selname);
			return true;
		}
		dlgname[0] = confname[0] = 0;
		free(selname);
	}
	return false;
}


I also suggest to rename SdlGui_DirSelect() to SDLGui_DirSelect() for matching the naming scheme of the other functions.




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/