source: trunk/av2.c@ 1203

Last change on this file since 1203 was 1203, checked in by John Small, 17 years ago

Ticket 187: Move datadevlarations/definitions out of fm3dll.h

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