1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: defview.c 551 2007-02-28 01:33:51Z gyoung $
|
---|
5 |
|
---|
6 | Copyright (c) 1993-98 M. Kimes
|
---|
7 | Copyright (c) 2003, 2006 Steven H.Levine
|
---|
8 |
|
---|
9 | Default file viewer
|
---|
10 |
|
---|
11 | 20 Nov 03 SHL ShowMultimedia: try to convince fmplay to not play exes (Gregg Young)
|
---|
12 | 14 Jul 06 SHL Use Runtime_Error
|
---|
13 |
|
---|
14 | ***********************************************************************/
|
---|
15 |
|
---|
16 | #define INCL_DOS
|
---|
17 | #define INCL_WIN
|
---|
18 | #define INCL_GPI
|
---|
19 | #define INCL_MMIOOS2
|
---|
20 | #include <os2.h>
|
---|
21 | #include <os2me.h>
|
---|
22 |
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <string.h>
|
---|
26 | #include <ctype.h>
|
---|
27 |
|
---|
28 | #include "fm3dll.h"
|
---|
29 | #include "fm3dlg.h"
|
---|
30 |
|
---|
31 | static PSZ pszSrcFile = __FILE__;
|
---|
32 |
|
---|
33 | #pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
|
---|
34 |
|
---|
35 | BOOL ShowMultimedia(CHAR * filename)
|
---|
36 | {
|
---|
37 |
|
---|
38 | static BOOL no_mmos2 = FALSE;
|
---|
39 | BOOL played = FALSE;
|
---|
40 | CHAR loaderror[CCHMAXPATH];
|
---|
41 | HMODULE MMIOModHandle = NULLHANDLE;
|
---|
42 | PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
|
---|
43 | FOURCC fccStorageSystem = 0;
|
---|
44 | MMFORMATINFO mmFormatInfo;
|
---|
45 | APIRET rc;
|
---|
46 |
|
---|
47 | if (no_mmos2 || !filename || !*filename)
|
---|
48 | return played;
|
---|
49 |
|
---|
50 | /* load MMPM/2, if available. */
|
---|
51 | *loaderror = 0;
|
---|
52 | rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
|
---|
53 | if (rc) {
|
---|
54 | no_mmos2 = TRUE;
|
---|
55 | return played;
|
---|
56 | }
|
---|
57 | else {
|
---|
58 | if (DosQueryProcAddr(MMIOModHandle,
|
---|
59 | 0,
|
---|
60 | "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
|
---|
61 | DosFreeModule(MMIOModHandle);
|
---|
62 | no_mmos2 = TRUE;
|
---|
63 | return played;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | /* attempt to identify the file using MMPM/2 */
|
---|
68 | memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
|
---|
69 | mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
|
---|
70 | rc = pMMIOIdentifyFile(filename,
|
---|
71 | 0L,
|
---|
72 | &mmFormatInfo,
|
---|
73 | &fccStorageSystem, 0L, MMIO_FORCE_IDENTIFY_FF);
|
---|
74 | /* free module handle */
|
---|
75 | DosFreeModule(MMIOModHandle);
|
---|
76 |
|
---|
77 | /* if identified and not FOURCC_DOS */
|
---|
78 | if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
|
---|
79 | if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
|
---|
80 | (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
|
---|
81 | /* is an image that can be translated */
|
---|
82 | runemf2(SEPARATE | WINDOWED,
|
---|
83 | HWND_DESKTOP,
|
---|
84 | NULL,
|
---|
85 | NULL,
|
---|
86 | "%sIMAGE.EXE \"%s\"",
|
---|
87 | (fAddUtils) ? "UTILS\\" : NullStr, filename);
|
---|
88 | played = TRUE;
|
---|
89 | }
|
---|
90 | else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
|
---|
91 | /* is a multimedia file (WAV, MID, AVI, etc.) */
|
---|
92 | runemf2(SEPARATE | WINDOWED,
|
---|
93 | HWND_DESKTOP,
|
---|
94 | NULL,
|
---|
95 | NULL,
|
---|
96 | "%sFM2PLAY.EXE \"%s\"",
|
---|
97 | (fAddUtils) ? "UTILS\\" : NullStr, filename);
|
---|
98 | played = TRUE;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | return played;
|
---|
103 | }
|
---|
104 |
|
---|
105 | VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
|
---|
106 | SWP * swp, CHAR * filename)
|
---|
107 | {
|
---|
108 | if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
|
---|
109 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
|
---|
110 | else if (shiftstate & KC_CTRL)
|
---|
111 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
|
---|
112 | else if (shiftstate & KC_SHIFT)
|
---|
113 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
|
---|
114 | else
|
---|
115 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
|
---|
116 | }
|
---|
117 |
|
---|
118 | VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
|
---|
119 | ULONG flags, CHAR * filename)
|
---|
120 | {
|
---|
121 | /*
|
---|
122 | * bitmapped flags:
|
---|
123 | * ---------------
|
---|
124 | * 1 = View directly
|
---|
125 | * 2 = Open WPS default view
|
---|
126 | * 4 = Open WPS settings view
|
---|
127 | * 8 = Edit
|
---|
128 | * 16 = Info
|
---|
129 | * 32 = No view info
|
---|
130 | */
|
---|
131 |
|
---|
132 | HWND hwndArc = (HWND) 0;
|
---|
133 | char *p, *dummy[3];
|
---|
134 |
|
---|
135 | if (!hwndParent)
|
---|
136 | hwndParent = HWND_DESKTOP;
|
---|
137 |
|
---|
138 | if (flags & 32) {
|
---|
139 | flags &= (~16);
|
---|
140 | if (!IsFile(filename)) {
|
---|
141 | Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
|
---|
142 | return;
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | if (flags & 1) /* directly view the file */
|
---|
147 | goto ViewIt;
|
---|
148 |
|
---|
149 | if (flags & 2) { /* open default WPS view of file */
|
---|
150 | OpenObject(filename, Default, hwnd);
|
---|
151 | return;
|
---|
152 | }
|
---|
153 |
|
---|
154 | if (flags & 4) { /* open WPS settings notebook for file */
|
---|
155 | OpenObject(filename, Settings, hwnd);
|
---|
156 | return;
|
---|
157 | }
|
---|
158 |
|
---|
159 | if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
|
---|
160 |
|
---|
161 | char fullname[CCHMAXPATH];
|
---|
162 |
|
---|
163 | if (!IsFullName(filename)) {
|
---|
164 | if (!DosQueryPathInfo(filename,
|
---|
165 | FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
|
---|
166 | filename = fullname;
|
---|
167 | }
|
---|
168 | if (IsFullName(filename) &&
|
---|
169 | !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
|
---|
170 | if (!IsRoot(filename)) {
|
---|
171 | dummy[0] = filename;
|
---|
172 | dummy[1] = NULL;
|
---|
173 | WinDlgBox(HWND_DESKTOP,
|
---|
174 | HWND_DESKTOP,
|
---|
175 | FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
|
---|
176 | }
|
---|
177 | else
|
---|
178 | WinDlgBox(HWND_DESKTOP,
|
---|
179 | HWND_DESKTOP,
|
---|
180 | DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
|
---|
181 | }
|
---|
182 | return;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (flags & 8) { /* edit file */
|
---|
186 |
|
---|
187 | ULONG type = IDM_EDITTEXT;
|
---|
188 |
|
---|
189 | dummy[0] = filename;
|
---|
190 | dummy[1] = NULL;
|
---|
191 | if (TestBinary(filename))
|
---|
192 | type = IDM_EDITBINARY;
|
---|
193 | switch (type) {
|
---|
194 | case IDM_EDITBINARY:
|
---|
195 | if (*bined) {
|
---|
196 | ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL);
|
---|
197 | break;
|
---|
198 | }
|
---|
199 | /* else intentional fallthru */
|
---|
200 | case IDM_EDITTEXT:
|
---|
201 | if (*editor)
|
---|
202 | ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL);
|
---|
203 | else {
|
---|
204 | type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
|
---|
205 | type |= 4;
|
---|
206 | StartMLEEditor(hwndParent, type, filename, hwndFrame);
|
---|
207 | }
|
---|
208 | break;
|
---|
209 | }
|
---|
210 | return;
|
---|
211 | }
|
---|
212 |
|
---|
213 | if (ExecAssociation(hwnd, filename) == -1) {
|
---|
214 | hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
|
---|
215 | strcmp(realappname, FM3Str)) ?
|
---|
216 | HWND_DESKTOP :
|
---|
217 | hwndParent, hwndFrame, filename, 4, NULL);
|
---|
218 | if (!hwndArc) {
|
---|
219 | if (!fCheckMM || !ShowMultimedia(filename)) {
|
---|
220 | if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
|
---|
221 | p = strrchr(filename, '.');
|
---|
222 | if (!p)
|
---|
223 | p = ".";
|
---|
224 | if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
|
---|
225 | if (stricmp(p, ".HLP") || !ViewHelp(filename)) {
|
---|
226 | ViewIt:
|
---|
227 | if (*viewer) {
|
---|
228 | dummy[0] = filename;
|
---|
229 | dummy[1] = NULL;
|
---|
230 | ExecOnList(hwnd,
|
---|
231 | viewer,
|
---|
232 | WINDOWED | SEPARATE |
|
---|
233 | ((fViewChild) ? CHILD : 0), NULL, dummy, NULL);
|
---|
234 | }
|
---|
235 | else
|
---|
236 | StartMLEEditor(hwndParent, 5, filename, hwndFrame);
|
---|
237 | }
|
---|
238 | }
|
---|
239 | }
|
---|
240 | }
|
---|
241 | }
|
---|
242 | else {
|
---|
243 | if ((swp &&
|
---|
244 | !fExternalArcboxes &&
|
---|
245 | !strcmp(realappname, FM3Str)) &&
|
---|
246 | !ParentIsDesktop(hwnd, hwndParent))
|
---|
247 | WinSetWindowPos(hwndArc,
|
---|
248 | HWND_TOP,
|
---|
249 | swp->x,
|
---|
250 | swp->y,
|
---|
251 | swp->cx,
|
---|
252 | swp->cy,
|
---|
253 | SWP_MOVE | SWP_SIZE | SWP_SHOW |
|
---|
254 | SWP_ZORDER | SWP_ACTIVATE);
|
---|
255 | }
|
---|
256 | }
|
---|
257 | }
|
---|