[451] | 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
|
---|
[793] | 12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[451] | 13 |
|
---|
| 14 | ***********************************************************************/
|
---|
| 15 |
|
---|
[907] | 16 | #include <string.h>
|
---|
| 17 | #include <ctype.h>
|
---|
| 18 |
|
---|
[2] | 19 | #define INCL_DOS
|
---|
| 20 | #define INCL_WIN
|
---|
[841] | 21 | #define INCL_LONGLONG
|
---|
[2] | 22 |
|
---|
| 23 | #include "fm3dlg.h"
|
---|
| 24 | #include "fm3str.h"
|
---|
[907] | 25 | #include "errutil.h" // Dos_Error...
|
---|
| 26 | #include "strutil.h" // GetPString
|
---|
| 27 | #include "fm3dll.h"
|
---|
[2] | 28 |
|
---|
| 29 | #pragma data_seg(DATA1)
|
---|
| 30 |
|
---|
[551] | 31 | MRESULT EXPENTRY CustomFileDlg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[451] | 32 | {
|
---|
[551] | 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;
|
---|
[841] | 40 | FILEFINDBUF3L findbuf;
|
---|
[551] | 41 | HDIR hDir;
|
---|
| 42 | APIRET rc;
|
---|
| 43 | LINKDIRS *info, *temp;
|
---|
[2] | 44 |
|
---|
[551] | 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))
|
---|
[838] | 56 | rc = xDosFindFirst(info->path, &hDir, FILE_DIRECTORY |
|
---|
| 57 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
---|
| 58 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
---|
[841] | 59 | &findbuf, sizeof(FILEFINDBUF3L),
|
---|
| 60 | &ulSearchCount, FIL_STANDARDL);
|
---|
[551] | 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;
|
---|
[2] | 87 | }
|
---|
[551] | 88 | }
|
---|
| 89 | break;
|
---|
[2] | 90 |
|
---|
[551] | 91 | case WM_ADJUSTWINDOWPOS:
|
---|
| 92 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
|
---|
| 93 | break;
|
---|
[2] | 94 |
|
---|
[551] | 95 | case UM_SETDIR:
|
---|
| 96 | PaintRecessedWindow(WinWindowFromID(hwnd, FDLG_HELP),
|
---|
| 97 | (HPS) 0, FALSE, TRUE);
|
---|
| 98 | return 0;
|
---|
[2] | 99 |
|
---|
[551] | 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;
|
---|
[2] | 110 |
|
---|
[551] | 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;
|
---|
[2] | 122 |
|
---|
[551] | 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;
|
---|
[2] | 134 |
|
---|
[551] | 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;
|
---|
[2] | 146 |
|
---|
[551] | 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;
|
---|
[2] | 157 |
|
---|
[551] | 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;
|
---|
[2] | 191 | }
|
---|
| 192 | break;
|
---|
[551] | 193 | }
|
---|
| 194 | break;
|
---|
[2] | 195 |
|
---|
[551] | 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;
|
---|
[2] | 203 | }
|
---|
[551] | 204 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 205 | }
|
---|
| 206 |
|
---|
[551] | 207 | BOOL insert_filename(HWND hwnd, CHAR * filename, INT loadit, BOOL newok)
|
---|
[451] | 208 | {
|
---|
[551] | 209 | FILEDLG fdlg;
|
---|
[847] | 210 | FILESTATUS3 fsa;
|
---|
[551] | 211 | CHAR drive[3], *pdrive = drive, *p;
|
---|
| 212 | APIRET rc;
|
---|
[2] | 213 | static CHAR lastfilename[CCHMAXPATH] = "";
|
---|
| 214 |
|
---|
[551] | 215 | if (!filename)
|
---|
[2] | 216 | return FALSE;
|
---|
[551] | 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);
|
---|
[2] | 223 | }
|
---|
[551] | 224 | else if (loadit == TRUE) {
|
---|
| 225 | fdlg.pszTitle = GetPString(IDS_ENTERFILELOADTEXT);
|
---|
| 226 | fdlg.pszOKButton = GetPString(IDS_LOADTEXT);
|
---|
[2] | 227 | }
|
---|
| 228 | else {
|
---|
[551] | 229 | fdlg.pszTitle = GetPString(IDS_ENTERFILETEXT);
|
---|
| 230 | fdlg.pszOKButton = GetPString(IDS_OKAYTEXT);
|
---|
[2] | 231 | }
|
---|
[551] | 232 | if (IsFullName(filename)) {
|
---|
[2] | 233 | *drive = *filename;
|
---|
| 234 | drive[1] = ':';
|
---|
| 235 | drive[2] = 0;
|
---|
| 236 | fdlg.pszIDrive = pdrive;
|
---|
| 237 | }
|
---|
[551] | 238 | else if (*lastfilename) {
|
---|
[2] | 239 | *drive = *lastfilename;
|
---|
| 240 | drive[1] = ':';
|
---|
| 241 | drive[2] = 0;
|
---|
| 242 | fdlg.pszIDrive = pdrive;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[551] | 245 | if (!*filename) {
|
---|
| 246 | if (*lastfilename) {
|
---|
| 247 | strcpy(fdlg.szFullFile, lastfilename);
|
---|
| 248 | p = strrchr(fdlg.szFullFile, '\\');
|
---|
| 249 | if (p) {
|
---|
| 250 | p++;
|
---|
| 251 | *p = 0;
|
---|
[2] | 252 | }
|
---|
| 253 | }
|
---|
[551] | 254 | if (!loadit || loadit == TRUE)
|
---|
| 255 | strcat(fdlg.szFullFile, "*.TXT");
|
---|
[2] | 256 | else
|
---|
[551] | 257 | strcat(fdlg.szFullFile, "*");
|
---|
[2] | 258 | }
|
---|
| 259 | else
|
---|
[551] | 260 | strcpy(fdlg.szFullFile, filename);
|
---|
[2] | 261 |
|
---|
[551] | 262 | if (fCustomFileDlg) {
|
---|
[2] | 263 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM;
|
---|
[551] | 264 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg;
|
---|
[2] | 265 | fdlg.hMod = FM3ModHandle;
|
---|
| 266 | fdlg.usDlgId = FDLG_FRAME;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[551] | 269 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) {
|
---|
| 270 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC)
|
---|
| 271 | strcpy(filename, fdlg.szFullFile);
|
---|
[2] | 272 | else
|
---|
| 273 | return FALSE;
|
---|
| 274 | }
|
---|
| 275 | else
|
---|
| 276 | return FALSE;
|
---|
| 277 | MakeFullName(filename);
|
---|
[847] | 278 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) {
|
---|
[551] | 279 | if (fsa.attrFile & FILE_DIRECTORY) {
|
---|
[451] | 280 | /* device or directory */
|
---|
[2] | 281 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
[551] | 282 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename);
|
---|
[2] | 283 | return FALSE;
|
---|
| 284 | }
|
---|
[841] | 285 | else if (fsa.cbFile == 0) {
|
---|
[2] | 286 | saymsg(MB_CANCEL,
|
---|
[551] | 287 | hwnd, filename, GetPString(IDS_ISZEROLENGTHTEXT), filename);
|
---|
[2] | 288 | return FALSE;
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
[551] | 291 | else if (!newok) {
|
---|
[2] | 292 | saymsg(MB_CANCEL,
|
---|
[551] | 293 | hwnd, filename, GetPString(IDS_DOESNTEXISTTEXT), filename);
|
---|
[2] | 294 | return FALSE;
|
---|
| 295 | }
|
---|
| 296 | else {
|
---|
| 297 | rc = saymsg(MB_YESNOCANCEL,
|
---|
[551] | 298 | hwnd, filename, GetPString(IDS_CREATENEWTEXT));
|
---|
| 299 | if (rc != MBID_YES)
|
---|
[2] | 300 | return FALSE;
|
---|
| 301 | }
|
---|
| 302 | p = filename;
|
---|
[551] | 303 | while (*p) {
|
---|
| 304 | if (*p == '/')
|
---|
[2] | 305 | *p = '\\';
|
---|
| 306 | p++;
|
---|
| 307 | }
|
---|
[551] | 308 | if (*filename)
|
---|
| 309 | strcpy(lastfilename, filename);
|
---|
[2] | 310 | return TRUE;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[551] | 313 | BOOL export_filename(HWND hwnd, CHAR * filename, INT overwrite)
|
---|
[451] | 314 | {
|
---|
[551] | 315 | FILEDLG fdlg;
|
---|
[847] | 316 | FILESTATUS3 fsa;
|
---|
[551] | 317 | CHAR drive[3], *pdrive = drive, *p;
|
---|
[2] | 318 | static CHAR lastfilename[CCHMAXPATH] = "";
|
---|
| 319 |
|
---|
[551] | 320 | if (!filename)
|
---|
[2] | 321 | return FALSE;
|
---|
[551] | 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)) {
|
---|
[2] | 328 | *drive = *filename;
|
---|
| 329 | drive[1] = ':';
|
---|
| 330 | drive[2] = 0;
|
---|
| 331 | fdlg.pszIDrive = pdrive;
|
---|
| 332 | }
|
---|
[551] | 333 | else if (*lastfilename) {
|
---|
[2] | 334 | *drive = *lastfilename;
|
---|
| 335 | drive[1] = ':';
|
---|
| 336 | drive[2] = 0;
|
---|
| 337 | fdlg.pszIDrive = pdrive;
|
---|
| 338 | }
|
---|
[551] | 339 | if (!*filename) {
|
---|
| 340 | if (*lastfilename) {
|
---|
| 341 | strcpy(fdlg.szFullFile, lastfilename);
|
---|
| 342 | p = strrchr(fdlg.szFullFile, '\\');
|
---|
| 343 | if (p) {
|
---|
| 344 | p++;
|
---|
| 345 | *p = 0;
|
---|
[2] | 346 | }
|
---|
| 347 | }
|
---|
[551] | 348 | strcat(fdlg.szFullFile, "*.TXT");
|
---|
[2] | 349 | }
|
---|
| 350 | else
|
---|
[551] | 351 | strcpy(fdlg.szFullFile, filename);
|
---|
[2] | 352 |
|
---|
[551] | 353 | if (fCustomFileDlg) {
|
---|
[2] | 354 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM;
|
---|
[551] | 355 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg;
|
---|
[2] | 356 | fdlg.hMod = FM3ModHandle;
|
---|
| 357 | fdlg.usDlgId = FDLG_FRAME;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[551] | 360 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) {
|
---|
| 361 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC)
|
---|
| 362 | strcpy(filename, fdlg.szFullFile);
|
---|
[2] | 363 | else
|
---|
| 364 | return FALSE;
|
---|
| 365 | }
|
---|
| 366 | else
|
---|
| 367 | return FALSE;
|
---|
| 368 | MakeFullName(filename);
|
---|
[847] | 369 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) {
|
---|
[551] | 370 | if (fsa.attrFile & FILE_DIRECTORY) { /* device or directory */
|
---|
[2] | 371 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
[551] | 372 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename);
|
---|
[2] | 373 | return FALSE;
|
---|
| 374 | }
|
---|
[847] | 375 | else if (overwrite && fsa.cbFile != 0) {
|
---|
[551] | 376 | if (saymsg(MB_YESNO,
|
---|
| 377 | hwnd,
|
---|
| 378 | filename,
|
---|
| 379 | GetPString(IDS_EXISTSERASETEXT), filename) == MBID_YES)
|
---|
| 380 | unlinkf("%s", filename);
|
---|
[2] | 381 | }
|
---|
| 382 | }
|
---|
| 383 | p = filename;
|
---|
[551] | 384 | while (*p) {
|
---|
| 385 | if (*p == '/')
|
---|
[2] | 386 | *p = '\\';
|
---|
| 387 | p++;
|
---|
| 388 | }
|
---|
[551] | 389 | if (*filename)
|
---|
| 390 | strcpy(lastfilename, filename);
|
---|
[2] | 391 | return TRUE;
|
---|
| 392 | }
|
---|
[793] | 393 |
|
---|
| 394 | #pragma alloc_text(GETNAMES,insert_filename,export_filename,CustomFileDlg)
|
---|