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