| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: walkem.c 794 2007-08-21 02:54:46Z gyoung $
|
|---|
| 5 |
|
|---|
| 6 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 7 | Copyright (c) 2005, 2007 Steven H. Levine
|
|---|
| 8 |
|
|---|
| 9 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
|---|
| 10 | 05 Jun 05 SHL Use QWL_USER
|
|---|
| 11 | 13 Aug 05 SHL Run through indent
|
|---|
| 12 | 13 Aug 05 SHL remove_udir - avoid corrupting last dirs list
|
|---|
| 13 | 17 Jul 06 SHL Use Runtime_Error
|
|---|
| 14 | 29 Jul 06 SHL Use xfgets
|
|---|
| 15 | 20 Oct 06 SHL Correct . .. check
|
|---|
| 16 | 06 Nov 06 SHL Oops - need to allow .. here
|
|---|
| 17 | 14 Nov 06 SHL Correct FillPathListBox regression
|
|---|
| 18 | 22 Mar 07 GKY Use QWL_USER
|
|---|
| 19 | 20 Apr 07 SHL Avoid spurious add_udir error reports
|
|---|
| 20 | 16 Aug 07 SHL Update add_setups for ticket# 109
|
|---|
| 21 | 19 Aug 07 SHL Correct load_setups error reporting
|
|---|
| 22 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
|---|
| 23 |
|
|---|
| 24 | ***********************************************************************/
|
|---|
| 25 |
|
|---|
| 26 | #define INCL_WIN
|
|---|
| 27 | #define INCL_DOS
|
|---|
| 28 | #define INCL_DOSERRORS
|
|---|
| 29 | #define INCL_SHLERRORS // PMERR_NOT_IN_IDX
|
|---|
| 30 | #include <os2.h>
|
|---|
| 31 |
|
|---|
| 32 | #include <stdlib.h>
|
|---|
| 33 | #include <stdio.h>
|
|---|
| 34 | #include <string.h>
|
|---|
| 35 | #include <ctype.h>
|
|---|
| 36 | #include <time.h>
|
|---|
| 37 | #include <share.h>
|
|---|
| 38 |
|
|---|
| 39 | #include "fm3dll.h"
|
|---|
| 40 | #include "fm3dlg.h"
|
|---|
| 41 | #include "fm3str.h"
|
|---|
| 42 |
|
|---|
| 43 | #pragma data_seg(DATA1)
|
|---|
| 44 |
|
|---|
| 45 | static PSZ pszSrcFile = __FILE__;
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | typedef struct
|
|---|
| 49 | {
|
|---|
| 50 | USHORT size;
|
|---|
| 51 | USHORT changed;
|
|---|
| 52 | BOOL nounwriteable;
|
|---|
| 53 | CHAR szCurrentPath[CCHMAXPATH];
|
|---|
| 54 | CHAR *szReturnPath;
|
|---|
| 55 | }
|
|---|
| 56 | WALKER;
|
|---|
| 57 |
|
|---|
| 58 | static CHAR WalkFont[CCHMAXPATH] = "";
|
|---|
| 59 | static ULONG WalkFontSize = sizeof(WalkFont);
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | * States names management
|
|---|
| 63 | */
|
|---|
| 64 |
|
|---|
| 65 | static BOOL fSetupsLoaded;
|
|---|
| 66 | static LINKDIRS *pFirstSetup;
|
|---|
| 67 | static const PSZ pszLastSetups = "LastSetups";
|
|---|
| 68 | // // 18 Aug 07 SHL fixme to stop supporting old style 1 year from now?
|
|---|
| 69 | static const ULONG ulOldSetupsBytes = 100 * 13; // Prior to 3.0.7
|
|---|
| 70 |
|
|---|
| 71 | /**
|
|---|
| 72 | * Fill States drop down list with known state names
|
|---|
| 73 | */
|
|---|
| 74 |
|
|---|
| 75 | VOID fill_setups_list(VOID)
|
|---|
| 76 | {
|
|---|
| 77 | WinSendMsg(hwndStatelist, LM_DELETEALL, MPVOID, MPVOID);
|
|---|
| 78 | if (fUserComboBox) {
|
|---|
| 79 | LINKDIRS *pld;
|
|---|
| 80 | load_setups();
|
|---|
| 81 | for (pld = pFirstSetup; pld; pld = pld->next) {
|
|---|
| 82 | // DbgMsg(pszSrcFile, __LINE__, "Inserted %s", pld->path);
|
|---|
| 83 | WinSendMsg(hwndStatelist,
|
|---|
| 84 | LM_INSERTITEM,
|
|---|
| 85 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 86 | MPFROMP(pld->path));
|
|---|
| 87 | }
|
|---|
| 88 | WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | /**
|
|---|
| 93 | * Lookup setup and do requested action
|
|---|
| 94 | * @param - action, Support old/new style storage method
|
|---|
| 95 | * @return 1 if found and action OK, 0 if not found and action OK, -1 if error during action
|
|---|
| 96 | */
|
|---|
| 97 |
|
|---|
| 98 | #define LS_FIND 0
|
|---|
| 99 | #define LS_ADD 1
|
|---|
| 100 | #define LS_DELETE 2
|
|---|
| 101 |
|
|---|
| 102 | static INT lookup_setup(PSZ name, UINT action)
|
|---|
| 103 | {
|
|---|
| 104 | LINKDIRS *pld;
|
|---|
| 105 | LINKDIRS *pldLast = NULL;
|
|---|
| 106 |
|
|---|
| 107 | if (!name || !*name) {
|
|---|
| 108 | Runtime_Error(pszSrcFile, __LINE__, "no data");
|
|---|
| 109 | return -1;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | load_setups();
|
|---|
| 113 |
|
|---|
| 114 | for (pld = pFirstSetup; pld; pld = pld->next) {
|
|---|
| 115 | if (!stricmp(pld->path, name)) {
|
|---|
| 116 | if (action == LS_DELETE) {
|
|---|
| 117 | if (pldLast)
|
|---|
| 118 | pldLast->next = pld->next;
|
|---|
| 119 | else
|
|---|
| 120 | pFirstSetup = pld->next;
|
|---|
| 121 | xfree(pld->path);
|
|---|
| 122 | xfree(pld);
|
|---|
| 123 | }
|
|---|
| 124 | return 1; // Found or added
|
|---|
| 125 | }
|
|---|
| 126 | pldLast = pld; // In case deleting
|
|---|
| 127 | } // for
|
|---|
| 128 |
|
|---|
| 129 | // Not found
|
|---|
| 130 | if (action == LS_ADD) {
|
|---|
| 131 | pld = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
|
|---|
| 132 | if (!pld)
|
|---|
| 133 | return -1;
|
|---|
| 134 | pld->path = xstrdup(name, pszSrcFile, __LINE__);
|
|---|
| 135 | if (!pld->path) {
|
|---|
| 136 | xfree(pld);
|
|---|
| 137 | return -1;
|
|---|
| 138 | }
|
|---|
| 139 | // Insert at front of list - drop down will sort
|
|---|
| 140 | pld->next = pFirstSetup;
|
|---|
| 141 | pFirstSetup = pld;
|
|---|
| 142 | return 0;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | return FALSE; // Not found
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | /**
|
|---|
| 149 | * Load state names from ini
|
|---|
| 150 | * Support old/new style storage method
|
|---|
| 151 | */
|
|---|
| 152 |
|
|---|
| 153 | VOID load_setups(VOID)
|
|---|
| 154 | {
|
|---|
| 155 | ULONG ulDataBytes;
|
|---|
| 156 | ULONG l;
|
|---|
| 157 | PSZ pszBuf;
|
|---|
| 158 | PSZ psz;
|
|---|
| 159 | LINKDIRS *pld;
|
|---|
| 160 |
|
|---|
| 161 | if (fSetupsLoaded)
|
|---|
| 162 | return;
|
|---|
| 163 |
|
|---|
| 164 | if (!PrfQueryProfileSize(fmprof, FM3Str, pszLastSetups, &ulDataBytes)) {
|
|---|
| 165 | // fixme to use generic hab
|
|---|
| 166 | ERRORID eid = WinGetLastError((HAB)0);
|
|---|
| 167 | if ((eid & 0xffff) != PMERR_NOT_IN_IDX) {
|
|---|
| 168 | // Get error info back
|
|---|
| 169 | PrfQueryProfileSize(fmprof, FM3Str, pszLastSetups, &ulDataBytes);
|
|---|
| 170 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, "PrfQueryProfileSize");
|
|---|
| 171 | }
|
|---|
| 172 | else
|
|---|
| 173 | fSetupsLoaded = TRUE; // Nothing saved
|
|---|
| 174 | return;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | if (ulDataBytes == 0) {
|
|---|
| 178 | Runtime_Error(pszSrcFile, __LINE__, "PrfQueryProfileSize reported 0 bytes");
|
|---|
| 179 | return;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | pszBuf = xmalloc(ulDataBytes + 1, pszSrcFile, __LINE__); // One extra for end marker
|
|---|
| 183 | if (!pszBuf)
|
|---|
| 184 | return;
|
|---|
| 185 | l = ulDataBytes;
|
|---|
| 186 | if (!PrfQueryProfileData(fmprof, FM3Str, pszLastSetups, pszBuf, &l)) {
|
|---|
| 187 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, "PrfQueryProfileData");
|
|---|
| 188 | xfree(pszBuf);
|
|---|
| 189 | return;
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | if (ulDataBytes != l) {
|
|---|
| 193 | Runtime_Error(pszSrcFile, __LINE__, "PrfQueryProfileData reported %u expected %u", l, ulDataBytes);
|
|---|
| 194 | xfree(pszBuf);
|
|---|
| 195 | return;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | *(pszBuf + ulDataBytes) = 0; // Insert end marker
|
|---|
| 199 |
|
|---|
| 200 | psz = pszBuf;
|
|---|
| 201 | if (!*psz && ulDataBytes == ulOldSetupsBytes)
|
|---|
| 202 | psz += 13; // Rarely used 1st fixed width entry prior to 3.0.7
|
|---|
| 203 |
|
|---|
| 204 | while (*psz) {
|
|---|
| 205 | pld = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
|
|---|
| 206 | if (!pld) {
|
|---|
| 207 | xfree(pszBuf);
|
|---|
| 208 | return;
|
|---|
| 209 | }
|
|---|
| 210 | pld->path = xstrdup(psz, pszSrcFile, __LINE__);
|
|---|
| 211 | if (!pld->path) {
|
|---|
| 212 | xfree(pszBuf);
|
|---|
| 213 | xfree(pld);
|
|---|
| 214 | return;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | // Insert at front of list - drop down will sort
|
|---|
| 218 | pld->next = pFirstSetup;
|
|---|
| 219 | pFirstSetup = pld;
|
|---|
| 220 | // DbgMsg(pszSrcFile, __LINE__, "Inserted %s", pld->path);
|
|---|
| 221 |
|
|---|
| 222 | if (ulDataBytes == ulOldSetupsBytes)
|
|---|
| 223 | psz += 13; // Buffers fixed width prior to 3.0.7
|
|---|
| 224 | else
|
|---|
| 225 | psz += strlen(psz) + 1;
|
|---|
| 226 | } // while
|
|---|
| 227 |
|
|---|
| 228 | xfree(pszBuf);
|
|---|
| 229 |
|
|---|
| 230 | fSetupsLoaded = TRUE;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | VOID save_setups(VOID)
|
|---|
| 234 | {
|
|---|
| 235 | ULONG ulBufBytes;
|
|---|
| 236 | ULONG ulFillBytes;
|
|---|
| 237 | ULONG l;
|
|---|
| 238 | PSZ pszBuf;
|
|---|
| 239 | PSZ psz;
|
|---|
| 240 | LINKDIRS *pld;
|
|---|
| 241 |
|
|---|
| 242 | if (!fSetupsLoaded)
|
|---|
| 243 | return;
|
|---|
| 244 |
|
|---|
| 245 | ulBufBytes = 0;
|
|---|
| 246 | for (pld = pFirstSetup; pld; pld = pld->next) {
|
|---|
| 247 | ulBufBytes += strlen(pld->path) + 1;
|
|---|
| 248 | } // for
|
|---|
| 249 |
|
|---|
| 250 | if (!ulBufBytes)
|
|---|
| 251 | pszBuf = NULL;
|
|---|
| 252 | else {
|
|---|
| 253 | // Ensure different than size prior to 3.0.7
|
|---|
| 254 | ulFillBytes = ulBufBytes == ulOldSetupsBytes ? 1 : 0;
|
|---|
| 255 | pszBuf = xmalloc(ulBufBytes + ulFillBytes, pszSrcFile, __LINE__);
|
|---|
| 256 | if (!pszBuf)
|
|---|
| 257 | return;
|
|---|
| 258 |
|
|---|
| 259 | psz = pszBuf;
|
|---|
| 260 | for (pld = pFirstSetup; pld; pld = pld->next) {
|
|---|
| 261 | l = strlen(pld->path) + 1;
|
|---|
| 262 | memcpy(psz, pld->path, l);
|
|---|
| 263 | psz += l;
|
|---|
| 264 | } // for
|
|---|
| 265 | if (ulFillBytes)
|
|---|
| 266 | *psz = 0;
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | if (!PrfWriteProfileData(fmprof,
|
|---|
| 270 | FM3Str,
|
|---|
| 271 | pszLastSetups, pszBuf, ulBufBytes)) {
|
|---|
| 272 | // Win_Error(pszSrcFile, __LINE__, HWND_DESKTOP, HWND_DESKTOP, "PrfWriteProfileData");
|
|---|
| 273 | ERRORID eid = WinGetLastError((HAB)0);
|
|---|
| 274 | if ((eid & 0xffff) != PMERR_NOT_IN_IDX)
|
|---|
| 275 | Runtime_Error(pszSrcFile, __LINE__, "PrfWriteProfileData returned %u", eid);
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | // Delete obsolete INI entry
|
|---|
| 279 | PrfWriteProfileData(fmprof, FM3Str, "LastSetup", NULL, 0);
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | /**
|
|---|
| 283 | * Add named state to setups list
|
|---|
| 284 | * @return same as lookup_setup
|
|---|
| 285 | */
|
|---|
| 286 |
|
|---|
| 287 | INT add_setup(PSZ name)
|
|---|
| 288 | {
|
|---|
| 289 | return lookup_setup(name, LS_ADD);
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | /**
|
|---|
| 293 | * Delete named state from setups list
|
|---|
| 294 | * @return same as lookup_setup
|
|---|
| 295 | */
|
|---|
| 296 |
|
|---|
| 297 | INT remove_setup(PSZ name)
|
|---|
| 298 | {
|
|---|
| 299 | return lookup_setup(name, LS_DELETE);
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | VOID load_udirs(VOID)
|
|---|
| 303 | {
|
|---|
| 304 | /* load linked list of user directories from USERDIRS.DAT file */
|
|---|
| 305 |
|
|---|
| 306 | FILE *fp;
|
|---|
| 307 | LINKDIRS *info;
|
|---|
| 308 | LINKDIRS *last = NULL;
|
|---|
| 309 | CHAR s[CCHMAXPATH + 24];
|
|---|
| 310 |
|
|---|
| 311 | loadedudirs = TRUE;
|
|---|
| 312 | fUdirsChanged = FALSE;
|
|---|
| 313 | save_dir2(s);
|
|---|
| 314 | if (s[strlen(s) - 1] != '\\')
|
|---|
| 315 | strcat(s, "\\");
|
|---|
| 316 | strcat(s, "USERDIRS.DAT");
|
|---|
| 317 | fp = _fsopen(s, "r", SH_DENYWR);
|
|---|
| 318 | if (fp) {
|
|---|
| 319 | while (!feof(fp)) {
|
|---|
| 320 | if (!xfgets(s, CCHMAXPATH + 24, fp, pszSrcFile, __LINE__))
|
|---|
| 321 | break;
|
|---|
| 322 | s[CCHMAXPATH] = 0;
|
|---|
| 323 | bstripcr(s);
|
|---|
| 324 | if (*s && *s != ';') {
|
|---|
| 325 | info = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
|
|---|
| 326 | if (info) {
|
|---|
| 327 | info->path = xstrdup(s, pszSrcFile, __LINE__);
|
|---|
| 328 | if (!info->path)
|
|---|
| 329 | free(info);
|
|---|
| 330 | else {
|
|---|
| 331 | info->next = NULL;
|
|---|
| 332 | if (!udirhead)
|
|---|
| 333 | udirhead = info;
|
|---|
| 334 | else
|
|---|
| 335 | last->next = info;
|
|---|
| 336 | last = info;
|
|---|
| 337 | }
|
|---|
| 338 | }
|
|---|
| 339 | }
|
|---|
| 340 | }
|
|---|
| 341 | fclose(fp);
|
|---|
| 342 | }
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | VOID save_udirs(VOID)
|
|---|
| 346 | {
|
|---|
| 347 | FILE *fp;
|
|---|
| 348 | LINKDIRS *info;
|
|---|
| 349 | CHAR s[CCHMAXPATH + 14];
|
|---|
| 350 |
|
|---|
| 351 | if (loadedudirs) {
|
|---|
| 352 | fUdirsChanged = FALSE;
|
|---|
| 353 | if (udirhead) {
|
|---|
| 354 | save_dir2(s);
|
|---|
| 355 | if (s[strlen(s) - 1] != '\\')
|
|---|
| 356 | strcat(s, "\\");
|
|---|
| 357 | strcat(s, "USERDIRS.DAT");
|
|---|
| 358 | fp = xfopen(s, "w", pszSrcFile, __LINE__);
|
|---|
| 359 | if (fp) {
|
|---|
| 360 | fputs(GetPString(IDS_USERDEFDIRSTEXT), fp);
|
|---|
| 361 | info = udirhead;
|
|---|
| 362 | while (info) {
|
|---|
| 363 | fprintf(fp, "%0.*s\n", CCHMAXPATH, info->path);
|
|---|
| 364 | info = info->next;
|
|---|
| 365 | }
|
|---|
| 366 | fclose(fp);
|
|---|
| 367 | }
|
|---|
| 368 | }
|
|---|
| 369 | }
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 | /**
|
|---|
| 373 | * Add path to user directory list or last used directory list.
|
|---|
| 374 | * Callers need to check fUdirsChanged to know if user dirs change occured.
|
|---|
| 375 | * Callers need to check return code to know if last dirs change occured.
|
|---|
| 376 | * @param userdirs TRUE to process user directory list. Otherwise last used list.
|
|---|
| 377 | * @return TRUE if added, FALSE if already in list or error.
|
|---|
| 378 | */
|
|---|
| 379 |
|
|---|
| 380 | BOOL add_udir(BOOL userdirs, CHAR *inpath)
|
|---|
| 381 | {
|
|---|
| 382 | CHAR path[CCHMAXPATH];
|
|---|
| 383 | LINKDIRS *info;
|
|---|
| 384 | LINKDIRS *last = NULL;
|
|---|
| 385 | LINKDIRS *temp;
|
|---|
| 386 |
|
|---|
| 387 | if (inpath && *inpath) {
|
|---|
| 388 | if (DosQueryPathInfo(inpath, FIL_QUERYFULLNAME, path, sizeof(path)))
|
|---|
| 389 | strcpy(path, inpath);
|
|---|
| 390 | if (!userdirs && IsRoot(path))
|
|---|
| 391 | return FALSE;
|
|---|
| 392 | if (IsFullName(path)) {
|
|---|
| 393 | if (!loadedudirs)
|
|---|
| 394 | load_udirs();
|
|---|
| 395 | // Search user dir list first unless doing last dirs
|
|---|
| 396 | info = userdirs ? udirhead : ldirhead;
|
|---|
| 397 | while (info) {
|
|---|
| 398 | if (!stricmp(info->path, path))
|
|---|
| 399 | return FALSE; // Already in list
|
|---|
| 400 | last = info; // Remember append to location
|
|---|
| 401 | info = info->next;
|
|---|
| 402 | }
|
|---|
| 403 | // Search last dir list unless doing just last dirs
|
|---|
| 404 | if (!userdirs) {
|
|---|
| 405 | info = udirhead;
|
|---|
| 406 | while (info) {
|
|---|
| 407 | if (!stricmp(info->path, path))
|
|---|
| 408 | return FALSE;
|
|---|
| 409 | info = info->next;
|
|---|
| 410 | }
|
|---|
| 411 | }
|
|---|
| 412 | else {
|
|---|
| 413 | /* if adding manual directory, remove from auto list if present */
|
|---|
| 414 | info = ldirhead;
|
|---|
| 415 | temp = NULL;
|
|---|
| 416 | while (info) {
|
|---|
| 417 | if (!stricmp(info->path, path)) {
|
|---|
| 418 | if (temp)
|
|---|
| 419 | temp->next = info->next;
|
|---|
| 420 | else
|
|---|
| 421 | ldirhead = info->next;
|
|---|
| 422 | free(info->path);
|
|---|
| 423 | free(info);
|
|---|
| 424 | break;
|
|---|
| 425 | }
|
|---|
| 426 | temp = info;
|
|---|
| 427 | info = info->next;
|
|---|
| 428 | }
|
|---|
| 429 | }
|
|---|
| 430 | // Append entry to end of user dirs list
|
|---|
| 431 | info = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__);
|
|---|
| 432 | if (info) {
|
|---|
| 433 | info->path = xstrdup(path, pszSrcFile, __LINE__);
|
|---|
| 434 | if (!info->path)
|
|---|
| 435 | free(info);
|
|---|
| 436 | else {
|
|---|
| 437 | info->next = NULL;
|
|---|
| 438 | if (userdirs) {
|
|---|
| 439 | fUdirsChanged = TRUE;
|
|---|
| 440 | if (!udirhead)
|
|---|
| 441 | udirhead = info;
|
|---|
| 442 | else
|
|---|
| 443 | last->next = info;
|
|---|
| 444 | }
|
|---|
| 445 | else {
|
|---|
| 446 | if (!ldirhead)
|
|---|
| 447 | ldirhead = info;
|
|---|
| 448 | else
|
|---|
| 449 | last->next = info;
|
|---|
| 450 | }
|
|---|
| 451 | return TRUE;
|
|---|
| 452 | }
|
|---|
| 453 | }
|
|---|
| 454 | }
|
|---|
| 455 | }
|
|---|
| 456 | return FALSE;
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | //=== remove_udir - remove path from user dir list or last directory list ===
|
|---|
| 460 |
|
|---|
| 461 | BOOL remove_udir(CHAR * path)
|
|---|
| 462 | {
|
|---|
| 463 | LINKDIRS *info;
|
|---|
| 464 | LINKDIRS *last = NULL;
|
|---|
| 465 |
|
|---|
| 466 | if (path && *path) {
|
|---|
| 467 | if (!loadedudirs)
|
|---|
| 468 | load_udirs();
|
|---|
| 469 | info = udirhead;
|
|---|
| 470 | while (info) {
|
|---|
| 471 | if (!stricmp(info->path, path)) {
|
|---|
| 472 | if (last)
|
|---|
| 473 | last->next = info->next;
|
|---|
| 474 | else
|
|---|
| 475 | udirhead = info->next;
|
|---|
| 476 | free(info->path);
|
|---|
| 477 | free(info);
|
|---|
| 478 | fUdirsChanged = TRUE;
|
|---|
| 479 | return TRUE;
|
|---|
| 480 | }
|
|---|
| 481 | last = info;
|
|---|
| 482 | info = info->next;
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 | info = ldirhead;
|
|---|
| 486 | last = NULL;
|
|---|
| 487 | while (info) {
|
|---|
| 488 | if (!stricmp(info->path, path)) {
|
|---|
| 489 | if (last)
|
|---|
| 490 | last->next = info->next;
|
|---|
| 491 | else
|
|---|
| 492 | ldirhead = info->next;
|
|---|
| 493 | free(info->path);
|
|---|
| 494 | free(info);
|
|---|
| 495 | return TRUE;
|
|---|
| 496 | }
|
|---|
| 497 | last = info;
|
|---|
| 498 | info = info->next;
|
|---|
| 499 | }
|
|---|
| 500 | }
|
|---|
| 501 | return FALSE;
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| 504 | BOOL remove_ldir(CHAR * path)
|
|---|
| 505 | {
|
|---|
| 506 | LINKDIRS *info;
|
|---|
| 507 | LINKDIRS *last = NULL;
|
|---|
| 508 |
|
|---|
| 509 | if (path && *path) {
|
|---|
| 510 | info = ldirhead;
|
|---|
| 511 | while (info) {
|
|---|
| 512 | if (!stricmp(info->path, path)) {
|
|---|
| 513 | if (last)
|
|---|
| 514 | last->next = info->next;
|
|---|
| 515 | else
|
|---|
| 516 | ldirhead = info->next;
|
|---|
| 517 | free(info->path);
|
|---|
| 518 | free(info);
|
|---|
| 519 | return TRUE;
|
|---|
| 520 | }
|
|---|
| 521 | last = info;
|
|---|
| 522 | info = info->next;
|
|---|
| 523 | }
|
|---|
| 524 | }
|
|---|
| 525 | return FALSE;
|
|---|
| 526 | }
|
|---|
| 527 |
|
|---|
| 528 | VOID FillPathListBox(HWND hwnd, HWND hwnddrive, HWND hwnddir, CHAR * pszPath,
|
|---|
| 529 | BOOL nounwriteable)
|
|---|
| 530 | {
|
|---|
| 531 | /*
|
|---|
| 532 | * this function fills one or two list boxes with drive and directory
|
|---|
| 533 | * information showing all available drives and all directories off of
|
|---|
| 534 | * the directory represented by path. This works independently of the
|
|---|
| 535 | * current directory.
|
|---|
| 536 | */
|
|---|
| 537 |
|
|---|
| 538 | CHAR szDrive[] = " :", szTemp[1032];
|
|---|
| 539 | FILEFINDBUF3 findbuf;
|
|---|
| 540 | HDIR hDir = HDIR_CREATE;
|
|---|
| 541 | SHORT sDrive;
|
|---|
| 542 | ULONG ulDriveNum, ulSearchCount = 1, ulDriveMap;
|
|---|
| 543 |
|
|---|
| 544 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 545 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
|---|
| 546 | if (hwnddrive)
|
|---|
| 547 | WinSendMsg(hwnddrive, LM_DELETEALL, MPVOID, MPVOID);
|
|---|
| 548 | if (hwnddrive != hwnddir && hwnddir)
|
|---|
| 549 | WinSendMsg(hwnddir, LM_DELETEALL, MPVOID, MPVOID);
|
|---|
| 550 |
|
|---|
| 551 | if (hwnddrive) {
|
|---|
| 552 | // Fill drive listbox
|
|---|
| 553 | for (sDrive = 0; sDrive < 26; sDrive++) {
|
|---|
| 554 | if (ulDriveMap & (1 << sDrive)) {
|
|---|
| 555 | *szDrive = (CHAR) (sDrive + 'A');
|
|---|
| 556 | if ((!nounwriteable || !(driveflags[sDrive] & DRIVE_NOTWRITEABLE)) &&
|
|---|
| 557 | !(driveflags[sDrive] & (DRIVE_IGNORE | DRIVE_INVALID)))
|
|---|
| 558 | WinSendMsg(hwnddrive, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0),
|
|---|
| 559 | MPFROMP(szDrive));
|
|---|
| 560 | }
|
|---|
| 561 | }
|
|---|
| 562 | if (hwnddrive != hwnddir && pszPath && isalpha(*pszPath)
|
|---|
| 563 | && pszPath[1] == ':') {
|
|---|
| 564 | *szDrive = toupper(*pszPath);
|
|---|
| 565 | WinSetWindowText(hwnddrive, szDrive);
|
|---|
| 566 | }
|
|---|
| 567 | }
|
|---|
| 568 |
|
|---|
| 569 | if (hwnddir) {
|
|---|
| 570 | // Fill directory listbox
|
|---|
| 571 | sprintf(szTemp,
|
|---|
| 572 | "%s%s*",
|
|---|
| 573 | pszPath, (pszPath[strlen(pszPath) - 1] == '\\') ? "" : "\\");
|
|---|
| 574 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 575 | if (!DosFindFirst(szTemp,
|
|---|
| 576 | &hDir,
|
|---|
| 577 | FILE_DIRECTORY | MUST_HAVE_DIRECTORY |
|
|---|
| 578 | FILE_READONLY | FILE_ARCHIVED | FILE_SYSTEM |
|
|---|
| 579 | FILE_HIDDEN,
|
|---|
| 580 | &findbuf,
|
|---|
| 581 | sizeof(FILEFINDBUF3), &ulSearchCount, FIL_STANDARD)) {
|
|---|
| 582 | do {
|
|---|
| 583 | if (findbuf.attrFile & FILE_DIRECTORY) {
|
|---|
| 584 | // Skip .. unless full path supplied
|
|---|
| 585 | if (strcmp(findbuf.achName, "..") ||
|
|---|
| 586 | strlen(pszPath) > 3 || pszPath[1] != ':') {
|
|---|
| 587 | // Skip . allow ..
|
|---|
| 588 | if (findbuf.achName[0] != '.' || findbuf.achName[1]) {
|
|---|
| 589 | WinSendMsg(hwnddir,
|
|---|
| 590 | LM_INSERTITEM,
|
|---|
| 591 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 592 | MPFROMP(findbuf.achName));
|
|---|
| 593 | }
|
|---|
| 594 | }
|
|---|
| 595 | }
|
|---|
| 596 | ulSearchCount = 1;
|
|---|
| 597 | } while (!DosFindNext(hDir,
|
|---|
| 598 | &findbuf, sizeof(FILEFINDBUF3), &ulSearchCount));
|
|---|
| 599 | DosFindClose(hDir);
|
|---|
| 600 | }
|
|---|
| 601 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 602 | }
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | MRESULT EXPENTRY TextSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 606 | {
|
|---|
| 607 | PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
|
|---|
| 608 |
|
|---|
| 609 | switch (msg) {
|
|---|
| 610 | case WM_CHAR:
|
|---|
| 611 | if (SHORT1FROMMP(mp1) & KC_KEYUP) {
|
|---|
| 612 | if ((SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
|
|---|
| 613 | (SHORT1FROMMP(mp2) & 255) == '\r')
|
|---|
| 614 | PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
|
|---|
| 615 | MPFROM2SHORT(DID_OK, 0), MPVOID);
|
|---|
| 616 | }
|
|---|
| 617 | break;
|
|---|
| 618 | }
|
|---|
| 619 | return oldproc(hwnd, msg, mp1, mp2);
|
|---|
| 620 | }
|
|---|
| 621 |
|
|---|
| 622 | MRESULT EXPENTRY WalkDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 623 | {
|
|---|
| 624 | WALKER *wa;
|
|---|
| 625 | CHAR szBuff[CCHMAXPATH + 1], szBuffer[CCHMAXPATH + 1], *p;
|
|---|
| 626 | SHORT sSelect;
|
|---|
| 627 | static BOOL okay; /* avoid combobox selecting as filled */
|
|---|
| 628 | static CHAR lastdir[CCHMAXPATH + 1];
|
|---|
| 629 |
|
|---|
| 630 | switch (msg) {
|
|---|
| 631 | case UM_SETUP2:
|
|---|
| 632 | case WM_INITDLG:
|
|---|
| 633 | okay = FALSE;
|
|---|
| 634 | *lastdir = 0;
|
|---|
| 635 | if (!mp2) {
|
|---|
| 636 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
|
|---|
| 637 | WinDismissDlg(hwnd, 0);
|
|---|
| 638 | break;
|
|---|
| 639 | }
|
|---|
| 640 | wa = xmallocz(sizeof(WALKER), pszSrcFile, __LINE__);
|
|---|
| 641 | if (!wa) {
|
|---|
| 642 | WinDismissDlg(hwnd, 0);
|
|---|
| 643 | break;
|
|---|
| 644 | }
|
|---|
| 645 | wa->size = (USHORT) sizeof(WALKER);
|
|---|
| 646 | WinSetWindowPtr(hwnd, QWL_USER, (PVOID) wa);
|
|---|
| 647 | wa->szReturnPath = (CHAR *) mp2;
|
|---|
| 648 | {
|
|---|
| 649 | PFNWP oldproc;
|
|---|
| 650 |
|
|---|
| 651 | oldproc = WinSubclassWindow(WinWindowFromID(hwnd, WALK_PATH),
|
|---|
| 652 | (PFNWP) TextSubProc);
|
|---|
| 653 | if (oldproc)
|
|---|
| 654 | WinSetWindowPtr(WinWindowFromID(hwnd, WALK_PATH),
|
|---|
| 655 | QWL_USER, (PVOID) oldproc);
|
|---|
| 656 | WinSendDlgItemMsg(WinWindowFromID(hwnd, WALK_RECENT),
|
|---|
| 657 | CBID_EDIT,
|
|---|
| 658 | EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
|---|
| 659 | WinSendDlgItemMsg(WinWindowFromID(hwnd, WALK_RECENT),
|
|---|
| 660 | CBID_EDIT,
|
|---|
| 661 | EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
|
|---|
| 662 | }
|
|---|
| 663 | PosOverOkay(hwnd);
|
|---|
| 664 | if (msg == UM_SETUP2)
|
|---|
| 665 | wa->nounwriteable = FALSE;
|
|---|
| 666 | else
|
|---|
| 667 | wa->nounwriteable = TRUE;
|
|---|
| 668 | if (!*wa->szReturnPath)
|
|---|
| 669 | save_dir2(wa->szCurrentPath);
|
|---|
| 670 | else {
|
|---|
| 671 | strcpy(wa->szCurrentPath, wa->szReturnPath);
|
|---|
| 672 | MakeFullName(wa->szCurrentPath);
|
|---|
| 673 | }
|
|---|
| 674 | if (wa->nounwriteable &&
|
|---|
| 675 | (driveflags[toupper(*wa->szCurrentPath) - 'A'] &
|
|---|
| 676 | DRIVE_NOTWRITEABLE)) {
|
|---|
| 677 |
|
|---|
| 678 | ULONG bd;
|
|---|
| 679 |
|
|---|
| 680 | strcpy(wa->szCurrentPath, "C:\\");
|
|---|
| 681 | if (DosQuerySysInfo(QSV_BOOT_DRIVE,
|
|---|
| 682 | QSV_BOOT_DRIVE,
|
|---|
| 683 | (PVOID) & bd, (ULONG) sizeof(ULONG)))
|
|---|
| 684 | bd = 3;
|
|---|
| 685 | *wa->szCurrentPath = (CHAR) bd + '@';
|
|---|
| 686 | }
|
|---|
| 687 | WinSendDlgItemMsg(hwnd,
|
|---|
| 688 | WALK_PATH,
|
|---|
| 689 | EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
|---|
| 690 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
|
|---|
| 691 | if (!loadedudirs)
|
|---|
| 692 | load_udirs();
|
|---|
| 693 | { /* fill user list box */
|
|---|
| 694 | ULONG ulDriveNum, ulDriveMap;
|
|---|
| 695 | ULONG ulSearchCount;
|
|---|
| 696 | FILEFINDBUF3 findbuf;
|
|---|
| 697 | HDIR hDir;
|
|---|
| 698 | APIRET rc;
|
|---|
| 699 | LINKDIRS *info, *temp;
|
|---|
| 700 |
|
|---|
| 701 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 702 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
|---|
| 703 | info = udirhead;
|
|---|
| 704 | while (info) {
|
|---|
| 705 | if (IsFullName(info->path) &&
|
|---|
| 706 | !(driveflags[toupper(*info->path) - 'A'] &
|
|---|
| 707 | (DRIVE_IGNORE | DRIVE_INVALID))) {
|
|---|
| 708 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 709 | hDir = HDIR_CREATE;
|
|---|
| 710 | ulSearchCount = 1;
|
|---|
| 711 | if (!IsRoot(info->path))
|
|---|
| 712 | rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
|
|---|
| 713 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 714 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 715 | &findbuf, sizeof(FILEFINDBUF3),
|
|---|
| 716 | &ulSearchCount, FIL_STANDARD);
|
|---|
| 717 | else {
|
|---|
| 718 | rc = 0;
|
|---|
| 719 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 720 | }
|
|---|
| 721 | if (!rc) {
|
|---|
| 722 | if (!IsRoot(info->path))
|
|---|
| 723 | DosFindClose(hDir);
|
|---|
| 724 | if (findbuf.attrFile & FILE_DIRECTORY)
|
|---|
| 725 | WinSendDlgItemMsg(hwnd, WALK_USERLIST, LM_INSERTITEM,
|
|---|
| 726 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 727 | MPFROMP(info->path));
|
|---|
| 728 | else {
|
|---|
| 729 | temp = info->next;
|
|---|
| 730 | remove_udir(info->path);
|
|---|
| 731 | info = temp;
|
|---|
| 732 | continue;
|
|---|
| 733 | }
|
|---|
| 734 | }
|
|---|
| 735 | else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
|
|---|
| 736 | temp = info->next;
|
|---|
| 737 | remove_udir(info->path);
|
|---|
| 738 | info = temp;
|
|---|
| 739 | continue;
|
|---|
| 740 | }
|
|---|
| 741 | }
|
|---|
| 742 | info = info->next;
|
|---|
| 743 | }
|
|---|
| 744 | info = ldirhead;
|
|---|
| 745 | while (info) {
|
|---|
| 746 | if (IsFullName(info->path) &&
|
|---|
| 747 | !(driveflags[toupper(*info->path) - 'A'] &
|
|---|
| 748 | (DRIVE_IGNORE | DRIVE_INVALID))) {
|
|---|
| 749 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 750 | hDir = HDIR_CREATE;
|
|---|
| 751 | ulSearchCount = 1;
|
|---|
| 752 | if (!IsRoot(info->path))
|
|---|
| 753 | rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
|
|---|
| 754 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 755 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 756 | &findbuf, sizeof(FILEFINDBUF3),
|
|---|
| 757 | &ulSearchCount, FIL_STANDARD);
|
|---|
| 758 | else {
|
|---|
| 759 | rc = 0;
|
|---|
| 760 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 761 | }
|
|---|
| 762 | if (!rc) {
|
|---|
| 763 | if (!IsRoot(info->path))
|
|---|
| 764 | DosFindClose(hDir);
|
|---|
| 765 | if (findbuf.attrFile & FILE_DIRECTORY)
|
|---|
| 766 | WinSendDlgItemMsg(hwnd, WALK_RECENT, LM_INSERTITEM,
|
|---|
| 767 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 768 | MPFROMP(info->path));
|
|---|
| 769 | else {
|
|---|
| 770 | temp = info->next;
|
|---|
| 771 | remove_ldir(info->path);
|
|---|
| 772 | info = temp;
|
|---|
| 773 | continue;
|
|---|
| 774 | }
|
|---|
| 775 | WinSetDlgItemText(hwnd, WALK_RECENT,
|
|---|
| 776 | GetPString(IDS_WALKRECENTDIRSTEXT));
|
|---|
| 777 | }
|
|---|
| 778 | else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
|
|---|
| 779 | temp = info->next;
|
|---|
| 780 | remove_ldir(info->path);
|
|---|
| 781 | info = temp;
|
|---|
| 782 | continue;
|
|---|
| 783 | }
|
|---|
| 784 | }
|
|---|
| 785 | info = info->next;
|
|---|
| 786 | }
|
|---|
| 787 | }
|
|---|
| 788 | FillPathListBox(hwnd,
|
|---|
| 789 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 790 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 791 | wa->szCurrentPath, wa->nounwriteable);
|
|---|
| 792 | if (!PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID))
|
|---|
| 793 | okay = TRUE;
|
|---|
| 794 | {
|
|---|
| 795 | MRESULT ret;
|
|---|
| 796 |
|
|---|
| 797 | ret = WinDefDlgProc(hwnd, WM_INITDLG, mp1, mp2);
|
|---|
| 798 | WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
|
|---|
| 799 | WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
|
|---|
| 800 | return ret;
|
|---|
| 801 | }
|
|---|
| 802 |
|
|---|
| 803 | case UM_SETUP4:
|
|---|
| 804 | okay = TRUE;
|
|---|
| 805 | return 0;
|
|---|
| 806 |
|
|---|
| 807 | case WM_ADJUSTWINDOWPOS:
|
|---|
| 808 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
|
|---|
| 809 | break;
|
|---|
| 810 |
|
|---|
| 811 | case UM_SETDIR:
|
|---|
| 812 | PaintRecessedWindow(WinWindowFromID(hwnd, WALK_HELP), (HPS) 0, FALSE,
|
|---|
| 813 | TRUE);
|
|---|
| 814 | return 0;
|
|---|
| 815 |
|
|---|
| 816 | case WM_PRESPARAMCHANGED:
|
|---|
| 817 | {
|
|---|
| 818 | ULONG AttrFound, AttrValue[64], cbRetLen;
|
|---|
| 819 |
|
|---|
| 820 | cbRetLen = WinQueryPresParam(hwnd, (ULONG) mp1, 0, &AttrFound,
|
|---|
| 821 | (ULONG) sizeof(AttrValue), &AttrValue, 0);
|
|---|
| 822 | if (cbRetLen) {
|
|---|
| 823 | switch (AttrFound) {
|
|---|
| 824 | case PP_FONTNAMESIZE:
|
|---|
| 825 | PrfWriteProfileData(fmprof,
|
|---|
| 826 | appname,
|
|---|
| 827 | "WalkFont", (PVOID) AttrValue, cbRetLen);
|
|---|
| 828 | *WalkFont = 0;
|
|---|
| 829 | WalkFontSize = sizeof(WalkFont);
|
|---|
| 830 | WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
|
|---|
| 831 | break;
|
|---|
| 832 | }
|
|---|
| 833 | }
|
|---|
| 834 | }
|
|---|
| 835 | break;
|
|---|
| 836 |
|
|---|
| 837 | case UM_SETUP3:
|
|---|
| 838 | save_udirs();
|
|---|
| 839 | if (hwndMain)
|
|---|
| 840 | PostMsg(hwndMain, UM_FILLUSERLIST, MPVOID, MPVOID);
|
|---|
| 841 | return 0;
|
|---|
| 842 |
|
|---|
| 843 | case UM_SETUP:
|
|---|
| 844 | {
|
|---|
| 845 | INT x;
|
|---|
| 846 | USHORT id[] = { WALK_PATH, WALK_DIRLIST, WALK_USERLIST,
|
|---|
| 847 | WALK_RECENT, 0
|
|---|
| 848 | };
|
|---|
| 849 |
|
|---|
| 850 | if (*WalkFont ||
|
|---|
| 851 | (PrfQueryProfileData(fmprof,
|
|---|
| 852 | appname,
|
|---|
| 853 | "WalkFont",
|
|---|
| 854 | (PVOID) WalkFont,
|
|---|
| 855 | &WalkFontSize) && WalkFontSize)) {
|
|---|
| 856 | for (x = 0; id[x]; x++)
|
|---|
| 857 | WinSetPresParam(WinWindowFromID(hwnd, id[x]),
|
|---|
| 858 | PP_FONTNAMESIZE, WalkFontSize, (PVOID) WalkFont);
|
|---|
| 859 | }
|
|---|
| 860 | }
|
|---|
| 861 | return 0;
|
|---|
| 862 |
|
|---|
| 863 | case UM_CONTROL:
|
|---|
| 864 | case WM_CONTROL:
|
|---|
| 865 | wa = WinQueryWindowPtr(hwnd, QWL_USER);
|
|---|
| 866 | if (SHORT1FROMMP(mp1) == WALK_DRIVELIST ||
|
|---|
| 867 | SHORT1FROMMP(mp1) == WALK_DIRLIST ||
|
|---|
| 868 | SHORT1FROMMP(mp1) == WALK_USERLIST ||
|
|---|
| 869 | SHORT1FROMMP(mp1) == WALK_RECENT) {
|
|---|
| 870 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 871 | SHORT1FROMMP(mp1),
|
|---|
| 872 | LM_QUERYSELECTION, MPVOID, MPVOID);
|
|---|
| 873 | *szBuffer = 0;
|
|---|
| 874 | if (sSelect >= 0)
|
|---|
| 875 | WinSendDlgItemMsg(hwnd, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
|
|---|
| 876 | MPFROM2SHORT(sSelect, CCHMAXPATH),
|
|---|
| 877 | MPFROMP(szBuffer));
|
|---|
| 878 | }
|
|---|
| 879 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 880 | case WALK_PATH:
|
|---|
| 881 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
|---|
| 882 | WinSetDlgItemText(hwnd, WALK_HELP, GetPString(IDS_WALKCURRDIRTEXT));
|
|---|
| 883 | else if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
|---|
| 884 | WinSetDlgItemText(hwnd, WALK_HELP,
|
|---|
| 885 | GetPString(IDS_WALKDEFAULTHELPTEXT));
|
|---|
| 886 | break;
|
|---|
| 887 |
|
|---|
| 888 | case WALK_RECENT:
|
|---|
| 889 | if (okay && SHORT2FROMMP(mp1) == CBN_LBSELECT) {
|
|---|
| 890 |
|
|---|
| 891 | ULONG ulSearchCount;
|
|---|
| 892 | FILEFINDBUF3 findbuf;
|
|---|
| 893 | HDIR hDir;
|
|---|
| 894 | APIRET rc;
|
|---|
| 895 |
|
|---|
| 896 | // *szBuffer = 0;
|
|---|
| 897 | // WinQueryDlgItemText(hwnd,WALK_RECENT,CCHMAXPATH,szBuffer);
|
|---|
| 898 | if (!*szBuffer)
|
|---|
| 899 | break;
|
|---|
| 900 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 901 | hDir = HDIR_CREATE;
|
|---|
| 902 | ulSearchCount = 1;
|
|---|
| 903 | if (!IsRoot(szBuffer)) {
|
|---|
| 904 | rc = DosFindFirst(szBuffer, &hDir, FILE_DIRECTORY |
|
|---|
| 905 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 906 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 907 | &findbuf, sizeof(FILEFINDBUF3),
|
|---|
| 908 | &ulSearchCount, FIL_STANDARD);
|
|---|
| 909 | if (!rc)
|
|---|
| 910 | DosFindClose(hDir);
|
|---|
| 911 | }
|
|---|
| 912 | else {
|
|---|
| 913 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 914 | rc = 0;
|
|---|
| 915 | }
|
|---|
| 916 | if (rc)
|
|---|
| 917 | Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
|
|---|
| 918 | "DosFindFirst");
|
|---|
| 919 | else if (~findbuf.attrFile & FILE_DIRECTORY)
|
|---|
| 920 | Runtime_Error(pszSrcFile, __LINE__, "not a directory");
|
|---|
| 921 | else {
|
|---|
| 922 | strcpy(wa->szCurrentPath, szBuffer);
|
|---|
| 923 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
|
|---|
| 924 | WinSetDlgItemText(hwnd, WALK_RECENT, wa->szCurrentPath);
|
|---|
| 925 | FillPathListBox(hwnd,
|
|---|
| 926 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 927 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 928 | wa->szCurrentPath, FALSE);
|
|---|
| 929 | }
|
|---|
| 930 | }
|
|---|
| 931 | else if (SHORT2FROMMP(mp1) == CBN_ENTER)
|
|---|
| 932 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
|---|
| 933 | else if (SHORT2FROMMP(mp1) == CBN_SHOWLIST)
|
|---|
| 934 | WinSetDlgItemText(hwnd, WALK_HELP,
|
|---|
| 935 | GetPString(IDS_WALKRECENTDIRSHELPTEXT));
|
|---|
| 936 | break;
|
|---|
| 937 |
|
|---|
| 938 | case WALK_USERLIST:
|
|---|
| 939 | if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_SELECT) {
|
|---|
| 940 |
|
|---|
| 941 | ULONG ulSearchCount;
|
|---|
| 942 | FILEFINDBUF3 findbuf;
|
|---|
| 943 | HDIR hDir;
|
|---|
| 944 | APIRET rc;
|
|---|
| 945 |
|
|---|
| 946 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 947 | hDir = HDIR_CREATE;
|
|---|
| 948 | ulSearchCount = 1;
|
|---|
| 949 | if (!IsRoot(szBuffer)) {
|
|---|
| 950 | rc = DosFindFirst(szBuffer,
|
|---|
| 951 | &hDir,
|
|---|
| 952 | FILE_DIRECTORY |
|
|---|
| 953 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 954 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 955 | &findbuf,
|
|---|
| 956 | sizeof(FILEFINDBUF3),
|
|---|
| 957 | &ulSearchCount, FIL_STANDARD);
|
|---|
| 958 | if (!rc)
|
|---|
| 959 | DosFindClose(hDir);
|
|---|
| 960 | }
|
|---|
| 961 | else {
|
|---|
| 962 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 963 | rc = 0;
|
|---|
| 964 | }
|
|---|
| 965 | if (rc)
|
|---|
| 966 | Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
|
|---|
| 967 | "DosFindFirst");
|
|---|
| 968 | else if (~findbuf.attrFile & FILE_DIRECTORY)
|
|---|
| 969 | Runtime_Error(pszSrcFile, __LINE__, "not a directory");
|
|---|
| 970 | else {
|
|---|
| 971 | strcpy(wa->szCurrentPath, szBuffer);
|
|---|
| 972 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
|
|---|
| 973 | FillPathListBox(hwnd,
|
|---|
| 974 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 975 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 976 | wa->szCurrentPath, FALSE);
|
|---|
| 977 | }
|
|---|
| 978 | }
|
|---|
| 979 | else if (SHORT2FROMMP(mp1) == LN_ENTER)
|
|---|
| 980 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
|---|
| 981 | else if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
|
|---|
| 982 | WinSetDlgItemText(hwnd,
|
|---|
| 983 | WALK_HELP, GetPString(IDS_WALKUSERDIRSHELPTEXT));
|
|---|
| 984 | else if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
|
|---|
| 985 | WinSetDlgItemText(hwnd,
|
|---|
| 986 | WALK_HELP, GetPString(IDS_WALKDEFAULTHELPTEXT));
|
|---|
| 987 | break;
|
|---|
| 988 |
|
|---|
| 989 | case WALK_DRIVELIST:
|
|---|
| 990 | if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_ENTER) {
|
|---|
| 991 |
|
|---|
| 992 | ULONG ulDirLen = CCHMAXPATH;
|
|---|
| 993 | APIRET rc;
|
|---|
| 994 |
|
|---|
| 995 | rc = DosQCurDir(toupper(*szBuffer) - '@', &szBuff[3], &ulDirLen);
|
|---|
| 996 | if (!rc) {
|
|---|
| 997 | strcpy(wa->szCurrentPath, "C:\\");
|
|---|
| 998 | *wa->szCurrentPath = toupper(*szBuffer);
|
|---|
| 999 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
|
|---|
| 1000 | FillPathListBox(hwnd,
|
|---|
| 1001 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 1002 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 1003 | wa->szCurrentPath, FALSE);
|
|---|
| 1004 | }
|
|---|
| 1005 | }
|
|---|
| 1006 | else if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
|
|---|
| 1007 | WinSetDlgItemText(hwnd, WALK_HELP,
|
|---|
| 1008 | GetPString(IDS_WALKDRIVELISTHELPTEXT));
|
|---|
| 1009 | else if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
|
|---|
| 1010 | WinSetDlgItemText(hwnd, WALK_HELP,
|
|---|
| 1011 | GetPString(IDS_WALKDEFAULTHELPTEXT));
|
|---|
| 1012 | break;
|
|---|
| 1013 |
|
|---|
| 1014 | case WALK_DIRLIST:
|
|---|
| 1015 | if (okay && SHORT2FROMMP(mp1) == LN_ENTER) {
|
|---|
| 1016 |
|
|---|
| 1017 | ULONG ulSearchCount;
|
|---|
| 1018 | FILEFINDBUF3 findbuf;
|
|---|
| 1019 | HDIR hDir;
|
|---|
| 1020 | APIRET rc;
|
|---|
| 1021 |
|
|---|
| 1022 | bstrip(szBuffer);
|
|---|
| 1023 | if (*szBuffer) {
|
|---|
| 1024 | strcpy(szBuff, wa->szCurrentPath);
|
|---|
| 1025 | if (szBuff[strlen(szBuff) - 1] != '\\')
|
|---|
| 1026 | strcat(szBuff, "\\");
|
|---|
| 1027 | strcat(szBuff, szBuffer);
|
|---|
| 1028 | MakeFullName(szBuff);
|
|---|
| 1029 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1030 | hDir = HDIR_CREATE;
|
|---|
| 1031 | ulSearchCount = 1;
|
|---|
| 1032 | if (!IsRoot(szBuff)) {
|
|---|
| 1033 | rc = DosFindFirst(szBuff,
|
|---|
| 1034 | &hDir,
|
|---|
| 1035 | FILE_DIRECTORY |
|
|---|
| 1036 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 1037 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 1038 | &findbuf,
|
|---|
| 1039 | sizeof(FILEFINDBUF3),
|
|---|
| 1040 | &ulSearchCount, FIL_STANDARD);
|
|---|
| 1041 | if (!rc)
|
|---|
| 1042 | DosFindClose(hDir);
|
|---|
| 1043 | }
|
|---|
| 1044 | else {
|
|---|
| 1045 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 1046 | rc = 0;
|
|---|
| 1047 | }
|
|---|
| 1048 | if (!rc && (findbuf.attrFile & FILE_DIRECTORY)) {
|
|---|
| 1049 | strcpy(wa->szCurrentPath, szBuff);
|
|---|
| 1050 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
|
|---|
| 1051 | FillPathListBox(hwnd,
|
|---|
| 1052 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 1053 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 1054 | wa->szCurrentPath, FALSE);
|
|---|
| 1055 | }
|
|---|
| 1056 | }
|
|---|
| 1057 | }
|
|---|
| 1058 | else if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
|
|---|
| 1059 | WinSetDlgItemText(hwnd, WALK_HELP,
|
|---|
| 1060 | GetPString(IDS_WALKDIRLISTHELPTEXT));
|
|---|
| 1061 | else if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
|
|---|
| 1062 | WinSetDlgItemText(hwnd, WALK_HELP,
|
|---|
| 1063 | GetPString(IDS_WALKDEFAULTHELPTEXT));
|
|---|
| 1064 | break;
|
|---|
| 1065 | }
|
|---|
| 1066 | return 0;
|
|---|
| 1067 |
|
|---|
| 1068 | case WM_COMMAND:
|
|---|
| 1069 | wa = WinQueryWindowPtr(hwnd, QWL_USER);
|
|---|
| 1070 | if (!wa)
|
|---|
| 1071 | WinDismissDlg(hwnd, 0);
|
|---|
| 1072 | *szBuff = 0;
|
|---|
| 1073 | WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
|
|---|
| 1074 | bstrip(szBuff);
|
|---|
| 1075 | while ((p = strchr(szBuff, '/')) != NULL)
|
|---|
| 1076 | *p = '\\';
|
|---|
| 1077 | while (strlen(szBuff) > 3 && szBuff[strlen(szBuff) - 1] == '\\')
|
|---|
| 1078 | szBuff[strlen(szBuff) - 1] = 0;
|
|---|
| 1079 | MakeFullName(szBuff);
|
|---|
| 1080 | if (*szBuff && stricmp(szBuff, wa->szCurrentPath)) {
|
|---|
| 1081 | if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
|
|---|
| 1082 | QW_OWNER), hwnd, szBuff, 0))
|
|---|
| 1083 | strcpy(wa->szCurrentPath, szBuff);
|
|---|
| 1084 | else if (SHORT1FROMMP(mp1) != DID_CANCEL)
|
|---|
| 1085 | return 0;
|
|---|
| 1086 | }
|
|---|
| 1087 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath);
|
|---|
| 1088 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 1089 | case WALK_ADD:
|
|---|
| 1090 | *szBuff = 0;
|
|---|
| 1091 | WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
|
|---|
| 1092 | bstrip(szBuff);
|
|---|
| 1093 | while ((p = strchr(szBuff, '/')) != NULL)
|
|---|
| 1094 | *p = '\\';
|
|---|
| 1095 | if (*szBuff && !IsFile(szBuff)) {
|
|---|
| 1096 | MakeFullName(szBuff);
|
|---|
| 1097 | add_udir(TRUE, szBuff);
|
|---|
| 1098 | if (fUdirsChanged) {
|
|---|
| 1099 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1100 | WALK_USERLIST,
|
|---|
| 1101 | LM_INSERTITEM,
|
|---|
| 1102 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 1103 | MPFROMP(szBuff));
|
|---|
| 1104 | wa->changed = 1;
|
|---|
| 1105 | }
|
|---|
| 1106 | }
|
|---|
| 1107 | break;
|
|---|
| 1108 |
|
|---|
| 1109 | case WALK_DELETE:
|
|---|
| 1110 | *szBuff = 0;
|
|---|
| 1111 | WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
|
|---|
| 1112 | bstrip(szBuff);
|
|---|
| 1113 | while ((p = strchr(szBuff, '/')) != NULL)
|
|---|
| 1114 | *p = '\\';
|
|---|
| 1115 | if (*szBuff && !IsFile(szBuff)) {
|
|---|
| 1116 | MakeFullName(szBuff);
|
|---|
| 1117 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 1118 | WALK_USERLIST,
|
|---|
| 1119 | LM_SEARCHSTRING,
|
|---|
| 1120 | MPFROM2SHORT(0, LIT_FIRST),
|
|---|
| 1121 | MPFROMP(szBuff));
|
|---|
| 1122 | if (sSelect >= 0) {
|
|---|
| 1123 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1124 | WALK_USERLIST,
|
|---|
| 1125 | LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
|
|---|
| 1126 | remove_udir(szBuff);
|
|---|
| 1127 | wa->changed = 1;
|
|---|
| 1128 | }
|
|---|
| 1129 | }
|
|---|
| 1130 | break;
|
|---|
| 1131 |
|
|---|
| 1132 | case DID_OK:
|
|---|
| 1133 | if (*wa->szCurrentPath) {
|
|---|
| 1134 | strcpy(wa->szReturnPath, wa->szCurrentPath);
|
|---|
| 1135 | MakeValidDir(wa->szReturnPath);
|
|---|
| 1136 | if (fAutoAddAllDirs)
|
|---|
| 1137 | add_udir(FALSE, wa->szReturnPath);
|
|---|
| 1138 | if (fChangeTarget) {
|
|---|
| 1139 | strcpy(targetdir, wa->szReturnPath);
|
|---|
| 1140 | PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
|
|---|
| 1141 | }
|
|---|
| 1142 | }
|
|---|
| 1143 | if (wa->changed)
|
|---|
| 1144 | WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
|
|---|
| 1145 | WinDismissDlg(hwnd, 1);
|
|---|
| 1146 | break;
|
|---|
| 1147 |
|
|---|
| 1148 | case IDM_HELP:
|
|---|
| 1149 | if (hwndHelp)
|
|---|
| 1150 | WinSendMsg(hwndHelp,
|
|---|
| 1151 | HM_DISPLAY_HELP,
|
|---|
| 1152 | MPFROM2SHORT(HELP_WALKEM, 0), MPFROMSHORT(HM_RESOURCEID));
|
|---|
| 1153 | break;
|
|---|
| 1154 |
|
|---|
| 1155 | case DID_CANCEL:
|
|---|
| 1156 | if (wa->changed)
|
|---|
| 1157 | WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
|
|---|
| 1158 | free(wa);
|
|---|
| 1159 | WinDismissDlg(hwnd, 0);
|
|---|
| 1160 | break;
|
|---|
| 1161 | }
|
|---|
| 1162 | return 0;
|
|---|
| 1163 |
|
|---|
| 1164 | case WM_CLOSE:
|
|---|
| 1165 | break;
|
|---|
| 1166 | }
|
|---|
| 1167 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1168 | }
|
|---|
| 1169 |
|
|---|
| 1170 | MRESULT EXPENTRY WalkAllDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 1171 | {
|
|---|
| 1172 | switch (msg) {
|
|---|
| 1173 | case WM_INITDLG:
|
|---|
| 1174 | return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
|
|---|
| 1175 | }
|
|---|
| 1176 | return WalkDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1177 | }
|
|---|
| 1178 |
|
|---|
| 1179 | MRESULT EXPENTRY WalkCopyDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 1180 | {
|
|---|
| 1181 | switch (msg) {
|
|---|
| 1182 | case WM_INITDLG:
|
|---|
| 1183 | WinSetWindowText(hwnd, GetPString(IDS_WALKCOPYDLGTEXT));
|
|---|
| 1184 | return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
|
|---|
| 1185 | }
|
|---|
| 1186 | return WalkDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1187 | }
|
|---|
| 1188 |
|
|---|
| 1189 | MRESULT EXPENTRY WalkMoveDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 1190 | {
|
|---|
| 1191 | switch (msg) {
|
|---|
| 1192 | case WM_INITDLG:
|
|---|
| 1193 | WinSetWindowText(hwnd, GetPString(IDS_WALKMOVEDLGTEXT));
|
|---|
| 1194 | return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
|
|---|
| 1195 | }
|
|---|
| 1196 | return WalkDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1197 | }
|
|---|
| 1198 |
|
|---|
| 1199 | MRESULT EXPENTRY WalkExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
|
|---|
| 1200 | MPARAM mp2)
|
|---|
| 1201 | {
|
|---|
| 1202 | switch (msg) {
|
|---|
| 1203 | case WM_INITDLG:
|
|---|
| 1204 | WinSetWindowText(hwnd, GetPString(IDS_WALKEXTRACTDLGTEXT));
|
|---|
| 1205 | return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
|
|---|
| 1206 | }
|
|---|
| 1207 | return WalkDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1208 | }
|
|---|
| 1209 |
|
|---|
| 1210 | MRESULT EXPENTRY WalkTargetDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
|
|---|
| 1211 | MPARAM mp2)
|
|---|
| 1212 | {
|
|---|
| 1213 | switch (msg) {
|
|---|
| 1214 | case WM_INITDLG:
|
|---|
| 1215 | {
|
|---|
| 1216 | char s[CCHMAXPATH + 32];
|
|---|
| 1217 |
|
|---|
| 1218 | sprintf(s,
|
|---|
| 1219 | GetPString(IDS_WALKTARGETDLGTEXT),
|
|---|
| 1220 | (*targetdir) ?
|
|---|
| 1221 | NullStr :
|
|---|
| 1222 | " (",
|
|---|
| 1223 | (*targetdir) ?
|
|---|
| 1224 | NullStr : GetPString(IDS_NONE), (*targetdir) ? NullStr : ")");
|
|---|
| 1225 | WinSetWindowText(hwnd, s);
|
|---|
| 1226 | }
|
|---|
| 1227 | return WalkDlgProc(hwnd, UM_SETUP2, mp1, mp2);
|
|---|
| 1228 | }
|
|---|
| 1229 | return WalkDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1230 | }
|
|---|
| 1231 |
|
|---|
| 1232 | MRESULT EXPENTRY WalkTwoDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 1233 | {
|
|---|
| 1234 | WALK2 *wa;
|
|---|
| 1235 | CHAR szBuff[CCHMAXPATH + 1], szBuffer[CCHMAXPATH + 1], *p;
|
|---|
| 1236 | SHORT sSelect;
|
|---|
| 1237 | static BOOL okay; /* avoid combobox selecting as filled */
|
|---|
| 1238 |
|
|---|
| 1239 | switch (msg) {
|
|---|
| 1240 | case UM_SETUP2:
|
|---|
| 1241 | case WM_INITDLG:
|
|---|
| 1242 | okay = FALSE;
|
|---|
| 1243 | if (!mp2) {
|
|---|
| 1244 | WinDismissDlg(hwnd, 0);
|
|---|
| 1245 | break;
|
|---|
| 1246 | }
|
|---|
| 1247 | WinSetWindowPtr(hwnd, QWL_USER, mp2);
|
|---|
| 1248 | wa = mp2;
|
|---|
| 1249 | {
|
|---|
| 1250 | PFNWP oldproc;
|
|---|
| 1251 |
|
|---|
| 1252 | oldproc = WinSubclassWindow(WinWindowFromID(hwnd, WALK_PATH),
|
|---|
| 1253 | (PFNWP) TextSubProc);
|
|---|
| 1254 | if (oldproc)
|
|---|
| 1255 | WinSetWindowPtr(WinWindowFromID(hwnd, WALK_PATH),
|
|---|
| 1256 | QWL_USER, (PVOID) oldproc);
|
|---|
| 1257 | oldproc = WinSubclassWindow(WinWindowFromID(hwnd, WALK2_PATH),
|
|---|
| 1258 | (PFNWP) TextSubProc);
|
|---|
| 1259 | if (oldproc)
|
|---|
| 1260 | WinSetWindowPtr(WinWindowFromID(hwnd, WALK2_PATH),
|
|---|
| 1261 | QWL_USER, (PVOID) oldproc);
|
|---|
| 1262 | }
|
|---|
| 1263 | if (!*wa->szCurrentPath1)
|
|---|
| 1264 | save_dir2(wa->szCurrentPath1);
|
|---|
| 1265 | MakeFullName(wa->szCurrentPath1);
|
|---|
| 1266 | if (!*wa->szCurrentPath2)
|
|---|
| 1267 | save_dir2(wa->szCurrentPath2);
|
|---|
| 1268 | MakeFullName(wa->szCurrentPath2);
|
|---|
| 1269 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1270 | WALK_PATH,
|
|---|
| 1271 | EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
|---|
| 1272 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
|
|---|
| 1273 | WinSendDlgItemMsg(hwnd, WALK2_PATH, EM_SETTEXTLIMIT,
|
|---|
| 1274 | MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
|---|
| 1275 | WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
|
|---|
| 1276 | FillPathListBox(hwnd,
|
|---|
| 1277 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 1278 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 1279 | wa->szCurrentPath1, FALSE);
|
|---|
| 1280 | FillPathListBox(hwnd,
|
|---|
| 1281 | WinWindowFromID(hwnd, WALK2_DRIVELIST),
|
|---|
| 1282 | WinWindowFromID(hwnd, WALK2_DIRLIST),
|
|---|
| 1283 | wa->szCurrentPath2, FALSE);
|
|---|
| 1284 | if (!PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID))
|
|---|
| 1285 | okay = TRUE;
|
|---|
| 1286 | {
|
|---|
| 1287 | MRESULT ret;
|
|---|
| 1288 |
|
|---|
| 1289 | ret = WinDefDlgProc(hwnd, WM_INITDLG, mp1, mp2);
|
|---|
| 1290 | WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
|
|---|
| 1291 | WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
|
|---|
| 1292 | WinInvalidateRect(WinWindowFromID(hwnd, WALK2_PATH), NULL, TRUE);
|
|---|
| 1293 | return ret;
|
|---|
| 1294 | }
|
|---|
| 1295 |
|
|---|
| 1296 | case UM_SETUP4:
|
|---|
| 1297 | okay = TRUE;
|
|---|
| 1298 | return 0;
|
|---|
| 1299 |
|
|---|
| 1300 | case WM_PRESPARAMCHANGED:
|
|---|
| 1301 | {
|
|---|
| 1302 | ULONG AttrFound, AttrValue[64], cbRetLen;
|
|---|
| 1303 |
|
|---|
| 1304 | cbRetLen = WinQueryPresParam(hwnd, (ULONG) mp1, 0, &AttrFound,
|
|---|
| 1305 | (ULONG) sizeof(AttrValue), &AttrValue, 0);
|
|---|
| 1306 | if (cbRetLen) {
|
|---|
| 1307 | switch (AttrFound) {
|
|---|
| 1308 | case PP_FONTNAMESIZE:
|
|---|
| 1309 | PrfWriteProfileData(fmprof,
|
|---|
| 1310 | appname,
|
|---|
| 1311 | "WalkFont", (PVOID) AttrValue, cbRetLen);
|
|---|
| 1312 | *WalkFont = 0;
|
|---|
| 1313 | WalkFontSize = sizeof(WalkFont);
|
|---|
| 1314 | WinInvalidateRect(WinWindowFromID(hwnd, WALK_PATH), NULL, TRUE);
|
|---|
| 1315 | break;
|
|---|
| 1316 | }
|
|---|
| 1317 | }
|
|---|
| 1318 | }
|
|---|
| 1319 | break;
|
|---|
| 1320 |
|
|---|
| 1321 | case UM_SETUP:
|
|---|
| 1322 | {
|
|---|
| 1323 | INT x;
|
|---|
| 1324 | USHORT id[] = { WALK_PATH, WALK_DIRLIST,
|
|---|
| 1325 | WALK2_PATH, WALK2_DIRLIST, 0
|
|---|
| 1326 | };
|
|---|
| 1327 |
|
|---|
| 1328 | if (*WalkFont ||
|
|---|
| 1329 | (PrfQueryProfileData(fmprof,
|
|---|
| 1330 | appname,
|
|---|
| 1331 | "WalkFont",
|
|---|
| 1332 | (PVOID) WalkFont,
|
|---|
| 1333 | &WalkFontSize) && WalkFontSize)) {
|
|---|
| 1334 | for (x = 0; id[x]; x++)
|
|---|
| 1335 | WinSetPresParam(WinWindowFromID(hwnd, id[x]),
|
|---|
| 1336 | PP_FONTNAMESIZE, WalkFontSize, (PVOID) WalkFont);
|
|---|
| 1337 | }
|
|---|
| 1338 | }
|
|---|
| 1339 | return 0;
|
|---|
| 1340 |
|
|---|
| 1341 | case UM_CONTROL:
|
|---|
| 1342 | case WM_CONTROL:
|
|---|
| 1343 | wa = WinQueryWindowPtr(hwnd, QWL_USER);
|
|---|
| 1344 | if (SHORT1FROMMP(mp1) == WALK_DRIVELIST ||
|
|---|
| 1345 | SHORT1FROMMP(mp1) == WALK_DIRLIST ||
|
|---|
| 1346 | SHORT1FROMMP(mp1) == WALK2_DRIVELIST ||
|
|---|
| 1347 | SHORT1FROMMP(mp1) == WALK2_DIRLIST) {
|
|---|
| 1348 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 1349 | SHORT1FROMMP(mp1),
|
|---|
| 1350 | LM_QUERYSELECTION, MPVOID, MPVOID);
|
|---|
| 1351 | *szBuffer = 0;
|
|---|
| 1352 | if (sSelect >= 0)
|
|---|
| 1353 | WinSendDlgItemMsg(hwnd, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
|
|---|
| 1354 | MPFROM2SHORT(sSelect, CCHMAXPATH),
|
|---|
| 1355 | MPFROMP(szBuffer));
|
|---|
| 1356 | }
|
|---|
| 1357 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 1358 | case WALK_DRIVELIST:
|
|---|
| 1359 | if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_ENTER) {
|
|---|
| 1360 |
|
|---|
| 1361 | ULONG ulDirLen = CCHMAXPATH;
|
|---|
| 1362 | APIRET rc;
|
|---|
| 1363 |
|
|---|
| 1364 | rc = DosQCurDir(toupper(*szBuffer) - '@', &szBuff[3], &ulDirLen);
|
|---|
| 1365 | if (!rc) {
|
|---|
| 1366 | strcpy(wa->szCurrentPath1, "C:\\");
|
|---|
| 1367 | *wa->szCurrentPath1 = toupper(*szBuffer);
|
|---|
| 1368 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
|
|---|
| 1369 | FillPathListBox(hwnd,
|
|---|
| 1370 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 1371 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 1372 | wa->szCurrentPath1, FALSE);
|
|---|
| 1373 | }
|
|---|
| 1374 | }
|
|---|
| 1375 | break;
|
|---|
| 1376 |
|
|---|
| 1377 | case WALK_DIRLIST:
|
|---|
| 1378 | if (okay && SHORT2FROMMP(mp1) == LN_ENTER) {
|
|---|
| 1379 |
|
|---|
| 1380 | ULONG ulSearchCount;
|
|---|
| 1381 | FILEFINDBUF3 findbuf;
|
|---|
| 1382 | HDIR hDir;
|
|---|
| 1383 | APIRET rc;
|
|---|
| 1384 |
|
|---|
| 1385 | bstrip(szBuffer);
|
|---|
| 1386 | if (*szBuffer) {
|
|---|
| 1387 | strcpy(szBuff, wa->szCurrentPath1);
|
|---|
| 1388 | if (szBuff[strlen(szBuff) - 1] != '\\')
|
|---|
| 1389 | strcat(szBuff, "\\");
|
|---|
| 1390 | strcat(szBuff, szBuffer);
|
|---|
| 1391 | MakeFullName(szBuff);
|
|---|
| 1392 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1393 | hDir = HDIR_CREATE;
|
|---|
| 1394 | ulSearchCount = 1;
|
|---|
| 1395 | if (!IsRoot(szBuff)) {
|
|---|
| 1396 | rc = DosFindFirst(szBuff,
|
|---|
| 1397 | &hDir,
|
|---|
| 1398 | FILE_DIRECTORY |
|
|---|
| 1399 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 1400 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 1401 | &findbuf,
|
|---|
| 1402 | sizeof(FILEFINDBUF3),
|
|---|
| 1403 | &ulSearchCount, FIL_STANDARD);
|
|---|
| 1404 | if (!rc)
|
|---|
| 1405 | DosFindClose(hDir);
|
|---|
| 1406 | }
|
|---|
| 1407 | else {
|
|---|
| 1408 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 1409 | rc = 0;
|
|---|
| 1410 | }
|
|---|
| 1411 | if (!rc && (findbuf.attrFile & FILE_DIRECTORY)) {
|
|---|
| 1412 | strcpy(wa->szCurrentPath1, szBuff);
|
|---|
| 1413 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
|
|---|
| 1414 | FillPathListBox(hwnd,
|
|---|
| 1415 | WinWindowFromID(hwnd, WALK_DRIVELIST),
|
|---|
| 1416 | WinWindowFromID(hwnd, WALK_DIRLIST),
|
|---|
| 1417 | wa->szCurrentPath1, FALSE);
|
|---|
| 1418 | }
|
|---|
| 1419 | }
|
|---|
| 1420 | }
|
|---|
| 1421 | break;
|
|---|
| 1422 |
|
|---|
| 1423 | case WALK2_DRIVELIST:
|
|---|
| 1424 | if (okay && *szBuffer && SHORT2FROMMP(mp1) == LN_ENTER) {
|
|---|
| 1425 |
|
|---|
| 1426 | ULONG ulDirLen = CCHMAXPATH;
|
|---|
| 1427 | APIRET rc;
|
|---|
| 1428 |
|
|---|
| 1429 | rc = DosQCurDir(toupper(*szBuffer) - '@', &szBuff[3], &ulDirLen);
|
|---|
| 1430 | if (!rc) {
|
|---|
| 1431 | strcpy(wa->szCurrentPath2, "C:\\");
|
|---|
| 1432 | *wa->szCurrentPath2 = toupper(*szBuffer);
|
|---|
| 1433 | WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
|
|---|
| 1434 | FillPathListBox(hwnd,
|
|---|
| 1435 | WinWindowFromID(hwnd, WALK2_DRIVELIST),
|
|---|
| 1436 | WinWindowFromID(hwnd, WALK2_DIRLIST),
|
|---|
| 1437 | wa->szCurrentPath2, FALSE);
|
|---|
| 1438 | }
|
|---|
| 1439 | }
|
|---|
| 1440 | break;
|
|---|
| 1441 |
|
|---|
| 1442 | case WALK2_DIRLIST:
|
|---|
| 1443 | if (okay && SHORT2FROMMP(mp1) == LN_ENTER) {
|
|---|
| 1444 |
|
|---|
| 1445 | ULONG ulSearchCount;
|
|---|
| 1446 | FILEFINDBUF3 findbuf;
|
|---|
| 1447 | HDIR hDir;
|
|---|
| 1448 | APIRET rc;
|
|---|
| 1449 |
|
|---|
| 1450 | bstrip(szBuffer);
|
|---|
| 1451 | if (*szBuffer) {
|
|---|
| 1452 | strcpy(szBuff, wa->szCurrentPath2);
|
|---|
| 1453 | if (szBuff[strlen(szBuff) - 1] != '\\')
|
|---|
| 1454 | strcat(szBuff, "\\");
|
|---|
| 1455 | strcat(szBuff, szBuffer);
|
|---|
| 1456 | MakeFullName(szBuff);
|
|---|
| 1457 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1458 | hDir = HDIR_CREATE;
|
|---|
| 1459 | ulSearchCount = 1;
|
|---|
| 1460 | if (!IsRoot(szBuff)) {
|
|---|
| 1461 | rc = DosFindFirst(szBuff,
|
|---|
| 1462 | &hDir,
|
|---|
| 1463 | FILE_DIRECTORY |
|
|---|
| 1464 | MUST_HAVE_DIRECTORY | FILE_READONLY |
|
|---|
| 1465 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
|
|---|
| 1466 | &findbuf,
|
|---|
| 1467 | sizeof(FILEFINDBUF3),
|
|---|
| 1468 | &ulSearchCount, FIL_STANDARD);
|
|---|
| 1469 | if (!rc)
|
|---|
| 1470 | DosFindClose(hDir);
|
|---|
| 1471 | }
|
|---|
| 1472 | else {
|
|---|
| 1473 | findbuf.attrFile = FILE_DIRECTORY;
|
|---|
| 1474 | rc = 0;
|
|---|
| 1475 | }
|
|---|
| 1476 | if (!rc && (findbuf.attrFile & FILE_DIRECTORY)) {
|
|---|
| 1477 | strcpy(wa->szCurrentPath2, szBuff);
|
|---|
| 1478 | WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
|
|---|
| 1479 | FillPathListBox(hwnd,
|
|---|
| 1480 | WinWindowFromID(hwnd, WALK2_DRIVELIST),
|
|---|
| 1481 | WinWindowFromID(hwnd, WALK2_DIRLIST),
|
|---|
| 1482 | wa->szCurrentPath2, FALSE);
|
|---|
| 1483 | }
|
|---|
| 1484 | }
|
|---|
| 1485 | }
|
|---|
| 1486 | break;
|
|---|
| 1487 | }
|
|---|
| 1488 | return 0;
|
|---|
| 1489 |
|
|---|
| 1490 | case WM_COMMAND:
|
|---|
| 1491 | wa = WinQueryWindowPtr(hwnd, QWL_USER);
|
|---|
| 1492 | if (!wa)
|
|---|
| 1493 | WinDismissDlg(hwnd, 0);
|
|---|
| 1494 | *szBuff = 0;
|
|---|
| 1495 | WinQueryDlgItemText(hwnd, WALK_PATH, CCHMAXPATH, szBuff);
|
|---|
| 1496 | bstrip(szBuff);
|
|---|
| 1497 | while ((p = strchr(szBuff, '/')) != NULL)
|
|---|
| 1498 | *p = '\\';
|
|---|
| 1499 | while (strlen(szBuff) > 3 && szBuff[strlen(szBuff) - 1] == '\\')
|
|---|
| 1500 | szBuff[strlen(szBuff) - 1] = 0;
|
|---|
| 1501 | MakeFullName(szBuff);
|
|---|
| 1502 | if (*szBuff && stricmp(szBuff, wa->szCurrentPath1)) {
|
|---|
| 1503 | if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
|
|---|
| 1504 | QW_OWNER), hwnd, szBuff, 0))
|
|---|
| 1505 | strcpy(wa->szCurrentPath1, szBuff);
|
|---|
| 1506 | else if (SHORT1FROMMP(mp1) != DID_CANCEL)
|
|---|
| 1507 | return 0;
|
|---|
| 1508 | }
|
|---|
| 1509 | WinSetDlgItemText(hwnd, WALK_PATH, wa->szCurrentPath1);
|
|---|
| 1510 | *szBuff = 0;
|
|---|
| 1511 | WinQueryDlgItemText(hwnd, WALK2_PATH, CCHMAXPATH, szBuff);
|
|---|
| 1512 | bstrip(szBuff);
|
|---|
| 1513 | while ((p = strchr(szBuff, '/')) != NULL)
|
|---|
| 1514 | *p = '\\';
|
|---|
| 1515 | while (strlen(szBuff) > 3 && szBuff[strlen(szBuff) - 1] == '\\')
|
|---|
| 1516 | szBuff[strlen(szBuff) - 1] = 0;
|
|---|
| 1517 | MakeFullName(szBuff);
|
|---|
| 1518 | if (*szBuff && stricmp(szBuff, wa->szCurrentPath2)) {
|
|---|
| 1519 | if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
|
|---|
| 1520 | QW_OWNER), hwnd, szBuff, 0))
|
|---|
| 1521 | strcpy(wa->szCurrentPath2, szBuff);
|
|---|
| 1522 | else if (SHORT1FROMMP(mp1) != DID_CANCEL)
|
|---|
| 1523 | return 0;
|
|---|
| 1524 | }
|
|---|
| 1525 | WinSetDlgItemText(hwnd, WALK2_PATH, wa->szCurrentPath2);
|
|---|
| 1526 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 1527 | case DID_OK:
|
|---|
| 1528 | WinDismissDlg(hwnd, 1);
|
|---|
| 1529 | break;
|
|---|
| 1530 |
|
|---|
| 1531 | case IDM_HELP:
|
|---|
| 1532 | if (hwndHelp)
|
|---|
| 1533 | WinSendMsg(hwndHelp,
|
|---|
| 1534 | HM_DISPLAY_HELP,
|
|---|
| 1535 | MPFROM2SHORT(HELP_WALKEM2, 0), MPFROMSHORT(HM_RESOURCEID));
|
|---|
| 1536 | break;
|
|---|
| 1537 |
|
|---|
| 1538 | case DID_CANCEL:
|
|---|
| 1539 | WinDismissDlg(hwnd, 0);
|
|---|
| 1540 | break;
|
|---|
| 1541 | }
|
|---|
| 1542 | return 0;
|
|---|
| 1543 |
|
|---|
| 1544 | case WM_CLOSE:
|
|---|
| 1545 | break;
|
|---|
| 1546 | }
|
|---|
| 1547 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1548 | }
|
|---|
| 1549 |
|
|---|
| 1550 | MRESULT EXPENTRY WalkTwoCmpDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
|
|---|
| 1551 | MPARAM mp2)
|
|---|
| 1552 | {
|
|---|
| 1553 | switch (msg) {
|
|---|
| 1554 | case WM_INITDLG:
|
|---|
| 1555 | WinSetWindowText(hwnd, GetPString(IDS_WALKCOMPAREDLGTEXT));
|
|---|
| 1556 | return WalkTwoDlgProc(hwnd, UM_SETUP2, mp1, mp2);
|
|---|
| 1557 | }
|
|---|
| 1558 | return WalkTwoDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1559 | }
|
|---|
| 1560 |
|
|---|
| 1561 | MRESULT EXPENTRY WalkTwoSetDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
|
|---|
| 1562 | MPARAM mp2)
|
|---|
| 1563 | {
|
|---|
| 1564 | switch (msg) {
|
|---|
| 1565 | case WM_INITDLG:
|
|---|
| 1566 | WinSetWindowText(hwnd, GetPString(IDS_WALKSETDIRSDLGTEXT));
|
|---|
| 1567 | return WalkTwoDlgProc(hwnd, UM_SETUP2, mp1, mp2);
|
|---|
| 1568 | }
|
|---|
| 1569 | return WalkTwoDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1570 | }
|
|---|
| 1571 |
|
|---|
| 1572 | #pragma alloc_text(WALKER,FillPathListBox,WalkDlgProc,TextSubProc)
|
|---|
| 1573 | #pragma alloc_text(WALKER,WalkAllDlgProc,WalkCopyDlgProc)
|
|---|
| 1574 | #pragma alloc_text(WALKER,WalkMoveDlgProc,WalkExtractDlgProc,WalkTargetDlgProc)
|
|---|
| 1575 | #pragma alloc_text(WALK2,WalkTwoDlgProc,WalkTwoCmpDlgProc,WalkTwoSetDlgProc)
|
|---|
| 1576 | #pragma alloc_text(UDIRS,add_udir,remove_udir,remove_ldir,load_udirs)
|
|---|
| 1577 | #pragma alloc_text(UDIRS,save_udirs,load_setup,save_setup,add_setup)
|
|---|
| 1578 | #pragma alloc_text(UDIRS,remove_setup)
|
|---|