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