| 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 | 
|---|
| 12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| 13 |  | 
|---|
| 14 | ***********************************************************************/ | 
|---|
| 15 |  | 
|---|
| 16 | #define INCL_DOS | 
|---|
| 17 | #define INCL_WIN | 
|---|
| 18 | #define INCL_LONGLONG | 
|---|
| 19 | #include <os2.h> | 
|---|
| 20 |  | 
|---|
| 21 | #include <stdlib.h> | 
|---|
| 22 | #include <stdio.h> | 
|---|
| 23 | #include <string.h> | 
|---|
| 24 | #include <time.h> | 
|---|
| 25 |  | 
|---|
| 26 | #include <ctype.h> | 
|---|
| 27 | #include "fm3dll.h" | 
|---|
| 28 | #include "fm3dlg.h" | 
|---|
| 29 | #include "fm3str.h" | 
|---|
| 30 |  | 
|---|
| 31 | #pragma data_seg(DATA1) | 
|---|
| 32 |  | 
|---|
| 33 | MRESULT EXPENTRY CustomFileDlg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 34 | { | 
|---|
| 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; | 
|---|
| 42 | FILEFINDBUF3L findbuf; | 
|---|
| 43 | HDIR hDir; | 
|---|
| 44 | APIRET rc; | 
|---|
| 45 | LINKDIRS *info, *temp; | 
|---|
| 46 |  | 
|---|
| 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)) | 
|---|
| 58 | rc = xDosFindFirst(info->path, &hDir, FILE_DIRECTORY | | 
|---|
| 59 | MUST_HAVE_DIRECTORY | FILE_READONLY | | 
|---|
| 60 | FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN, | 
|---|
| 61 | &findbuf, sizeof(FILEFINDBUF3L), | 
|---|
| 62 | &ulSearchCount, FIL_STANDARDL); | 
|---|
| 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; | 
|---|
| 89 | } | 
|---|
| 90 | } | 
|---|
| 91 | break; | 
|---|
| 92 |  | 
|---|
| 93 | case WM_ADJUSTWINDOWPOS: | 
|---|
| 94 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID); | 
|---|
| 95 | break; | 
|---|
| 96 |  | 
|---|
| 97 | case UM_SETDIR: | 
|---|
| 98 | PaintRecessedWindow(WinWindowFromID(hwnd, FDLG_HELP), | 
|---|
| 99 | (HPS) 0, FALSE, TRUE); | 
|---|
| 100 | return 0; | 
|---|
| 101 |  | 
|---|
| 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; | 
|---|
| 112 |  | 
|---|
| 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; | 
|---|
| 124 |  | 
|---|
| 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; | 
|---|
| 136 |  | 
|---|
| 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; | 
|---|
| 148 |  | 
|---|
| 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; | 
|---|
| 159 |  | 
|---|
| 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; | 
|---|
| 193 | } | 
|---|
| 194 | break; | 
|---|
| 195 | } | 
|---|
| 196 | break; | 
|---|
| 197 |  | 
|---|
| 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; | 
|---|
| 205 | } | 
|---|
| 206 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| 207 | } | 
|---|
| 208 |  | 
|---|
| 209 | BOOL insert_filename(HWND hwnd, CHAR * filename, INT loadit, BOOL newok) | 
|---|
| 210 | { | 
|---|
| 211 | FILEDLG fdlg; | 
|---|
| 212 | FILESTATUS3 fsa; | 
|---|
| 213 | CHAR drive[3], *pdrive = drive, *p; | 
|---|
| 214 | APIRET rc; | 
|---|
| 215 | static CHAR lastfilename[CCHMAXPATH] = ""; | 
|---|
| 216 |  | 
|---|
| 217 | if (!filename) | 
|---|
| 218 | return FALSE; | 
|---|
| 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); | 
|---|
| 225 | } | 
|---|
| 226 | else if (loadit == TRUE) { | 
|---|
| 227 | fdlg.pszTitle = GetPString(IDS_ENTERFILELOADTEXT); | 
|---|
| 228 | fdlg.pszOKButton = GetPString(IDS_LOADTEXT); | 
|---|
| 229 | } | 
|---|
| 230 | else { | 
|---|
| 231 | fdlg.pszTitle = GetPString(IDS_ENTERFILETEXT); | 
|---|
| 232 | fdlg.pszOKButton = GetPString(IDS_OKAYTEXT); | 
|---|
| 233 | } | 
|---|
| 234 | if (IsFullName(filename)) { | 
|---|
| 235 | *drive = *filename; | 
|---|
| 236 | drive[1] = ':'; | 
|---|
| 237 | drive[2] = 0; | 
|---|
| 238 | fdlg.pszIDrive = pdrive; | 
|---|
| 239 | } | 
|---|
| 240 | else if (*lastfilename) { | 
|---|
| 241 | *drive = *lastfilename; | 
|---|
| 242 | drive[1] = ':'; | 
|---|
| 243 | drive[2] = 0; | 
|---|
| 244 | fdlg.pszIDrive = pdrive; | 
|---|
| 245 | } | 
|---|
| 246 |  | 
|---|
| 247 | if (!*filename) { | 
|---|
| 248 | if (*lastfilename) { | 
|---|
| 249 | strcpy(fdlg.szFullFile, lastfilename); | 
|---|
| 250 | p = strrchr(fdlg.szFullFile, '\\'); | 
|---|
| 251 | if (p) { | 
|---|
| 252 | p++; | 
|---|
| 253 | *p = 0; | 
|---|
| 254 | } | 
|---|
| 255 | } | 
|---|
| 256 | if (!loadit || loadit == TRUE) | 
|---|
| 257 | strcat(fdlg.szFullFile, "*.TXT"); | 
|---|
| 258 | else | 
|---|
| 259 | strcat(fdlg.szFullFile, "*"); | 
|---|
| 260 | } | 
|---|
| 261 | else | 
|---|
| 262 | strcpy(fdlg.szFullFile, filename); | 
|---|
| 263 |  | 
|---|
| 264 | if (fCustomFileDlg) { | 
|---|
| 265 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM; | 
|---|
| 266 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg; | 
|---|
| 267 | fdlg.hMod = FM3ModHandle; | 
|---|
| 268 | fdlg.usDlgId = FDLG_FRAME; | 
|---|
| 269 | } | 
|---|
| 270 |  | 
|---|
| 271 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) { | 
|---|
| 272 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC) | 
|---|
| 273 | strcpy(filename, fdlg.szFullFile); | 
|---|
| 274 | else | 
|---|
| 275 | return FALSE; | 
|---|
| 276 | } | 
|---|
| 277 | else | 
|---|
| 278 | return FALSE; | 
|---|
| 279 | MakeFullName(filename); | 
|---|
| 280 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) { | 
|---|
| 281 | if (fsa.attrFile & FILE_DIRECTORY) { | 
|---|
| 282 | /* device or directory */ | 
|---|
| 283 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION, | 
|---|
| 284 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename); | 
|---|
| 285 | return FALSE; | 
|---|
| 286 | } | 
|---|
| 287 | else if (fsa.cbFile == 0) { | 
|---|
| 288 | saymsg(MB_CANCEL, | 
|---|
| 289 | hwnd, filename, GetPString(IDS_ISZEROLENGTHTEXT), filename); | 
|---|
| 290 | return FALSE; | 
|---|
| 291 | } | 
|---|
| 292 | } | 
|---|
| 293 | else if (!newok) { | 
|---|
| 294 | saymsg(MB_CANCEL, | 
|---|
| 295 | hwnd, filename, GetPString(IDS_DOESNTEXISTTEXT), filename); | 
|---|
| 296 | return FALSE; | 
|---|
| 297 | } | 
|---|
| 298 | else { | 
|---|
| 299 | rc = saymsg(MB_YESNOCANCEL, | 
|---|
| 300 | hwnd, filename, GetPString(IDS_CREATENEWTEXT)); | 
|---|
| 301 | if (rc != MBID_YES) | 
|---|
| 302 | return FALSE; | 
|---|
| 303 | } | 
|---|
| 304 | p = filename; | 
|---|
| 305 | while (*p) { | 
|---|
| 306 | if (*p == '/') | 
|---|
| 307 | *p = '\\'; | 
|---|
| 308 | p++; | 
|---|
| 309 | } | 
|---|
| 310 | if (*filename) | 
|---|
| 311 | strcpy(lastfilename, filename); | 
|---|
| 312 | return TRUE; | 
|---|
| 313 | } | 
|---|
| 314 |  | 
|---|
| 315 | BOOL export_filename(HWND hwnd, CHAR * filename, INT overwrite) | 
|---|
| 316 | { | 
|---|
| 317 | FILEDLG fdlg; | 
|---|
| 318 | FILESTATUS3 fsa; | 
|---|
| 319 | CHAR drive[3], *pdrive = drive, *p; | 
|---|
| 320 | static CHAR lastfilename[CCHMAXPATH] = ""; | 
|---|
| 321 |  | 
|---|
| 322 | if (!filename) | 
|---|
| 323 | return FALSE; | 
|---|
| 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)) { | 
|---|
| 330 | *drive = *filename; | 
|---|
| 331 | drive[1] = ':'; | 
|---|
| 332 | drive[2] = 0; | 
|---|
| 333 | fdlg.pszIDrive = pdrive; | 
|---|
| 334 | } | 
|---|
| 335 | else if (*lastfilename) { | 
|---|
| 336 | *drive = *lastfilename; | 
|---|
| 337 | drive[1] = ':'; | 
|---|
| 338 | drive[2] = 0; | 
|---|
| 339 | fdlg.pszIDrive = pdrive; | 
|---|
| 340 | } | 
|---|
| 341 | if (!*filename) { | 
|---|
| 342 | if (*lastfilename) { | 
|---|
| 343 | strcpy(fdlg.szFullFile, lastfilename); | 
|---|
| 344 | p = strrchr(fdlg.szFullFile, '\\'); | 
|---|
| 345 | if (p) { | 
|---|
| 346 | p++; | 
|---|
| 347 | *p = 0; | 
|---|
| 348 | } | 
|---|
| 349 | } | 
|---|
| 350 | strcat(fdlg.szFullFile, "*.TXT"); | 
|---|
| 351 | } | 
|---|
| 352 | else | 
|---|
| 353 | strcpy(fdlg.szFullFile, filename); | 
|---|
| 354 |  | 
|---|
| 355 | if (fCustomFileDlg) { | 
|---|
| 356 | fdlg.fl |= FDS_HELPBUTTON | FDS_CUSTOM; | 
|---|
| 357 | fdlg.pfnDlgProc = (PFNWP) CustomFileDlg; | 
|---|
| 358 | fdlg.hMod = FM3ModHandle; | 
|---|
| 359 | fdlg.usDlgId = FDLG_FRAME; | 
|---|
| 360 | } | 
|---|
| 361 |  | 
|---|
| 362 | if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) { | 
|---|
| 363 | if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC) | 
|---|
| 364 | strcpy(filename, fdlg.szFullFile); | 
|---|
| 365 | else | 
|---|
| 366 | return FALSE; | 
|---|
| 367 | } | 
|---|
| 368 | else | 
|---|
| 369 | return FALSE; | 
|---|
| 370 | MakeFullName(filename); | 
|---|
| 371 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) { | 
|---|
| 372 | if (fsa.attrFile & FILE_DIRECTORY) {        /* device or directory */ | 
|---|
| 373 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION, | 
|---|
| 374 | hwnd, filename, GetPString(IDS_EXISTSBUTNOTFILETEXT), filename); | 
|---|
| 375 | return FALSE; | 
|---|
| 376 | } | 
|---|
| 377 | else if (overwrite && fsa.cbFile != 0) { | 
|---|
| 378 | if (saymsg(MB_YESNO, | 
|---|
| 379 | hwnd, | 
|---|
| 380 | filename, | 
|---|
| 381 | GetPString(IDS_EXISTSERASETEXT), filename) == MBID_YES) | 
|---|
| 382 | unlinkf("%s", filename); | 
|---|
| 383 | } | 
|---|
| 384 | } | 
|---|
| 385 | p = filename; | 
|---|
| 386 | while (*p) { | 
|---|
| 387 | if (*p == '/') | 
|---|
| 388 | *p = '\\'; | 
|---|
| 389 | p++; | 
|---|
| 390 | } | 
|---|
| 391 | if (*filename) | 
|---|
| 392 | strcpy(lastfilename, filename); | 
|---|
| 393 | return TRUE; | 
|---|
| 394 | } | 
|---|
| 395 |  | 
|---|
| 396 | #pragma alloc_text(GETNAMES,insert_filename,export_filename,CustomFileDlg) | 
|---|