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