1 |
|
---|
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
|
---|
9 | Copyright (c) 2007, 2008 Steven H. Levine
|
---|
10 |
|
---|
11 | 23 Sep 07 SHL Sync with standards
|
---|
12 | 23 Sep 07 SHL Get rid of statics
|
---|
13 | 17 Sep 08 JBS Convert to use of wrapped DosFind... (i.e. xDosFind...)
|
---|
14 |
|
---|
15 | ***********************************************************************/
|
---|
16 |
|
---|
17 | #include <stdlib.h>
|
---|
18 | #include <string.h>
|
---|
19 |
|
---|
20 | #define INCL_DOS
|
---|
21 | #define INCL_WIN
|
---|
22 | #define INCL_LONGLONG
|
---|
23 |
|
---|
24 | #include "dll\fm3dll.h"
|
---|
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"
|
---|
29 | #include "dll\fm3str.h"
|
---|
30 | #include "dll\version.h"
|
---|
31 | #include "dll\arccnrs.h"
|
---|
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
|
---|
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
|
---|
41 | #include "dll\wrappers.h" // xDosFind...
|
---|
42 |
|
---|
43 | HMTX av2Sem;
|
---|
44 |
|
---|
45 | VOID APIENTRY deinit(ULONG why)
|
---|
46 | {
|
---|
47 | /* cleanup before exiting */
|
---|
48 |
|
---|
49 | DosCloseMutexSem(av2Sem);
|
---|
50 | if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) {
|
---|
51 | CHAR s[CCHMAXPATH]; // 23 Sep 07 SHL
|
---|
52 | CHAR *enddir;
|
---|
53 | HDIR search_handle;
|
---|
54 | ULONG num_matches;
|
---|
55 | FILEFINDBUF3 ffb3;
|
---|
56 |
|
---|
57 | save_dir(s);
|
---|
58 | if (s[strlen(s) - 1] != '\\')
|
---|
59 | strcat(s, "\\");
|
---|
60 | enddir = &s[strlen(s)];
|
---|
61 | if (*ArcTempRoot) {
|
---|
62 | strcat(s, ArcTempRoot);
|
---|
63 | strcat(s, "*");
|
---|
64 | search_handle = HDIR_CREATE;
|
---|
65 | num_matches = 1;
|
---|
66 | if (!xDosFindFirst(s,
|
---|
67 | &search_handle,
|
---|
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)) {
|
---|
74 | do {
|
---|
75 | strcpy(enddir, ffb3.achName);
|
---|
76 | if (ffb3.attrFile & FILE_DIRECTORY) {
|
---|
77 | wipeallf("%s\\*", s);
|
---|
78 | DosDeleteDir(s);
|
---|
79 | }
|
---|
80 | else
|
---|
81 | unlinkf("%s", s);
|
---|
82 | } while (!xDosFindNext(search_handle,
|
---|
83 | &ffb3, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD));
|
---|
84 | DosFindClose(search_handle);
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 | else
|
---|
89 | DosCloseMutexSem(av2Sem);
|
---|
90 |
|
---|
91 | DosExitList(EXLST_REMOVE, deinit);
|
---|
92 | }
|
---|
93 |
|
---|
94 | int main(int argc, char *argv[])
|
---|
95 | {
|
---|
96 | HAB hab;
|
---|
97 | HMQ hmq;
|
---|
98 | QMSG qmsg;
|
---|
99 | HWND hwndFrame = (HWND) 0;
|
---|
100 | static CHAR fullname[CCHMAXPATH]; // 23 Sep 07 SHL fixme to not be static
|
---|
101 | CHAR *thisarg = NULL;
|
---|
102 | INT x;
|
---|
103 |
|
---|
104 | *fullname = 0;
|
---|
105 | strcpy(appname, "AV/2");
|
---|
106 | fAmAV2 = TRUE;
|
---|
107 | DosError(FERR_DISABLEHARDERR);
|
---|
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], '.')))) {
|
---|
114 | thisarg = argv[x];
|
---|
115 | break;
|
---|
116 | }
|
---|
117 | }
|
---|
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, '.'))) {
|
---|
127 |
|
---|
128 | FILEFINDBUF3 ffb3;
|
---|
129 | ULONG nm;
|
---|
130 | HDIR hdir;
|
---|
131 | CHAR *enddir;
|
---|
132 |
|
---|
133 | if (!strchr(fullname, '.'))
|
---|
134 | strcat(fullname, ".*");
|
---|
135 | enddir = strrchr(fullname, '\\');
|
---|
136 | if (enddir) {
|
---|
137 | enddir++;
|
---|
138 | hdir = HDIR_CREATE;
|
---|
139 | nm = 1;
|
---|
140 | if (!DosFindFirst(fullname,
|
---|
141 | &hdir,
|
---|
142 | FILE_NORMAL | FILE_SYSTEM |
|
---|
143 | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
|
---|
144 | &ffb3, sizeof(FILEFINDBUF3), &nm, FIL_STANDARD)) {
|
---|
145 | strcpy(enddir, ffb3.achName);
|
---|
146 | DosFindClose(hdir);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|
151 | hab = WinInitialize(0);
|
---|
152 | if (hab) {
|
---|
153 | hmq = WinCreateMsgQueue(hab, 1024);
|
---|
154 | if (hmq) {
|
---|
155 | {
|
---|
156 | CHAR path[CCHMAXPATH];
|
---|
157 | CHAR *env;
|
---|
158 | FILESTATUS3 fs;
|
---|
159 |
|
---|
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);
|
---|
165 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
|
---|
166 | if (!(fs.attrFile & FILE_DIRECTORY)) {
|
---|
167 | env = strrchr(path, '\\');
|
---|
168 | if (env)
|
---|
169 | *env = 0;
|
---|
170 | }
|
---|
171 | DosError(FERR_DISABLEHARDERR);
|
---|
172 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) {
|
---|
173 | if (fs.attrFile & FILE_DIRECTORY)
|
---|
174 | switch_to(path);
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
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) {
|
---|
196 |
|
---|
197 | CHAR *p = strrchr(fullname, '.');
|
---|
198 |
|
---|
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 | }
|
---|
230 | DosSleep(125);
|
---|
231 | }
|
---|
232 | }
|
---|
233 | }
|
---|
234 | }
|
---|
235 | }
|
---|
236 | Abort:
|
---|
237 | DosSleep(125);
|
---|
238 | WinDestroyMsgQueue(hmq);
|
---|
239 | }
|
---|
240 | WinTerminate(hab);
|
---|
241 | }
|
---|
242 | return 0;
|
---|
243 | }
|
---|