| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: av2.c 1404 2009-03-15 03:50:25Z stevenhl $ | 
|---|
| 5 |  | 
|---|
| 6 | Archive viewer applet | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| 9 | Copyright (c) 2007, 2008 Steven H. Levine | 
|---|
| 10 |  | 
|---|
| 11 | 23 Sep 07 SHL Sync with standards | 
|---|
| 12 | 23 Sep 07 SHL Get rid of statics | 
|---|
| 13 | 17 Sep 08 JBS Convert to use of wrapped DosFind... (i.e. xDosFind...) | 
|---|
| 14 | 14 Dec 08 SHL Add exception handler support | 
|---|
| 15 |  | 
|---|
| 16 | ***********************************************************************/ | 
|---|
| 17 |  | 
|---|
| 18 | #include <stdlib.h>                     // getenv | 
|---|
| 19 | #include <string.h> | 
|---|
| 20 |  | 
|---|
| 21 | #define INCL_DOS | 
|---|
| 22 | #define INCL_WIN | 
|---|
| 23 | #define INCL_LONGLONG | 
|---|
| 24 | #define INCL_DOSEXCEPTIONS              // XCTP_... | 
|---|
| 25 | #define INCL_DOSERRORS                  // NO_ERROR | 
|---|
| 26 |  | 
|---|
| 27 | #include "dll\fm3dll.h" | 
|---|
| 28 | #include "dll\mainwnd.h"                // hwndBubble | 
|---|
| 29 | #include "dll\notebook.h"               // appname hwndHelp | 
|---|
| 30 | #include "dll\arccnrs.h" | 
|---|
| 31 | #include "dll\fm3str.h" | 
|---|
| 32 | #include "dll\version.h" | 
|---|
| 33 | #include "dll\arccnrs.h" | 
|---|
| 34 | #include "dll\assoc.h"                  // ExecAssociation | 
|---|
| 35 | #include "dll\defview.h"                // ShowMultimedia | 
|---|
| 36 | #include "dll\inis.h"                   // StartIniEditor | 
|---|
| 37 | #include "dll\dirs.h"                   // switch_to | 
|---|
| 38 | #include "dll\viewer.h"                 // StartMLEEditor | 
|---|
| 39 | #include "dll\getnames.h"               // insert_filename | 
|---|
| 40 | #include "dll\copyf.h"                  // unlinkf | 
|---|
| 41 | #include "dll\init.h"                   // InitFM3DLL | 
|---|
| 42 | #include "dll\valid.h"                  // IsFile | 
|---|
| 43 | #include "dll\wrappers.h"               // xDosFind... | 
|---|
| 44 | #include "dll\errutil.h"                // Error reporting | 
|---|
| 45 | #include "dll\excputil.h"               // Exception handlers | 
|---|
| 46 |  | 
|---|
| 47 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 48 |  | 
|---|
| 49 | HMTX av2Sem; | 
|---|
| 50 |  | 
|---|
| 51 | VOID APIENTRY deinit(ULONG why) | 
|---|
| 52 | { | 
|---|
| 53 | /* cleanup before exiting */ | 
|---|
| 54 |  | 
|---|
| 55 | DosCloseMutexSem(av2Sem); | 
|---|
| 56 | if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) { | 
|---|
| 57 | CHAR s[CCHMAXPATH];                 // 23 Sep 07 SHL | 
|---|
| 58 | CHAR *enddir; | 
|---|
| 59 | HDIR search_handle; | 
|---|
| 60 | ULONG num_matches; | 
|---|
| 61 | FILEFINDBUF3 ffb3; | 
|---|
| 62 |  | 
|---|
| 63 | save_dir(s); | 
|---|
| 64 | if (s[strlen(s) - 1] != '\\') | 
|---|
| 65 | strcat(s, "\\"); | 
|---|
| 66 | enddir = &s[strlen(s)]; | 
|---|
| 67 | if (*ArcTempRoot) { | 
|---|
| 68 | strcat(s, ArcTempRoot); | 
|---|
| 69 | strcat(s, "*"); | 
|---|
| 70 | search_handle = HDIR_CREATE; | 
|---|
| 71 | num_matches = 1; | 
|---|
| 72 | if (!xDosFindFirst(s, | 
|---|
| 73 | &search_handle, | 
|---|
| 74 | FILE_NORMAL | FILE_DIRECTORY | FILE_SYSTEM | | 
|---|
| 75 | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED, | 
|---|
| 76 | &ffb3, | 
|---|
| 77 | sizeof(ffb3), | 
|---|
| 78 | &num_matches, | 
|---|
| 79 | FIL_STANDARD)) { | 
|---|
| 80 | do { | 
|---|
| 81 | strcpy(enddir, ffb3.achName); | 
|---|
| 82 | if (ffb3.attrFile & FILE_DIRECTORY) { | 
|---|
| 83 | wipeallf("%s\\*", s); | 
|---|
| 84 | DosDeleteDir(s); | 
|---|
| 85 | } | 
|---|
| 86 | else | 
|---|
| 87 | unlinkf(s); | 
|---|
| 88 | } while (!xDosFindNext(search_handle, | 
|---|
| 89 | &ffb3, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)); | 
|---|
| 90 | DosFindClose(search_handle); | 
|---|
| 91 | } | 
|---|
| 92 | } | 
|---|
| 93 | } | 
|---|
| 94 | else | 
|---|
| 95 | DosCloseMutexSem(av2Sem); | 
|---|
| 96 |  | 
|---|
| 97 | DosExitList(EXLST_REMOVE, deinit); | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | int main(int argc, char *argv[]) | 
|---|
| 101 | { | 
|---|
| 102 | HAB hab; | 
|---|
| 103 | HMQ hmq; | 
|---|
| 104 | QMSG qmsg; | 
|---|
| 105 | HWND hwndFrame = 0; | 
|---|
| 106 | CHAR fullname[CCHMAXPATH] = { 0 };    // 14 Dec 08 SHL was static | 
|---|
| 107 | PSZ thisarg = NULL; | 
|---|
| 108 | UINT x; | 
|---|
| 109 | APIRET regRet; | 
|---|
| 110 | EXCEPTIONREGISTRATIONRECORD regRec = { NULL, NULL }; | 
|---|
| 111 |  | 
|---|
| 112 | strcpy(appname, "AV/2"); | 
|---|
| 113 | fAmAV2 = TRUE; | 
|---|
| 114 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 115 |  | 
|---|
| 116 | regRec.ExceptionHandler = HandleException; | 
|---|
| 117 | regRet = DosSetExceptionHandler(®Rec); | 
|---|
| 118 | if (regRet != NO_ERROR) { | 
|---|
| 119 | DbgMsg(pszSrcFile, __LINE__, | 
|---|
| 120 | "DosSetExceptionHandler failed with error %u", regRet); | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | for (x = 1; x < argc; x++) { | 
|---|
| 124 | if (!strchr("/;,`\'", *argv[x]) && | 
|---|
| 125 | !thisarg && | 
|---|
| 126 | (IsFile(argv[x]) == 1 || | 
|---|
| 127 | (strchr(argv[x], '?') || strchr(argv[x], '*') || | 
|---|
| 128 | !strchr(argv[x], '.')))) { | 
|---|
| 129 | thisarg = argv[x]; | 
|---|
| 130 | break; | 
|---|
| 131 | } | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | DosExitList(EXLST_ADD, deinit); | 
|---|
| 135 |  | 
|---|
| 136 | if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) | 
|---|
| 137 | DosCreateMutexSem("\\SEM32\\AV2", &av2Sem, DC_SEM_SHARED, FALSE); | 
|---|
| 138 |  | 
|---|
| 139 | if (thisarg) { | 
|---|
| 140 | if (DosQueryPathInfo(thisarg, | 
|---|
| 141 | FIL_QUERYFULLNAME, fullname, sizeof(fullname))) | 
|---|
| 142 | strcpy(fullname, thisarg); | 
|---|
| 143 | if (*fullname && (strchr(fullname, '?') || | 
|---|
| 144 | strchr(fullname, '*') || !strchr(fullname, '.'))) { | 
|---|
| 145 |  | 
|---|
| 146 | FILEFINDBUF3 ffb3; | 
|---|
| 147 | ULONG nm; | 
|---|
| 148 | HDIR hdir; | 
|---|
| 149 | CHAR *enddir; | 
|---|
| 150 |  | 
|---|
| 151 | if (!strchr(fullname, '.')) | 
|---|
| 152 | strcat(fullname, ".*"); | 
|---|
| 153 | enddir = strrchr(fullname, '\\'); | 
|---|
| 154 | if (enddir) { | 
|---|
| 155 | enddir++; | 
|---|
| 156 | hdir = HDIR_CREATE; | 
|---|
| 157 | nm = 1; | 
|---|
| 158 | if (!DosFindFirst(fullname, | 
|---|
| 159 | &hdir, | 
|---|
| 160 | FILE_NORMAL | FILE_SYSTEM | | 
|---|
| 161 | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED, | 
|---|
| 162 | &ffb3, sizeof(FILEFINDBUF3), &nm, FIL_STANDARD)) { | 
|---|
| 163 | strcpy(enddir, ffb3.achName); | 
|---|
| 164 | DosFindClose(hdir); | 
|---|
| 165 | } | 
|---|
| 166 | } | 
|---|
| 167 | } | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | hab = WinInitialize(0); | 
|---|
| 171 | if (hab) { | 
|---|
| 172 | hmq = WinCreateMsgQueue(hab, 1024); | 
|---|
| 173 | if (hmq) { | 
|---|
| 174 | { | 
|---|
| 175 | CHAR path[CCHMAXPATH]; | 
|---|
| 176 | CHAR *env; | 
|---|
| 177 | FILESTATUS3 fs; | 
|---|
| 178 |  | 
|---|
| 179 | env = getenv("FM3INI"); | 
|---|
| 180 | if (env && *env) { | 
|---|
| 181 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 182 | if (!DosQueryPathInfo(env, FIL_QUERYFULLNAME, path, sizeof(path))) { | 
|---|
| 183 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 184 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) { | 
|---|
| 185 | if (!(fs.attrFile & FILE_DIRECTORY)) { | 
|---|
| 186 | env = strrchr(path, '\\'); | 
|---|
| 187 | if (env) | 
|---|
| 188 | *env = 0; | 
|---|
| 189 | } | 
|---|
| 190 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 191 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) { | 
|---|
| 192 | if (fs.attrFile & FILE_DIRECTORY) | 
|---|
| 193 | switch_to(path); | 
|---|
| 194 | } | 
|---|
| 195 | } | 
|---|
| 196 | } | 
|---|
| 197 | } | 
|---|
| 198 | } | 
|---|
| 199 | if (InitFM3DLL(hab, argc, argv)) { | 
|---|
| 200 | if (CheckVersion(VERMAJOR, VERMINOR)) { | 
|---|
| 201 | fAmAV2 = TRUE; | 
|---|
| 202 | if (!*fullname) { | 
|---|
| 203 | strcpy(fullname, "*"); | 
|---|
| 204 | if (!insert_filename(HWND_DESKTOP, | 
|---|
| 205 | fullname, | 
|---|
| 206 | TRUE, | 
|---|
| 207 | FALSE) || !*fullname || *fullname == '*') | 
|---|
| 208 | goto Abort; | 
|---|
| 209 | } | 
|---|
| 210 | if (*fullname) { | 
|---|
| 211 | if (ExecAssociation(HWND_DESKTOP, fullname) == -1) { | 
|---|
| 212 | hwndFrame = StartArcCnr(HWND_DESKTOP, | 
|---|
| 213 | (HWND) 0, fullname, 0, NULL); | 
|---|
| 214 | if (!hwndFrame) { | 
|---|
| 215 |  | 
|---|
| 216 | CHAR *p = strrchr(fullname, '.'); | 
|---|
| 217 |  | 
|---|
| 218 | if (p) { | 
|---|
| 219 | if (!stricmp(p, ".INI")) | 
|---|
| 220 | hwndFrame = StartIniEditor(HWND_DESKTOP, fullname, 0); | 
|---|
| 221 | } | 
|---|
| 222 | if (!ShowMultimedia(fullname)) | 
|---|
| 223 | hwndFrame = StartMLEEditor(HWND_DESKTOP, | 
|---|
| 224 | 1, | 
|---|
| 225 | ((*fullname) ? | 
|---|
| 226 | fullname : NULL), (HWND) 0); | 
|---|
| 227 | } | 
|---|
| 228 | if (hwndFrame && WinIsWindow(hab, hwndFrame)) { | 
|---|
| 229 | if (hwndHelp) | 
|---|
| 230 | WinAssociateHelpInstance(hwndHelp, hwndFrame); | 
|---|
| 231 | for (;;) { | 
|---|
| 232 | if (!WinGetMsg(hab, &qmsg, (HWND) 0, 0, 0)) { | 
|---|
| 233 | if (!WinIsWindow(hab, hwndFrame)) | 
|---|
| 234 | break; | 
|---|
| 235 | if (qmsg.hwnd) | 
|---|
| 236 | qmsg.msg = WM_CLOSE; | 
|---|
| 237 | else | 
|---|
| 238 | break; | 
|---|
| 239 | } | 
|---|
| 240 | if (hwndBubble && | 
|---|
| 241 | ((qmsg.msg > (WM_BUTTON1DOWN - 1) && | 
|---|
| 242 | qmsg.msg < (WM_BUTTON3DBLCLK + 1)) || | 
|---|
| 243 | (qmsg.msg > (WM_CHORD - 1) && | 
|---|
| 244 | qmsg.msg < (WM_BUTTON3CLICK + 1))) && | 
|---|
| 245 | WinIsWindowVisible(hwndBubble)) | 
|---|
| 246 | WinShowWindow(hwndBubble, FALSE); | 
|---|
| 247 | WinDispatchMsg(hab, &qmsg); | 
|---|
| 248 | } | 
|---|
| 249 | DosSleep(125); | 
|---|
| 250 | } | 
|---|
| 251 | } | 
|---|
| 252 | } | 
|---|
| 253 | } | 
|---|
| 254 | } | 
|---|
| 255 | Abort: | 
|---|
| 256 | DosSleep(125); | 
|---|
| 257 | WinDestroyMsgQueue(hmq); | 
|---|
| 258 | } | 
|---|
| 259 | WinTerminate(hab); | 
|---|
| 260 | } | 
|---|
| 261 | return 0; | 
|---|
| 262 | } | 
|---|