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