1 |
|
---|
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 |
|
---|
16 | #include <stdarg.h>
|
---|
17 | #include <stdio.h>
|
---|
18 | #include <stdlib.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <ctype.h>
|
---|
21 |
|
---|
22 | #define INCL_DOS
|
---|
23 | #define INCL_WIN
|
---|
24 | #include <os2.h>
|
---|
25 |
|
---|
26 | #include "dll\fm3dll.h"
|
---|
27 | #include "dll\version.h"
|
---|
28 | #include "dll\fm3str.h"
|
---|
29 |
|
---|
30 | HMTX av2Sem;
|
---|
31 |
|
---|
32 | VOID APIENTRY deinit(ULONG why)
|
---|
33 | {
|
---|
34 | /* cleanup before exiting */
|
---|
35 |
|
---|
36 | DosCloseMutexSem(av2Sem);
|
---|
37 | if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) {
|
---|
38 | CHAR s[CCHMAXPATH]; // 23 Sep 07 SHL
|
---|
39 | CHAR *enddir;
|
---|
40 | HDIR search_handle;
|
---|
41 | ULONG num_matches;
|
---|
42 | FILEFINDBUF3 ffb3;
|
---|
43 |
|
---|
44 | save_dir(s);
|
---|
45 | if (s[strlen(s) - 1] != '\\')
|
---|
46 | strcat(s, "\\");
|
---|
47 | enddir = &s[strlen(s)];
|
---|
48 | if (*ArcTempRoot) {
|
---|
49 | strcat(s, ArcTempRoot);
|
---|
50 | strcat(s, "*");
|
---|
51 | search_handle = HDIR_CREATE;
|
---|
52 | num_matches = 1;
|
---|
53 | if (!DosFindFirst(s,
|
---|
54 | &search_handle,
|
---|
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)) {
|
---|
61 | do {
|
---|
62 | strcpy(enddir, ffb3.achName);
|
---|
63 | if (ffb3.attrFile & FILE_DIRECTORY) {
|
---|
64 | wipeallf("%s\\*", s);
|
---|
65 | DosDeleteDir(s);
|
---|
66 | }
|
---|
67 | else
|
---|
68 | unlinkf("%s", s);
|
---|
69 | } while (!DosFindNext(search_handle,
|
---|
70 | &ffb3, sizeof(FILEFINDBUF3), &num_matches));
|
---|
71 | DosFindClose(search_handle);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | else
|
---|
76 | DosCloseMutexSem(av2Sem);
|
---|
77 |
|
---|
78 | DosExitList(EXLST_REMOVE, deinit);
|
---|
79 | }
|
---|
80 |
|
---|
81 | int main(int argc, char *argv[])
|
---|
82 | {
|
---|
83 | HAB hab;
|
---|
84 | HMQ hmq;
|
---|
85 | QMSG qmsg;
|
---|
86 | HWND hwndFrame = (HWND) 0;
|
---|
87 | static CHAR fullname[CCHMAXPATH]; // 23 Sep 07 SHL fixme to not be static
|
---|
88 | CHAR *thisarg = NULL;
|
---|
89 | INT x;
|
---|
90 |
|
---|
91 | *fullname = 0;
|
---|
92 | strcpy(appname, "AV/2");
|
---|
93 | fAmAV2 = TRUE;
|
---|
94 | DosError(FERR_DISABLEHARDERR);
|
---|
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], '.')))) {
|
---|
101 | thisarg = argv[x];
|
---|
102 | break;
|
---|
103 | }
|
---|
104 | }
|
---|
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, '.'))) {
|
---|
114 |
|
---|
115 | FILEFINDBUF3 ffb3;
|
---|
116 | ULONG nm;
|
---|
117 | HDIR hdir;
|
---|
118 | CHAR *enddir;
|
---|
119 |
|
---|
120 | if (!strchr(fullname, '.'))
|
---|
121 | strcat(fullname, ".*");
|
---|
122 | enddir = strrchr(fullname, '\\');
|
---|
123 | if (enddir) {
|
---|
124 | enddir++;
|
---|
125 | hdir = HDIR_CREATE;
|
---|
126 | nm = 1;
|
---|
127 | if (!DosFindFirst(fullname,
|
---|
128 | &hdir,
|
---|
129 | FILE_NORMAL | FILE_SYSTEM |
|
---|
130 | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
|
---|
131 | &ffb3, sizeof(FILEFINDBUF3), &nm, FIL_STANDARD)) {
|
---|
132 | strcpy(enddir, ffb3.achName);
|
---|
133 | DosFindClose(hdir);
|
---|
134 | }
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 | hab = WinInitialize(0);
|
---|
139 | if (hab) {
|
---|
140 | hmq = WinCreateMsgQueue(hab, 1024);
|
---|
141 | if (hmq) {
|
---|
142 | {
|
---|
143 | CHAR path[CCHMAXPATH];
|
---|
144 | CHAR *env;
|
---|
145 | FILESTATUS3 fs;
|
---|
146 |
|
---|
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);
|
---|
152 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
|
---|
153 | if (!(fs.attrFile & FILE_DIRECTORY)) {
|
---|
154 | env = strrchr(path, '\\');
|
---|
155 | if (env)
|
---|
156 | *env = 0;
|
---|
157 | }
|
---|
158 | DosError(FERR_DISABLEHARDERR);
|
---|
159 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
|
---|
160 | if (fs.attrFile & FILE_DIRECTORY)
|
---|
161 | switch_to(path);
|
---|
162 | }
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|
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) {
|
---|
183 |
|
---|
184 | CHAR *p = strrchr(fullname, '.');
|
---|
185 |
|
---|
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 | }
|
---|
217 | DosSleep(125);
|
---|
218 | }
|
---|
219 | }
|
---|
220 | }
|
---|
221 | }
|
---|
222 | }
|
---|
223 | Abort:
|
---|
224 | DosSleep(125);
|
---|
225 | WinDestroyMsgQueue(hmq);
|
---|
226 | }
|
---|
227 | WinTerminate(hab);
|
---|
228 | }
|
---|
229 | return 0;
|
---|
230 | }
|
---|