2000-03-05 19:58:08 +00:00
|
|
|
/* ---------- direct.c --------- */
|
|
|
|
|
|
|
|
#include <direct.h>
|
|
|
|
#include <io.h>
|
|
|
|
|
|
|
|
#include "dflat.h"
|
|
|
|
|
|
|
|
#define DRIVE 1
|
|
|
|
#define DIRECTORY 2
|
|
|
|
#define FILENAME 4
|
|
|
|
#define EXTENSION 8
|
|
|
|
|
|
|
|
static char path[MAX_PATH];
|
|
|
|
static char drive[_MAX_DRIVE] = " :";
|
|
|
|
static char dir[_MAX_DIR];
|
|
|
|
static char name[_MAX_FNAME];
|
|
|
|
static char ext[_MAX_EXT];
|
|
|
|
|
|
|
|
/* ----- Create unambiguous path from file spec, filling in the
|
|
|
|
drive and directory if incomplete. Optionally change to
|
|
|
|
the new drive and subdirectory ------ */
|
2003-06-19 02:48:13 +00:00
|
|
|
void DfCreatePath(char *path,char *fspec,int InclName,int Change)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
int cm = 0;
|
|
|
|
char currdir[MAX_PATH];
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
/* save the current directory */
|
|
|
|
if (!Change)
|
|
|
|
GetCurrentDirectory (MAX_PATH, currdir);
|
|
|
|
|
|
|
|
*drive = *dir = *name = *ext = '\0';
|
|
|
|
_splitpath(fspec, drive, dir, name, ext);
|
|
|
|
if (!InclName)
|
|
|
|
*name = *ext = '\0';
|
|
|
|
*drive = toupper(*drive);
|
|
|
|
if (*ext)
|
|
|
|
cm |= EXTENSION;
|
|
|
|
if (InclName && *name)
|
|
|
|
cm |= FILENAME;
|
|
|
|
if (*dir)
|
|
|
|
cm |= DIRECTORY;
|
|
|
|
if (*drive)
|
|
|
|
cm |= DRIVE;
|
|
|
|
if (cm & DRIVE)
|
|
|
|
_chdrive(*drive - '@');
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*drive = _getdrive();
|
|
|
|
*drive += '@';
|
|
|
|
}
|
|
|
|
if (cm & DIRECTORY)
|
|
|
|
{
|
|
|
|
cp = dir+strlen(dir)-1;
|
|
|
|
if (*cp == '\\')
|
|
|
|
*cp = '\0';
|
|
|
|
chdir(dir);
|
|
|
|
}
|
|
|
|
getcwd(dir, sizeof dir);
|
|
|
|
memmove(dir, dir+2, strlen(dir+1));
|
|
|
|
if (InclName) {
|
|
|
|
if (!(cm & FILENAME))
|
|
|
|
strcpy(name, "*");
|
|
|
|
if (!(cm & EXTENSION) && strchr(fspec, '.') != NULL)
|
|
|
|
strcpy(ext, ".*");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*name = *ext = '\0';
|
|
|
|
if (dir[strlen(dir)-1] != '\\')
|
|
|
|
strcat(dir, "\\");
|
|
|
|
memset(path, 0, sizeof path);
|
|
|
|
_makepath(path, drive, dir, name, ext);
|
|
|
|
|
|
|
|
if (!Change)
|
|
|
|
SetCurrentDirectory (currdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dircmp(const void *c1, const void *c2)
|
|
|
|
{
|
|
|
|
return stricmp(*(char **)c1, *(char **)c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL DfDlgDirList(DFWINDOW wnd, char *fspec,
|
2003-06-19 02:48:13 +00:00
|
|
|
enum DfCommands nameid, enum DfCommands pathid,
|
2000-03-05 19:58:08 +00:00
|
|
|
unsigned attrib)
|
|
|
|
{
|
|
|
|
int ax, i = 0;
|
|
|
|
struct _finddata_t ff;
|
2003-06-19 02:48:13 +00:00
|
|
|
DF_CTLWINDOW *ct = DfFindCommand(wnd->extension,nameid,DF_LISTBOX);
|
2000-03-05 19:58:08 +00:00
|
|
|
DFWINDOW lwnd;
|
|
|
|
char **dirlist = NULL;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
DfCreatePath(path, fspec, TRUE, TRUE);
|
2000-03-05 19:58:08 +00:00
|
|
|
if (ct != NULL)
|
|
|
|
{
|
|
|
|
lwnd = ct->wnd;
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(ct->wnd, DFM_CLEARTEXT, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
|
|
|
|
if (attrib & 0x8000)
|
|
|
|
{
|
|
|
|
DWORD cd, dr;
|
|
|
|
|
|
|
|
cd = GetLogicalDrives ();
|
|
|
|
for (dr = 0; dr < 26; dr++)
|
|
|
|
{
|
|
|
|
if (cd & (1 << dr))
|
|
|
|
{
|
|
|
|
char drname[15];
|
|
|
|
|
|
|
|
sprintf(drname, "[%c:\\]", (char)(dr+'A'));
|
|
|
|
#if 0
|
|
|
|
/* ---- test for network or RAM disk ---- */
|
|
|
|
regs.x.ax = 0x4409; /* IOCTL func 9 */
|
|
|
|
regs.h.bl = dr+1;
|
|
|
|
int86(DOS, ®s, ®s);
|
|
|
|
if (!regs.x.cflag) {
|
|
|
|
if (regs.x.dx & 0x1000)
|
|
|
|
strcat(drname, " (Network)");
|
|
|
|
else if (regs.x.dx == 0x0800)
|
|
|
|
strcat(drname, " (RAMdisk)");
|
|
|
|
}
|
|
|
|
#endif
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(lwnd,DFM_ADDTEXT,(DF_PARAM)drname,0);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(lwnd, DFM_PAINT, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
ax = _findfirst(path, &ff);
|
|
|
|
if (ax == -1)
|
|
|
|
return FALSE;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!((attrib & 0x4000) &&
|
|
|
|
(ff.attrib & (attrib & 0x3f)) == 0) &&
|
|
|
|
strcmp(ff.name, "."))
|
|
|
|
{
|
|
|
|
char fname[MAX_PATH+2];
|
|
|
|
sprintf(fname, (ff.attrib & FILE_ATTRIBUTE_DIRECTORY) ?
|
|
|
|
"[%s]" : "%s" , ff.name);
|
2003-06-19 02:48:13 +00:00
|
|
|
dirlist = DfRealloc(dirlist,
|
2000-03-05 19:58:08 +00:00
|
|
|
sizeof(char *)*(i+1));
|
2003-06-19 02:48:13 +00:00
|
|
|
dirlist[i] = DfMalloc(strlen(fname)+1);
|
2000-03-05 19:58:08 +00:00
|
|
|
if (dirlist[i] != NULL)
|
|
|
|
strcpy(dirlist[i], fname);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (_findnext(ax, &ff) == 0);
|
|
|
|
_findclose(ax);
|
|
|
|
if (dirlist != NULL)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
/* -- sort file/drive/directory list box data -- */
|
|
|
|
qsort(dirlist, i, sizeof(void *), dircmp);
|
|
|
|
|
|
|
|
/* ---- send sorted list to list box ---- */
|
|
|
|
for (j = 0; j < i; j++) {
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(lwnd,DFM_ADDTEXT,(DF_PARAM)dirlist[j],0);
|
2000-03-05 19:58:08 +00:00
|
|
|
free(dirlist[j]);
|
|
|
|
}
|
|
|
|
free(dirlist);
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(lwnd, DFM_SHOW_WINDOW, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
if (pathid)
|
|
|
|
{
|
|
|
|
_makepath(path, drive, dir, NULL, NULL);
|
2003-06-19 02:48:13 +00:00
|
|
|
DfPutItemText(wnd, pathid, path);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|