source: trunk/av2.c@ 1155

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

Ticket 187: Draft 1: Functions only

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