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