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