| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: getnames.c 907 2008-01-06 07:26:17Z stevenhl $
|
|---|
| 5 |
|
|---|
| 6 | Directory containers
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2006 Steven H. Levine
|
|---|
| 10 |
|
|---|
| 11 | 23 Aug 06 SHL Comments
|
|---|
| 12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
|---|
| 13 |
|
|---|
| 14 | ***********************************************************************/
|
|---|
| 15 |
|
|---|
| 16 | #include <string.h>
|
|---|
| 17 | #include <ctype.h>
|
|---|
| 18 |
|
|---|
| 19 | #define INCL_DOS
|
|---|
| 20 | #define INCL_WIN
|
|---|
| 21 | #define INCL_LONGLONG
|
|---|
| 22 |
|
|---|
| 23 | #include "fm3dlg.h"
|
|---|
| 24 | #include "fm3str.h"
|
|---|
| 25 | #include "errutil.h" // Dos_Error...
|
|---|
| 26 | #include "strutil.h" // GetPString
|
|---|
| 27 | #include "fm3dll.h"
|
|---|
| 28 |
|
|---|
| 29 | #pragma data_seg(DATA1)
|
|---|
| 30 |
|
|---|
| 31 | MRESULT EXPENTRY CustomFileDlg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 32 | {
|
|---|
| 33 | switch (msg) {
|
|---|
| 34 | case WM_INITDLG:
|
|---|
| 35 | if (!loadedudirs)
|
|---|
| 36 | load_udirs();
|
|---|
| 37 | { /* fill user list box */
|
|---|
| 38 | ULONG ulDriveNum, ulDriveMap;
|
|---|
| 39 | ULONG ulSearchCount;
|
|---|
| 40 | FILEFINDBUF3L findbuf;
|
|---|
| 41 | HDIR hDir;
|
|---|
| 42 | APIRET rc;
|
|---|
| 43 | LINKDIRS *info, *temp;
|
|---|
| 44 |
|
|---|
| 45 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 46 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
|---|
| 47 | info = udirhead;
|
|---|
| 48 | while (info) {
|
|---|
| 49 | if (IsFullName(info->path) &&
|
|---|
| 50 | !(driveflags[toupper(*info->path) - 'A'] &
|
|---|
| 51 | (DRIVE_IGNORE | DRIVE_INVALID))) {
|
|---|
| 52 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 53 | hDir = HDIR_CREATE;
|
|---|
| 54 | ulSearchCount = 1L;
|
|---|
| 55 | if (!IsRoot(info->path))
|
|---|
| 56 | rc = xDosFindFirst(info->path, &hDir, FILE_DIRECTORY |
|
|---|
| 57 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 58 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 59 | &findbuf, sizeof(FILEFINDBUF3L),
|
|---|
| 60 | &ulSearchCount, FIL_STANDARDL);
|
|---|
| 61 | else {
|
|---|
| 62 | rc = 0;
|
|---|
| 63 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 64 | }
|
|---|
| 65 | if (!rc) {
|
|---|
| 66 | if (!IsRoot(info->path))
|
|---|
| 67 | DosFindClose(hDir);
|
|---|
| 68 | if (findbuf.attrFile & FILE_DIRECTORY)
|
|---|
| 69 | WinSendDlgItemMsg(hwnd, FDLG_USERDIRS, LM_INSERTITEM,
|
|---|
| 70 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 71 | MPFROMP(info->path));
|
|---|
| 72 | else {
|
|---|
| 73 | temp = info->next;
|
|---|
| 74 | remove_udir(info->path);
|
|---|
| 75 | info = temp;
|
|---|
| 76 | continue;
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 | else if (!(ulDriveMap & (1L << (toupper(*info->path) - 'A')))) {
|
|---|
| 80 | temp = info->next;
|
|---|
| 81 | remove_udir(info->path);
|
|---|
| 82 | info = temp;
|
|---|
| 83 | continue;
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | info = info->next;
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 | break;
|
|---|
| 90 |
|
|---|
| 91 | case WM_ADJUSTWINDOWPOS:
|
|---|
| 92 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
|
|---|
| 93 | break;
|
|---|
| 94 |
|
|---|
| 95 | case UM_SETDIR:
|
|---|
| 96 | PaintRecessedWindow(WinWindowFromID(hwnd, FDLG_HELP),
|
|---|
| 97 | (HPS) 0, FALSE, TRUE);
|
|---|
| 98 | return 0;
|
|---|
| 99 |
|
|---|
| 100 | case WM_CONTROL:
|
|---|
| 101 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 102 | case 260: /* drives dropdown list */
|
|---|
| 103 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 104 | case CBN_SHOWLIST:
|
|---|
| 105 | WinSetDlgItemText(hwnd,
|
|---|
| 106 | FDLG_HELP, GetPString(IDS_CLICKDRIVEHELPTEXT));
|
|---|
| 107 | break;
|
|---|
| 108 | }
|
|---|
| 109 | break;
|
|---|
| 110 |
|
|---|
| 111 | case 258: /* name entry field */
|
|---|
| 112 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 113 | case EN_SETFOCUS:
|
|---|
| 114 | WinSetDlgItemText(hwnd,
|
|---|
| 115 | FDLG_HELP, GetPString(IDS_ENTERFILEORMASKHELPTEXT));
|
|---|
| 116 | break;
|
|---|
| 117 | case EN_KILLFOCUS:
|
|---|
| 118 | WinSetDlgItemText(hwnd, FDLG_HELP, GetPString(IDS_NAMEDEFHELPTEXT));
|
|---|
| 119 | break;
|
|---|
| 120 | }
|
|---|
| 121 | break;
|
|---|
| 122 |
|
|---|
| 123 | case 264: /* dirs listbox */
|
|---|
| 124 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 125 | case LN_SETFOCUS:
|
|---|
| 126 | WinSetDlgItemText(hwnd,
|
|---|
| 127 | FDLG_HELP, GetPString(IDS_DBLCLKDIRSWITCHHELPTEXT));
|
|---|
| 128 | break;
|
|---|
| 129 | case LN_KILLFOCUS:
|
|---|
| 130 | WinSetDlgItemText(hwnd, FDLG_HELP, GetPString(IDS_NAMEDEFHELPTEXT));
|
|---|
| 131 | break;
|
|---|
| 132 | }
|
|---|
| 133 | break;
|
|---|
| 134 |
|
|---|
| 135 | case 266: /* files listbox */
|
|---|
| 136 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 137 | case LN_SETFOCUS:
|
|---|
| 138 | WinSetDlgItemText(hwnd, FDLG_HELP,
|
|---|
| 139 | GetPString(IDS_DBLCLKFILEUSEHELPTEXT));
|
|---|
| 140 | break;
|
|---|
| 141 | case LN_KILLFOCUS:
|
|---|
| 142 | WinSetDlgItemText(hwnd, FDLG_HELP, GetPString(IDS_NAMEDEFHELPTEXT));
|
|---|
| 143 | break;
|
|---|
| 144 | }
|
|---|
| 145 | break;
|
|---|
| 146 |
|
|---|
| 147 | case FDLG_USERDIRS:
|
|---|
| 148 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 149 | case CBN_SHOWLIST:
|
|---|
| 150 | WinSetDlgItemText(hwnd,
|
|---|
| 151 | FDLG_HELP, GetPString(IDS_DBLCLKDIRSWITCHHELPTEXT));
|
|---|
| 152 | break;
|
|---|
| 153 | case CBN_ENTER:
|
|---|
| 154 | {
|
|---|
| 155 | SHORT sSelect;
|
|---|
| 156 | CHAR szBuffer[CCHMAXPATH], szTemp[CCHMAXPATH], *p;
|
|---|
| 157 |
|
|---|
| 158 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 159 | FDLG_USERDIRS,
|
|---|
| 160 | LM_QUERYSELECTION,
|
|---|
| 161 | MPVOID, MPVOID);
|
|---|
| 162 | *szBuffer = 0;
|
|---|
| 163 | if (sSelect >= 0) {
|
|---|
| 164 | WinSendDlgItemMsg(hwnd,
|
|---|
| 165 | FDLG_USERDIRS,
|
|---|
| 166 | LM_QUERYITEMTEXT,
|
|---|
| 167 | MPFROM2SHORT(sSelect,
|
|---|
| 168 | CCHMAXPATH), MPFROMP(szBuffer));
|
|---|
| 169 | if (*szBuffer) {
|
|---|
| 170 | if (szBuffer[strlen(szBuffer) - 1] != '\\')
|
|---|
| 171 | strcat(szBuffer, "\\");
|
|---|
| 172 | *szTemp = 0;
|
|---|
| 173 | WinQueryDlgItemText(hwnd, 258, CCHMAXPATH, szTemp);
|
|---|
| 174 | p = strrchr(szTemp, '\\');
|
|---|
| 175 | if (!p)
|
|---|
| 176 | p = szTemp;
|
|---|
| 177 | else
|
|---|
| 178 | p++;
|
|---|
| 179 | if (*p)
|
|---|
| 180 | strcat(szBuffer, p);
|
|---|
| 181 | if (!strchr(szBuffer, '?') && !strchr(szBuffer, '*'))
|
|---|
| 182 | strcat(szBuffer, "*");
|
|---|
| 183 | WinSetDlgItemText(hwnd, 258, szBuffer);
|
|---|
| 184 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 188 | break;
|
|---|
| 189 | default:
|
|---|
| 190 | break;
|
|---|
| 191 | }
|
|---|
| 192 | break;
|
|---|
| 193 | }
|
|---|
| 194 | break;
|
|---|
| 195 |
|
|---|
| 196 | case WM_HELP:
|
|---|
| 197 | if (hwndHelp) {
|
|---|
| 198 | WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
|
|---|
| 199 | MPFROM2SHORT(HELP_FILEDLG, 0), MPFROMSHORT(HM_RESOURCEID));
|
|---|
| 200 | return 0;
|
|---|
| 201 | }
|
|---|
| 202 | break;
|
|---|
| 203 | }
|
|---|
| 204 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | BOOL insert_filename(HWND hwnd, CHAR * filename, INT loadit, BOOL newok)
|
|---|
| 208 | {
|
|---|
| 209 | FILEDLG fdlg;
|
|---|
| 210 | FILESTATUS3 fsa;
|
|---|
| 211 | CHAR drive[3], *pdrive = drive, *p;
|
|---|
| 212 | APIRET rc;
|
|---|
| 213 | static CHAR lastfilename[CCHMAXPATH] = "";
|
|---|
| 214 |
|
|---|
| 215 | if (!filename)
|
|---|
| 216 | return FALSE;
|
|---|
| 217 | memset(&fdlg, 0, sizeof(FILEDLG));
|
|---|
| 218 | fdlg.cbSize = (ULONG) sizeof(FILEDLG);
|
|---|
| 219 | fdlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;
|
|---|
| 220 | if (!loadit) {
|
|---|
| 221 | fdlg.pszTitle = GetPString(IDS_ENTERFILEINSERTTEXT);
|
|---|
| 222 | fdlg.pszOKButton = GetPString(IDS_INSERTTEXT);
|
|---|
| 223 | }
|
|---|
| 224 | else if (loadit == TRUE) {
|
|---|
| 225 | fdlg.pszTitle = GetPString(IDS_ENTERFILELOADTEXT);
|
|---|
| 226 | fdlg.pszOKButton = GetPString(IDS_LOADTEXT);
|
|---|
| 227 | }
|
|---|
| 228 | else {
|
|---|
| 229 | fdlg.pszTitle = GetPString(IDS_ENTERFILETEXT);
|
|---|
| 230 | fdlg.pszOKButton = GetPString(IDS_OKAYTEXT);
|
|---|
| 231 | }
|
|---|
| 232 | if (IsFullName(filename)) {
|
|---|
| 233 | *drive = *filename;
|
|---|
| 234 | drive[1] = ':';
|
|---|
| 235 | drive[2] = 0;
|
|---|
| 236 | fdlg.pszIDrive = pdrive;
|
|---|
| 237 | }
|
|---|
| 238 | else if (*lastfilename) {
|
|---|
| 239 | *drive = *lastfilename;
|
|---|
| 240 | drive[1] = ':';
|
|---|
| 241 | drive[2] = 0;
|
|---|
| 242 | fdlg.pszIDrive = pdrive;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | if (!*filename) {
|
|---|
| 246 | if (*lastfilename) {
|
|---|
| 247 | strcpy(fdlg.szFullFile, lastfilename);
|
|---|
| 248 | p = strrchr(fdlg.szFullFile, '\\');
|
|---|
| 249 | if (p) {
|
|---|
| 250 | p++;
|
|---|
| 251 | *p = 0;
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 | if (!loadit || loadit == TRUE)
|
|---|
| 255 | strcat(fdlg.szFullFile, "*.TXT");
|
|---|
| 256 | else
|
|---|
| 257 | strcat(fdlg.szFullFile, "*");
|
|---|
| 258 | }
|
|---|
| 259 | else
|
|---|
| 260 | strcpy(fdlg.szFullFile, filename);
|
|---|
| 261 |
|
|---|
| 262 | if (fCustomFileDlg) {
|
|---|
| 263 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM;
|
|---|
| 264 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg;
|
|---|
| 265 | fdlg.hMod = FM3ModHandle;
|
|---|
| 266 | fdlg.usDlgId = FDLG_FRAME;
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) {
|
|---|
| 270 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC)
|
|---|
| 271 | strcpy(filename, fdlg.szFullFile);
|
|---|
| 272 | else
|
|---|
| 273 | return FALSE;
|
|---|
| 274 | }
|
|---|
| 275 | else
|
|---|
| 276 | return FALSE;
|
|---|
| 277 | MakeFullName(filename);
|
|---|
| 278 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) {
|
|---|
| 279 | if (fsa.attrFile & FILE_DIRECTORY) {
|
|---|
| 280 | /* device or directory */
|
|---|
| 281 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
|---|
| 282 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename);
|
|---|
| 283 | return FALSE;
|
|---|
| 284 | }
|
|---|
| 285 | else if (fsa.cbFile == 0) {
|
|---|
| 286 | saymsg(MB_CANCEL,
|
|---|
| 287 | hwnd, filename, GetPString(IDS_ISZEROLENGTHTEXT), filename);
|
|---|
| 288 | return FALSE;
|
|---|
| 289 | }
|
|---|
| 290 | }
|
|---|
| 291 | else if (!newok) {
|
|---|
| 292 | saymsg(MB_CANCEL,
|
|---|
| 293 | hwnd, filename, GetPString(IDS_DOESNTEXISTTEXT), filename);
|
|---|
| 294 | return FALSE;
|
|---|
| 295 | }
|
|---|
| 296 | else {
|
|---|
| 297 | rc = saymsg(MB_YESNOCANCEL,
|
|---|
| 298 | hwnd, filename, GetPString(IDS_CREATENEWTEXT));
|
|---|
| 299 | if (rc != MBID_YES)
|
|---|
| 300 | return FALSE;
|
|---|
| 301 | }
|
|---|
| 302 | p = filename;
|
|---|
| 303 | while (*p) {
|
|---|
| 304 | if (*p == '/')
|
|---|
| 305 | *p = '\\';
|
|---|
| 306 | p++;
|
|---|
| 307 | }
|
|---|
| 308 | if (*filename)
|
|---|
| 309 | strcpy(lastfilename, filename);
|
|---|
| 310 | return TRUE;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | BOOL export_filename(HWND hwnd, CHAR * filename, INT overwrite)
|
|---|
| 314 | {
|
|---|
| 315 | FILEDLG fdlg;
|
|---|
| 316 | FILESTATUS3 fsa;
|
|---|
| 317 | CHAR drive[3], *pdrive = drive, *p;
|
|---|
| 318 | static CHAR lastfilename[CCHMAXPATH] = "";
|
|---|
| 319 |
|
|---|
| 320 | if (!filename)
|
|---|
| 321 | return FALSE;
|
|---|
| 322 | memset(&fdlg, 0, sizeof(FILEDLG));
|
|---|
| 323 | fdlg.cbSize = sizeof(FILEDLG);
|
|---|
| 324 | fdlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;
|
|---|
| 325 | fdlg.pszTitle = GetPString(IDS_EXPORTNAMETITLETEXT);
|
|---|
| 326 | fdlg.pszOKButton = GetPString(IDS_OKAYTEXT);
|
|---|
| 327 | if (IsFullName(filename)) {
|
|---|
| 328 | *drive = *filename;
|
|---|
| 329 | drive[1] = ':';
|
|---|
| 330 | drive[2] = 0;
|
|---|
| 331 | fdlg.pszIDrive = pdrive;
|
|---|
| 332 | }
|
|---|
| 333 | else if (*lastfilename) {
|
|---|
| 334 | *drive = *lastfilename;
|
|---|
| 335 | drive[1] = ':';
|
|---|
| 336 | drive[2] = 0;
|
|---|
| 337 | fdlg.pszIDrive = pdrive;
|
|---|
| 338 | }
|
|---|
| 339 | if (!*filename) {
|
|---|
| 340 | if (*lastfilename) {
|
|---|
| 341 | strcpy(fdlg.szFullFile, lastfilename);
|
|---|
| 342 | p = strrchr(fdlg.szFullFile, '\\');
|
|---|
| 343 | if (p) {
|
|---|
| 344 | p++;
|
|---|
| 345 | *p = 0;
|
|---|
| 346 | }
|
|---|
| 347 | }
|
|---|
| 348 | strcat(fdlg.szFullFile, "*.TXT");
|
|---|
| 349 | }
|
|---|
| 350 | else
|
|---|
| 351 | strcpy(fdlg.szFullFile, filename);
|
|---|
| 352 |
|
|---|
| 353 | if (fCustomFileDlg) {
|
|---|
| 354 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM;
|
|---|
| 355 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg;
|
|---|
| 356 | fdlg.hMod = FM3ModHandle;
|
|---|
| 357 | fdlg.usDlgId = FDLG_FRAME;
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) {
|
|---|
| 361 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC)
|
|---|
| 362 | strcpy(filename, fdlg.szFullFile);
|
|---|
| 363 | else
|
|---|
| 364 | return FALSE;
|
|---|
| 365 | }
|
|---|
| 366 | else
|
|---|
| 367 | return FALSE;
|
|---|
| 368 | MakeFullName(filename);
|
|---|
| 369 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) {
|
|---|
| 370 | if (fsa.attrFile & FILE_DIRECTORY) { /* device or directory */
|
|---|
| 371 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
|---|
| 372 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename);
|
|---|
| 373 | return FALSE;
|
|---|
| 374 | }
|
|---|
| 375 | else if (overwrite && fsa.cbFile != 0) {
|
|---|
| 376 | if (saymsg(MB_YESNO,
|
|---|
| 377 | hwnd,
|
|---|
| 378 | filename,
|
|---|
| 379 | GetPString(IDS_EXISTSERASETEXT), filename) == MBID_YES)
|
|---|
| 380 | unlinkf("%s", filename);
|
|---|
| 381 | }
|
|---|
| 382 | }
|
|---|
| 383 | p = filename;
|
|---|
| 384 | while (*p) {
|
|---|
| 385 | if (*p == '/')
|
|---|
| 386 | *p = '\\';
|
|---|
| 387 | p++;
|
|---|
| 388 | }
|
|---|
| 389 | if (*filename)
|
|---|
| 390 | strcpy(lastfilename, filename);
|
|---|
| 391 | return TRUE;
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | #pragma alloc_text(GETNAMES,insert_filename,export_filename,CustomFileDlg)
|
|---|