| [2] | 1 | 
 | 
|---|
| [873] | 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
 | 
|---|
| [1082] | 9 |   Copyright (c) 2007, 2008 Steven H. Levine
 | 
|---|
| [873] | 10 | 
 | 
|---|
 | 11 |   23 Sep 07 SHL Sync with standards
 | 
|---|
 | 12 |   23 Sep 07 SHL Get rid of statics
 | 
|---|
| [1238] | 13 |   17 Sep 08 JBS Convert to use of wrapped DosFind... (i.e. xDosFind...)
 | 
|---|
| [1341] | 14 |   14 Dec 08 SHL Add exception handler support
 | 
|---|
| [873] | 15 | 
 | 
|---|
 | 16 | ***********************************************************************/
 | 
|---|
 | 17 | 
 | 
|---|
| [1341] | 18 | #include <stdlib.h>                     // getenv
 | 
|---|
| [2] | 19 | #include <string.h>
 | 
|---|
| [873] | 20 | 
 | 
|---|
 | 21 | #define INCL_DOS
 | 
|---|
 | 22 | #define INCL_WIN
 | 
|---|
| [907] | 23 | #define INCL_LONGLONG
 | 
|---|
| [1341] | 24 | #define INCL_DOSEXCEPTIONS              // XCTP_...
 | 
|---|
 | 25 | #define INCL_DOSERRORS                  // NO_ERROR
 | 
|---|
| [873] | 26 | 
 | 
|---|
| [1176] | 27 | #include "dll\fm3dll.h"
 | 
|---|
| [1341] | 28 | #include "dll\mainwnd.h"                // hwndBubble
 | 
|---|
 | 29 | #include "dll\notebook.h"               // appname hwndHelp
 | 
|---|
| [1203] | 30 | #include "dll\arccnrs.h"
 | 
|---|
| [1176] | 31 | #include "dll\fm3str.h"
 | 
|---|
| [2] | 32 | #include "dll\version.h"
 | 
|---|
| [907] | 33 | #include "dll\arccnrs.h"
 | 
|---|
| [1155] | 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
 | 
|---|
| [1176] | 38 | #include "dll\viewer.h"                 // StartMLEEditor
 | 
|---|
| [1341] | 39 | #include "dll\getnames.h"               // insert_filename
 | 
|---|
| [1176] | 40 | #include "dll\copyf.h"                  // unlinkf
 | 
|---|
 | 41 | #include "dll\init.h"                   // InitFM3DLL
 | 
|---|
 | 42 | #include "dll\valid.h"                  // IsFile
 | 
|---|
| [1238] | 43 | #include "dll\wrappers.h"               // xDosFind...
 | 
|---|
| [1341] | 44 | #include "dll\errutil.h"                // Error reporting
 | 
|---|
 | 45 | #include "dll\excputil.h"               // Exception handlers
 | 
|---|
| [2] | 46 | 
 | 
|---|
| [1341] | 47 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
 | 48 | 
 | 
|---|
| [2] | 49 | HMTX av2Sem;
 | 
|---|
 | 50 | 
 | 
|---|
| [551] | 51 | VOID APIENTRY deinit(ULONG why)
 | 
|---|
 | 52 | {
 | 
|---|
| [873] | 53 |   /* cleanup before exiting */
 | 
|---|
| [2] | 54 | 
 | 
|---|
 | 55 |   DosCloseMutexSem(av2Sem);
 | 
|---|
| [551] | 56 |   if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) {
 | 
|---|
| [873] | 57 |     CHAR s[CCHMAXPATH];                 // 23 Sep 07 SHL
 | 
|---|
| [551] | 58 |     CHAR *enddir;
 | 
|---|
 | 59 |     HDIR search_handle;
 | 
|---|
 | 60 |     ULONG num_matches;
 | 
|---|
| [873] | 61 |     FILEFINDBUF3 ffb3;
 | 
|---|
| [2] | 62 | 
 | 
|---|
 | 63 |     save_dir(s);
 | 
|---|
| [551] | 64 |     if (s[strlen(s) - 1] != '\\')
 | 
|---|
 | 65 |       strcat(s, "\\");
 | 
|---|
| [2] | 66 |     enddir = &s[strlen(s)];
 | 
|---|
| [551] | 67 |     if (*ArcTempRoot) {
 | 
|---|
 | 68 |       strcat(s, ArcTempRoot);
 | 
|---|
 | 69 |       strcat(s, "*");
 | 
|---|
| [2] | 70 |       search_handle = HDIR_CREATE;
 | 
|---|
| [841] | 71 |       num_matches = 1;
 | 
|---|
| [1238] | 72 |       if (!xDosFindFirst(s,
 | 
|---|
| [551] | 73 |                         &search_handle,
 | 
|---|
| [873] | 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)) {
 | 
|---|
| [551] | 80 |         do {
 | 
|---|
| [873] | 81 |           strcpy(enddir, ffb3.achName);
 | 
|---|
 | 82 |           if (ffb3.attrFile & FILE_DIRECTORY) {
 | 
|---|
| [551] | 83 |             wipeallf("%s\\*", s);
 | 
|---|
 | 84 |             DosDeleteDir(s);
 | 
|---|
 | 85 |           }
 | 
|---|
 | 86 |           else
 | 
|---|
| [1404] | 87 |             unlinkf(s);
 | 
|---|
| [1238] | 88 |         } while (!xDosFindNext(search_handle,
 | 
|---|
 | 89 |                               &ffb3, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD));
 | 
|---|
| [551] | 90 |         DosFindClose(search_handle);
 | 
|---|
| [2] | 91 |       }
 | 
|---|
 | 92 |     }
 | 
|---|
 | 93 |   }
 | 
|---|
 | 94 |   else
 | 
|---|
 | 95 |     DosCloseMutexSem(av2Sem);
 | 
|---|
 | 96 | 
 | 
|---|
| [551] | 97 |   DosExitList(EXLST_REMOVE, deinit);
 | 
|---|
| [2] | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
| [551] | 100 | int main(int argc, char *argv[])
 | 
|---|
 | 101 | {
 | 
|---|
 | 102 |   HAB hab;
 | 
|---|
 | 103 |   HMQ hmq;
 | 
|---|
 | 104 |   QMSG qmsg;
 | 
|---|
| [1341] | 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 };
 | 
|---|
| [2] | 111 | 
 | 
|---|
| [551] | 112 |   strcpy(appname, "AV/2");
 | 
|---|
| [2] | 113 |   fAmAV2 = TRUE;
 | 
|---|
 | 114 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1341] | 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 | 
 | 
|---|
| [551] | 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], '.')))) {
 | 
|---|
| [2] | 129 |       thisarg = argv[x];
 | 
|---|
 | 130 |       break;
 | 
|---|
 | 131 |     }
 | 
|---|
 | 132 |   }
 | 
|---|
| [1341] | 133 | 
 | 
|---|
| [551] | 134 |   DosExitList(EXLST_ADD, deinit);
 | 
|---|
| [1341] | 135 | 
 | 
|---|
| [551] | 136 |   if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem))
 | 
|---|
 | 137 |     DosCreateMutexSem("\\SEM32\\AV2", &av2Sem, DC_SEM_SHARED, FALSE);
 | 
|---|
| [1341] | 138 | 
 | 
|---|
| [551] | 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, '.'))) {
 | 
|---|
| [2] | 145 | 
 | 
|---|
| [873] | 146 |       FILEFINDBUF3 ffb3;
 | 
|---|
| [551] | 147 |       ULONG nm;
 | 
|---|
 | 148 |       HDIR hdir;
 | 
|---|
 | 149 |       CHAR *enddir;
 | 
|---|
| [2] | 150 | 
 | 
|---|
| [551] | 151 |       if (!strchr(fullname, '.'))
 | 
|---|
 | 152 |         strcat(fullname, ".*");
 | 
|---|
 | 153 |       enddir = strrchr(fullname, '\\');
 | 
|---|
 | 154 |       if (enddir) {
 | 
|---|
 | 155 |         enddir++;
 | 
|---|
 | 156 |         hdir = HDIR_CREATE;
 | 
|---|
| [841] | 157 |         nm = 1;
 | 
|---|
| [844] | 158 |         if (!DosFindFirst(fullname,
 | 
|---|
| [551] | 159 |                           &hdir,
 | 
|---|
 | 160 |                           FILE_NORMAL | FILE_SYSTEM |
 | 
|---|
 | 161 |                           FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
 | 
|---|
| [873] | 162 |                           &ffb3, sizeof(FILEFINDBUF3), &nm, FIL_STANDARD)) {
 | 
|---|
 | 163 |           strcpy(enddir, ffb3.achName);
 | 
|---|
| [551] | 164 |           DosFindClose(hdir);
 | 
|---|
 | 165 |         }
 | 
|---|
| [2] | 166 |       }
 | 
|---|
 | 167 |     }
 | 
|---|
 | 168 |   }
 | 
|---|
| [1341] | 169 | 
 | 
|---|
| [2] | 170 |   hab = WinInitialize(0);
 | 
|---|
| [551] | 171 |   if (hab) {
 | 
|---|
 | 172 |     hmq = WinCreateMsgQueue(hab, 1024);
 | 
|---|
 | 173 |     if (hmq) {
 | 
|---|
| [2] | 174 |       {
 | 
|---|
| [873] | 175 |         CHAR path[CCHMAXPATH];
 | 
|---|
| [551] | 176 |         CHAR *env;
 | 
|---|
| [844] | 177 |         FILESTATUS3 fs;
 | 
|---|
| [2] | 178 | 
 | 
|---|
| [551] | 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);
 | 
|---|
| [873] | 184 |             if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
 | 
|---|
| [551] | 185 |               if (!(fs.attrFile & FILE_DIRECTORY)) {
 | 
|---|
 | 186 |                 env = strrchr(path, '\\');
 | 
|---|
 | 187 |                 if (env)
 | 
|---|
 | 188 |                   *env = 0;
 | 
|---|
 | 189 |               }
 | 
|---|
 | 190 |               DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [873] | 191 |               if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
 | 
|---|
| [551] | 192 |                 if (fs.attrFile & FILE_DIRECTORY)
 | 
|---|
 | 193 |                   switch_to(path);
 | 
|---|
 | 194 |               }
 | 
|---|
 | 195 |             }
 | 
|---|
 | 196 |           }
 | 
|---|
 | 197 |         }
 | 
|---|
| [2] | 198 |       }
 | 
|---|
| [551] | 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) {
 | 
|---|
| [2] | 215 | 
 | 
|---|
| [551] | 216 |                 CHAR *p = strrchr(fullname, '.');
 | 
|---|
| [2] | 217 | 
 | 
|---|
| [551] | 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 |                 }
 | 
|---|
| [844] | 249 |                 DosSleep(125);
 | 
|---|
| [551] | 250 |               }
 | 
|---|
 | 251 |             }
 | 
|---|
 | 252 |           }
 | 
|---|
 | 253 |         }
 | 
|---|
| [2] | 254 |       }
 | 
|---|
| [551] | 255 |     Abort:
 | 
|---|
| [844] | 256 |       DosSleep(125);
 | 
|---|
| [2] | 257 |       WinDestroyMsgQueue(hmq);
 | 
|---|
 | 258 |     }
 | 
|---|
 | 259 |     WinTerminate(hab);
 | 
|---|
 | 260 |   }
 | 
|---|
 | 261 |   return 0;
 | 
|---|
 | 262 | }
 | 
|---|