Re: [hatari-devel] SDL GUI file and directory selection |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] SDL GUI file and directory selection
- From: Andreas Grabher <andreas_g86@xxxxxxxxxx>
- Date: Sat, 15 Oct 2022 15:21:25 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1665840088; bh=l8wbuzYDxTX3/b3CMqW0UpeMoyUbj9RWA9olHkIkyJ8=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id; b=wSTN+iuoaWChcrp2iBZOLRIFBsGXeACv644f6w3Zuz2ZupHgT5dtjdqNiVRUK/yhL F0A0+xeLZCHAnUF8EtCccE3ZqhaprGd6YnF+Z3NB0kjZjXS09XKCVtRPsqgJShbjSG uIoiRT4OXKgU6dRWAoiIg0pmyoI+LvGHR0RkFNltParFBW4lXIzR7z4MPe9uFNgYku oeFtV7Wcc9/aD28mto2DUjzQMi6FGYOXyCdow5NlCpl87OaepOW+hqoN4ZYXdLEk6v bXgK/B0KRH+ESI9+eX9LDjXfwmS5fi863r7tDswwLRGZ85+Aa4cgSCVNQXNKwCOjPh WbjvfegAjkJhw==
Path is always valid (or '\0' in case of /somefile) after File_MakeValidPathName(). So SDLGui_DirSelect() can be further simplified like this:
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);
strncpy(confname, selname, FILENAME_MAX);
File_ShrinkName(dlgname, selname, maxlen);
free(selname);
return true;
}
return false;
}
> Am 15.10.2022 um 10:41 schrieb Andreas Grabher <andreas_g86@xxxxxxxxxx>:
>
> 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.
>
>
>