source: trunk/av2.c@ 1176

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

Ticket 187: Draft 2: Move remaining function declarations

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