Skip to content
Snippets Groups Projects
Commit 62006e72 authored by deuce's avatar deuce
Browse files

Do horrible things to support Windows namespace where drive letters are

located speciously designated as "\\?\" but displayed and input as ""
since that's how Windows users think of it.
parent 608242da
No related branches found
No related tags found
No related merge requests found
...@@ -161,7 +161,7 @@ char *getdirname(char *path) ...@@ -161,7 +161,7 @@ char *getdirname(char *path)
#endif #endif
p2 = path; p2 = path;
if(p1 > path) { if(p1 > path) {
for(p2=p1-1; p2>=path && !IS_PATH_DELIM(*p2); p2--); for(p2=p1-1; p2>path && !IS_PATH_DELIM(*p2); p2--);
if(IS_PATH_DELIM(*p2) && *(p2+1)) if(IS_PATH_DELIM(*p2) && *(p2+1))
p2++; p2++;
} }
...@@ -219,6 +219,8 @@ void display_current_path(uifcapi_t *api, char *path) ...@@ -219,6 +219,8 @@ void display_current_path(uifcapi_t *api, char *path)
if(*p=='/') if(*p=='/')
*p='\\'; *p='\\';
} }
if (strncmp(dpath, "\\\\?\\", 4)==0)
memmove(dpath, dpath+4, strlen(dpath+3));
#endif #endif
api->printf(SCRN_LEFT+2, SCRN_TOP+height-2, api->lclr|(api->bclr<<4), "%-*s", width, dpath); api->printf(SCRN_LEFT+2, SCRN_TOP+height-2, api->lclr|(api->bclr<<4), "%-*s", width, dpath);
...@@ -370,8 +372,18 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char ...@@ -370,8 +372,18 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
hold_update = TRUE; hold_update = TRUE;
api->printf(SCRN_LEFT+8, SCRN_TOP+height-3, api->lclr|(api->bclr<<4), "%-*s", width-7, cmsk); api->printf(SCRN_LEFT+8, SCRN_TOP+height-3, api->lclr|(api->bclr<<4), "%-*s", width-7, cmsk);
tmppath=strdup(cpath); tmppath=strdup(cpath);
if(tmppath != NULL) if(tmppath != NULL) {
#ifdef _WIN32
if (tmppath[0] == 0 || (tmppath[5]==0 && tmppath[3]=='.' && tmppath[4]=='.' && tmppath[1]==':' && IS_PATH_DELIM(tmppath[2])))
strcpy(cpath, "\\\\?\\");
else if(strncmp(tmppath, "\\\\?\\", 4)==0 && tmppath[4])
strcpy(cpath, tmppath+4);
else
#endif
{
FULLPATH(cpath,tmppath,sizeof(cpath)); FULLPATH(cpath,tmppath,sizeof(cpath));
}
}
FREE_AND_NULL(tmppath); FREE_AND_NULL(tmppath);
#ifdef __unix__ #ifdef __unix__
...@@ -399,9 +411,35 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char ...@@ -399,9 +411,35 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
root=TRUE; root=TRUE;
else else
root=FALSE; root=FALSE;
#else
/* #error Need to do something about root paths (in get_file_opt_list() too!) */
#endif #endif
#ifdef _WIN32
if (strcmp(cpath, "\\\\?\\")==0)
root = TRUE;
else
root = FALSE;
#endif
#ifdef _WIN32
// Hack together some hawtness
if (root) {
unsigned long drives = _getdrives();
int j;
char path[4];
memset(&dgl, 0, sizeof(dgl));
strcpy(path, "A:\\");
dgl.gl_pathv=malloc(sizeof(char *)*('Z'-'A'+2));
for (j=0; j<='Z'-'A'; j++) {
if(drives & (1<<j)) {
path[0]='A'+j;
dgl.gl_pathv[dgl.gl_pathc++]=strdup(path);
}
}
}
else
#endif
{
if(glob(dglob, GLOB_MARK, NULL, &dgl)!=0 && !isdir(cpath)) { if(glob(dglob, GLOB_MARK, NULL, &dgl)!=0 && !isdir(cpath)) {
if(lastpath==NULL) { if(lastpath==NULL) {
fp->files=0; fp->files=0;
...@@ -415,6 +453,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char ...@@ -415,6 +453,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
currfield=lastfield; currfield=lastfield;
continue; continue;
} }
}
if(glob(cglob, 0, NULL, &fgl)!=0) if(glob(cglob, 0, NULL, &fgl)!=0)
fgl.gl_pathc=0; fgl.gl_pathc=0;
api->list_height=api->scrn_len-3-7; api->list_height=api->scrn_len-3-7;
...@@ -492,25 +531,41 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char ...@@ -492,25 +531,41 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
case CURRENT_PATH: case CURRENT_PATH:
FREE_AND_NULL(tmplastpath); FREE_AND_NULL(tmplastpath);
tmplastpath=strdup(cpath); tmplastpath=strdup(cpath);
#ifdef _WIN32
if (strncmp(tmplastpath, "\\\\?\\", 4)==0)
memmove(tmplastpath, tmplastpath+4, strlen(tmplastpath+3));
if (strncmp(cfile, "\\\\?\\", 4)==0)
memmove(cfile, cfile+4, strlen(cfile+3));
#endif
api->getstrxy(SCRN_LEFT+2, SCRN_TOP+height-2, width-1, cfile, sizeof(cfile)-1, K_EDIT|K_TABEXIT|K_MOUSEEXIT, &i); api->getstrxy(SCRN_LEFT+2, SCRN_TOP+height-2, width-1, cfile, sizeof(cfile)-1, K_EDIT|K_TABEXIT|K_MOUSEEXIT, &i);
if(i==ESC) { if(i==ESC) {
retval=fp->files=0; retval=fp->files=0;
goto cleanup; goto cleanup;
} }
if((opts & (UIFC_FP_FILEEXIST|UIFC_FP_PATHEXIST)) && !fexist(cfile)) { if((opts & (UIFC_FP_FILEEXIST|UIFC_FP_PATHEXIST)) && !fexist(cfile)) {
#ifdef _WIN32
if (cfile[0]) // Allow zero-length path to mean "Drive list"
#endif
{
FREE_AND_NULL(tmplastpath); FREE_AND_NULL(tmplastpath);
api->msg("No such path/file!"); api->msg("No such path/file!");
continue; continue;
} }
if(isdir(cfile)) }
if(isdir(cfile) && cfile[0])
backslash(cfile); backslash(cfile);
_splitpath(cfile, drive, tdir, fname, ext); _splitpath(cfile, drive, tdir, fname, ext);
sprintf(cpath,"%s%s",drive,tdir); sprintf(cpath,"%s%s",drive,tdir);
if(!isdir(cpath)) { if(!isdir(cpath)) {
#ifdef _WIN32
if (cfile[0] && strcmp(cfile, cmsk)) // Allow zero-length path to mean "Drive list"
#endif
{
FREE_AND_NULL(tmplastpath); FREE_AND_NULL(tmplastpath);
api->msg("No such path!"); api->msg("No such path!");
continue; continue;
} }
}
if(i==CIO_KEY_MOUSE) if(i==CIO_KEY_MOUSE)
currfield=mousetofield(currfield, opts, height, width, api->list_height, listwidth, &dircur, &dirbar, &filecur, &filebar); currfield=mousetofield(currfield, opts, height, width, api->list_height, listwidth, &dircur, &dirbar, &filecur, &filebar);
if(i==3840) if(i==3840)
...@@ -522,7 +577,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char ...@@ -522,7 +577,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
sprintf(cfile,"%s%s%s%s",drive,tdir,fname,ext); sprintf(cfile,"%s%s%s%s",drive,tdir,fname,ext);
if(strchr(fname,'*') !=NULL || strchr(fname,'?') !=NULL if(strchr(fname,'*') !=NULL || strchr(fname,'?') !=NULL
|| strchr(ext,'*') !=NULL || strchr(ext,'?') !=NULL || strchr(ext,'*') !=NULL || strchr(ext,'?') !=NULL
|| (isdir(cfile) && !(opts & UIFC_FP_DIRSEL) && (i=='\r' || i=='\n')) || ((isdir(cfile) || cfile[0]==0) && !(opts & UIFC_FP_DIRSEL) && (i=='\r' || i=='\n'))
|| (!isdir(cfile) && i!='\r' && i!='\n')) { || (!isdir(cfile) && i!='\r' && i!='\n')) {
if(opts & UIFC_FP_MSKNOCHG) { if(opts & UIFC_FP_MSKNOCHG) {
sprintf(cfile,"%s%s%s",drive,tdir,cmsk); sprintf(cfile,"%s%s%s",drive,tdir,cmsk);
...@@ -531,7 +586,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char ...@@ -531,7 +586,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
continue; continue;
} }
else { else {
if(!isdir(cfile)) if((!isdir(cfile)) && cpath[0] != 0)
sprintf(cmsk, "%s%s", fname, ext); sprintf(cmsk, "%s%s", fname, ext);
reread=TRUE; reread=TRUE;
} }
...@@ -576,7 +631,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char ...@@ -576,7 +631,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
} }
} }
FREE_AND_NULL(tmplastpath); FREE_AND_NULL(tmplastpath);
if((opts & UIFC_FP_MULTI)!=UIFC_FP_MULTI && i!='\t' && i!=3840) { if((opts & UIFC_FP_MULTI)!=UIFC_FP_MULTI && i!='\t' && i!=3840 && cpath[0]) {
retval=fp->files=1; retval=fp->files=1;
fp->selected=(char **)malloc(sizeof(char *)); fp->selected=(char **)malloc(sizeof(char *));
if(fp->selected==NULL) { if(fp->selected==NULL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment