| [2] | 1 | 
 | 
|---|
| [873] | 2 | /***********************************************************************
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 |   $Id: av2.c 1176 2008-09-10 21:52:46Z jbs $
 | 
|---|
 | 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
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | ***********************************************************************/
 | 
|---|
 | 15 | 
 | 
|---|
| [2] | 16 | #include <stdlib.h>
 | 
|---|
 | 17 | #include <string.h>
 | 
|---|
| [873] | 18 | 
 | 
|---|
 | 19 | #define INCL_DOS
 | 
|---|
 | 20 | #define INCL_WIN
 | 
|---|
| [907] | 21 | #define INCL_LONGLONG
 | 
|---|
| [873] | 22 | 
 | 
|---|
| [1176] | 23 | #include "dll\fm3dll.h"
 | 
|---|
 | 24 | #include "dll\fm3str.h"
 | 
|---|
| [2] | 25 | #include "dll\version.h"
 | 
|---|
| [907] | 26 | #include "dll\arccnrs.h"
 | 
|---|
| [1155] | 27 | #include "dll\assoc.h"                  // ExecAssociation
 | 
|---|
 | 28 | #include "dll\defview.h"                // ShowMultimedia
 | 
|---|
 | 29 | #include "dll\inis.h"                   // StartIniEditor
 | 
|---|
 | 30 | #include "dll\dirs.h"                   // switch_to
 | 
|---|
| [1176] | 31 | #include "dll\viewer.h"                 // StartMLEEditor
 | 
|---|
 | 32 | #include "dll\getnames.h"                       // insert_filename
 | 
|---|
 | 33 | #include "dll\copyf.h"                  // unlinkf
 | 
|---|
 | 34 | #include "dll\init.h"                   // InitFM3DLL
 | 
|---|
 | 35 | #include "dll\valid.h"                  // IsFile
 | 
|---|
| [2] | 36 | 
 | 
|---|
 | 37 | HMTX av2Sem;
 | 
|---|
 | 38 | 
 | 
|---|
| [551] | 39 | VOID APIENTRY deinit(ULONG why)
 | 
|---|
 | 40 | {
 | 
|---|
| [873] | 41 |   /* cleanup before exiting */
 | 
|---|
| [2] | 42 | 
 | 
|---|
 | 43 |   DosCloseMutexSem(av2Sem);
 | 
|---|
| [551] | 44 |   if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) {
 | 
|---|
| [873] | 45 |     CHAR s[CCHMAXPATH];                 // 23 Sep 07 SHL
 | 
|---|
| [551] | 46 |     CHAR *enddir;
 | 
|---|
 | 47 |     HDIR search_handle;
 | 
|---|
 | 48 |     ULONG num_matches;
 | 
|---|
| [873] | 49 |     FILEFINDBUF3 ffb3;
 | 
|---|
| [2] | 50 | 
 | 
|---|
 | 51 |     save_dir(s);
 | 
|---|
| [551] | 52 |     if (s[strlen(s) - 1] != '\\')
 | 
|---|
 | 53 |       strcat(s, "\\");
 | 
|---|
| [2] | 54 |     enddir = &s[strlen(s)];
 | 
|---|
| [551] | 55 |     if (*ArcTempRoot) {
 | 
|---|
 | 56 |       strcat(s, ArcTempRoot);
 | 
|---|
 | 57 |       strcat(s, "*");
 | 
|---|
| [2] | 58 |       search_handle = HDIR_CREATE;
 | 
|---|
| [841] | 59 |       num_matches = 1;
 | 
|---|
| [844] | 60 |       if (!DosFindFirst(s,
 | 
|---|
| [551] | 61 |                         &search_handle,
 | 
|---|
| [873] | 62 |                         FILE_NORMAL | FILE_DIRECTORY | FILE_SYSTEM |
 | 
|---|
 | 63 |                         FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
 | 
|---|
 | 64 |                         &ffb3,
 | 
|---|
 | 65 |                         sizeof(ffb3),
 | 
|---|
 | 66 |                         &num_matches,
 | 
|---|
 | 67 |                         FIL_STANDARD)) {
 | 
|---|
| [551] | 68 |         do {
 | 
|---|
| [873] | 69 |           strcpy(enddir, ffb3.achName);
 | 
|---|
 | 70 |           if (ffb3.attrFile & FILE_DIRECTORY) {
 | 
|---|
| [551] | 71 |             wipeallf("%s\\*", s);
 | 
|---|
 | 72 |             DosDeleteDir(s);
 | 
|---|
 | 73 |           }
 | 
|---|
 | 74 |           else
 | 
|---|
 | 75 |             unlinkf("%s", s);
 | 
|---|
| [844] | 76 |         } while (!DosFindNext(search_handle,
 | 
|---|
| [873] | 77 |                               &ffb3, sizeof(FILEFINDBUF3), &num_matches));
 | 
|---|
| [551] | 78 |         DosFindClose(search_handle);
 | 
|---|
| [2] | 79 |       }
 | 
|---|
 | 80 |     }
 | 
|---|
 | 81 |   }
 | 
|---|
 | 82 |   else
 | 
|---|
 | 83 |     DosCloseMutexSem(av2Sem);
 | 
|---|
 | 84 | 
 | 
|---|
| [551] | 85 |   DosExitList(EXLST_REMOVE, deinit);
 | 
|---|
| [2] | 86 | }
 | 
|---|
 | 87 | 
 | 
|---|
| [551] | 88 | int main(int argc, char *argv[])
 | 
|---|
 | 89 | {
 | 
|---|
 | 90 |   HAB hab;
 | 
|---|
 | 91 |   HMQ hmq;
 | 
|---|
 | 92 |   QMSG qmsg;
 | 
|---|
 | 93 |   HWND hwndFrame = (HWND) 0;
 | 
|---|
| [873] | 94 |   static CHAR fullname[CCHMAXPATH];     // 23 Sep 07 SHL fixme to not be static
 | 
|---|
| [551] | 95 |   CHAR *thisarg = NULL;
 | 
|---|
 | 96 |   INT x;
 | 
|---|
| [2] | 97 | 
 | 
|---|
 | 98 |   *fullname = 0;
 | 
|---|
| [551] | 99 |   strcpy(appname, "AV/2");
 | 
|---|
| [2] | 100 |   fAmAV2 = TRUE;
 | 
|---|
 | 101 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [551] | 102 |   for (x = 1; x < argc; x++) {
 | 
|---|
 | 103 |     if (!strchr("/;,`\'", *argv[x]) &&
 | 
|---|
 | 104 |         !thisarg &&
 | 
|---|
 | 105 |         (IsFile(argv[x]) == 1 ||
 | 
|---|
 | 106 |          (strchr(argv[x], '?') || strchr(argv[x], '*') ||
 | 
|---|
 | 107 |           !strchr(argv[x], '.')))) {
 | 
|---|
| [2] | 108 |       thisarg = argv[x];
 | 
|---|
 | 109 |       break;
 | 
|---|
 | 110 |     }
 | 
|---|
 | 111 |   }
 | 
|---|
| [551] | 112 |   DosExitList(EXLST_ADD, deinit);
 | 
|---|
 | 113 |   if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem))
 | 
|---|
 | 114 |     DosCreateMutexSem("\\SEM32\\AV2", &av2Sem, DC_SEM_SHARED, FALSE);
 | 
|---|
 | 115 |   if (thisarg) {
 | 
|---|
 | 116 |     if (DosQueryPathInfo(thisarg,
 | 
|---|
 | 117 |                          FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
 | 
|---|
 | 118 |       strcpy(fullname, thisarg);
 | 
|---|
 | 119 |     if (*fullname && (strchr(fullname, '?') ||
 | 
|---|
 | 120 |                       strchr(fullname, '*') || !strchr(fullname, '.'))) {
 | 
|---|
| [2] | 121 | 
 | 
|---|
| [873] | 122 |       FILEFINDBUF3 ffb3;
 | 
|---|
| [551] | 123 |       ULONG nm;
 | 
|---|
 | 124 |       HDIR hdir;
 | 
|---|
 | 125 |       CHAR *enddir;
 | 
|---|
| [2] | 126 | 
 | 
|---|
| [551] | 127 |       if (!strchr(fullname, '.'))
 | 
|---|
 | 128 |         strcat(fullname, ".*");
 | 
|---|
 | 129 |       enddir = strrchr(fullname, '\\');
 | 
|---|
 | 130 |       if (enddir) {
 | 
|---|
 | 131 |         enddir++;
 | 
|---|
 | 132 |         hdir = HDIR_CREATE;
 | 
|---|
| [841] | 133 |         nm = 1;
 | 
|---|
| [844] | 134 |         if (!DosFindFirst(fullname,
 | 
|---|
| [551] | 135 |                           &hdir,
 | 
|---|
 | 136 |                           FILE_NORMAL | FILE_SYSTEM |
 | 
|---|
 | 137 |                           FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
 | 
|---|
| [873] | 138 |                           &ffb3, sizeof(FILEFINDBUF3), &nm, FIL_STANDARD)) {
 | 
|---|
 | 139 |           strcpy(enddir, ffb3.achName);
 | 
|---|
| [551] | 140 |           DosFindClose(hdir);
 | 
|---|
 | 141 |         }
 | 
|---|
| [2] | 142 |       }
 | 
|---|
 | 143 |     }
 | 
|---|
 | 144 |   }
 | 
|---|
 | 145 |   hab = WinInitialize(0);
 | 
|---|
| [551] | 146 |   if (hab) {
 | 
|---|
 | 147 |     hmq = WinCreateMsgQueue(hab, 1024);
 | 
|---|
 | 148 |     if (hmq) {
 | 
|---|
| [2] | 149 |       {
 | 
|---|
| [873] | 150 |         CHAR path[CCHMAXPATH];
 | 
|---|
| [551] | 151 |         CHAR *env;
 | 
|---|
| [844] | 152 |         FILESTATUS3 fs;
 | 
|---|
| [2] | 153 | 
 | 
|---|
| [551] | 154 |         env = getenv("FM3INI");
 | 
|---|
 | 155 |         if (env && *env) {
 | 
|---|
 | 156 |           DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 157 |           if (!DosQueryPathInfo(env, FIL_QUERYFULLNAME, path, sizeof(path))) {
 | 
|---|
 | 158 |             DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [873] | 159 |             if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
 | 
|---|
| [551] | 160 |               if (!(fs.attrFile & FILE_DIRECTORY)) {
 | 
|---|
 | 161 |                 env = strrchr(path, '\\');
 | 
|---|
 | 162 |                 if (env)
 | 
|---|
 | 163 |                   *env = 0;
 | 
|---|
 | 164 |               }
 | 
|---|
 | 165 |               DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [873] | 166 |               if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
 | 
|---|
| [551] | 167 |                 if (fs.attrFile & FILE_DIRECTORY)
 | 
|---|
 | 168 |                   switch_to(path);
 | 
|---|
 | 169 |               }
 | 
|---|
 | 170 |             }
 | 
|---|
 | 171 |           }
 | 
|---|
 | 172 |         }
 | 
|---|
| [2] | 173 |       }
 | 
|---|
| [551] | 174 |       if (InitFM3DLL(hab, argc, argv)) {
 | 
|---|
 | 175 |         if (CheckVersion(VERMAJOR, VERMINOR)) {
 | 
|---|
 | 176 |           fAmAV2 = TRUE;
 | 
|---|
 | 177 |           if (!*fullname) {
 | 
|---|
 | 178 |             strcpy(fullname, "*");
 | 
|---|
 | 179 |             if (!insert_filename(HWND_DESKTOP,
 | 
|---|
 | 180 |                                  fullname,
 | 
|---|
 | 181 |                                  TRUE,
 | 
|---|
 | 182 |                                  FALSE) || !*fullname || *fullname == '*')
 | 
|---|
 | 183 |               goto Abort;
 | 
|---|
 | 184 |           }
 | 
|---|
 | 185 |           if (*fullname) {
 | 
|---|
 | 186 |             if (ExecAssociation(HWND_DESKTOP, fullname) == -1) {
 | 
|---|
 | 187 |               hwndFrame = StartArcCnr(HWND_DESKTOP,
 | 
|---|
 | 188 |                                       (HWND) 0, fullname, 0, NULL);
 | 
|---|
 | 189 |               if (!hwndFrame) {
 | 
|---|
| [2] | 190 | 
 | 
|---|
| [551] | 191 |                 CHAR *p = strrchr(fullname, '.');
 | 
|---|
| [2] | 192 | 
 | 
|---|
| [551] | 193 |                 if (p) {
 | 
|---|
 | 194 |                   if (!stricmp(p, ".INI"))
 | 
|---|
 | 195 |                     hwndFrame = StartIniEditor(HWND_DESKTOP, fullname, 0);
 | 
|---|
 | 196 |                 }
 | 
|---|
 | 197 |                 if (!ShowMultimedia(fullname))
 | 
|---|
 | 198 |                   hwndFrame = StartMLEEditor(HWND_DESKTOP,
 | 
|---|
 | 199 |                                              1,
 | 
|---|
 | 200 |                                              ((*fullname) ?
 | 
|---|
 | 201 |                                               fullname : NULL), (HWND) 0);
 | 
|---|
 | 202 |               }
 | 
|---|
 | 203 |               if (hwndFrame && WinIsWindow(hab, hwndFrame)) {
 | 
|---|
 | 204 |                 if (hwndHelp)
 | 
|---|
 | 205 |                   WinAssociateHelpInstance(hwndHelp, hwndFrame);
 | 
|---|
 | 206 |                 for (;;) {
 | 
|---|
 | 207 |                   if (!WinGetMsg(hab, &qmsg, (HWND) 0, 0, 0)) {
 | 
|---|
 | 208 |                     if (!WinIsWindow(hab, hwndFrame))
 | 
|---|
 | 209 |                       break;
 | 
|---|
 | 210 |                     if (qmsg.hwnd)
 | 
|---|
 | 211 |                       qmsg.msg = WM_CLOSE;
 | 
|---|
 | 212 |                     else
 | 
|---|
 | 213 |                       break;
 | 
|---|
 | 214 |                   }
 | 
|---|
 | 215 |                   if (hwndBubble &&
 | 
|---|
 | 216 |                       ((qmsg.msg > (WM_BUTTON1DOWN - 1) &&
 | 
|---|
 | 217 |                         qmsg.msg < (WM_BUTTON3DBLCLK + 1)) ||
 | 
|---|
 | 218 |                        (qmsg.msg > (WM_CHORD - 1) &&
 | 
|---|
 | 219 |                         qmsg.msg < (WM_BUTTON3CLICK + 1))) &&
 | 
|---|
 | 220 |                       WinIsWindowVisible(hwndBubble))
 | 
|---|
 | 221 |                     WinShowWindow(hwndBubble, FALSE);
 | 
|---|
 | 222 |                   WinDispatchMsg(hab, &qmsg);
 | 
|---|
 | 223 |                 }
 | 
|---|
| [844] | 224 |                 DosSleep(125);
 | 
|---|
| [551] | 225 |               }
 | 
|---|
 | 226 |             }
 | 
|---|
 | 227 |           }
 | 
|---|
 | 228 |         }
 | 
|---|
| [2] | 229 |       }
 | 
|---|
| [551] | 230 |     Abort:
 | 
|---|
| [844] | 231 |       DosSleep(125);
 | 
|---|
| [2] | 232 |       WinDestroyMsgQueue(hmq);
 | 
|---|
 | 233 |     }
 | 
|---|
 | 234 |     WinTerminate(hab);
 | 
|---|
 | 235 |   }
 | 
|---|
 | 236 |   return 0;
 | 
|---|
 | 237 | }
 | 
|---|