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