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