source: trunk/dll/defview.c@ 1484

Last change on this file since 1484 was 1484, checked in by Gregg Young, 16 years ago

Another attempt to fix the container updating issues in FM/2 lite; fixed a typo in defview.c

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: defview.c 1484 2009-12-13 20:16:07Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2003, 2008 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 18 Mar 07 GKY Fixed misindentifycation of nonmultimedia files by ShowMultiMedia
14 18 Mar 07 GKY Open mp3, ogg & flac files with OS2 object default since fm2play fails
15 21 Apr 07 GKY Find FM2Utils by path or utils directory
16 09 Jun 07 SHL ShowMultimedia: Initialize hwnd so that OpenObject might work
17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
18 20 Dec 07 GKY Open jpg files with OS2 object default since image.exe fails
19 29 Feb 08 GKY Refactor global command line variables to notebook.h
20 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
21 less than 10 KiB (It hangs and can't be closed)
22 05 Jan 09 GKY Use TestBinary so that text viewer isn't used for hex files by default
23 08 Mar 09 GKY Additional strings move to PCSZs
24 15 Nov 09 GKY Add check for attempt to open zero byte file and reorder file type checks
25 to place exes before MMPM check (avoids MMPM trying to play them)
26 15 Nov 09 GKY Work around MMIO's falure to identify MPG files as media
27 12 Dec 09 GKY Remove code that opened files to check if they were media types
28 It was redundant.
29 12 Dec 09 GKY Pass .WPI files to PM for default handling.
30
31***********************************************************************/
32
33#include <string.h>
34#include <ctype.h>
35
36#define INCL_DOS
37#define INCL_WIN
38#define INCL_GPI
39#define INCL_MMIOOS2
40#define INCL_LONGLONG // dircnrs.h
41#include <os2.h>
42#include <os2me.h>
43
44#include "fm3dll.h"
45#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
46#include "mainwnd2.h" // Data declaration(s)
47#include "init.h" // Data declaration(s)
48#include "fm3dlg.h"
49#include "arccnrs.h" // StartArcCnr
50#include "errutil.h" // Dos_Error...
51#include "notebook.h" // external viewers
52#include "defview.h"
53#include "info.h" // DrvInfoProc
54#include "assoc.h" // ExecAssociation
55#include "info.h" // FileInfoProc
56#include "valid.h" // IsExecutable
57#include "srchpath.h" // RunFM2Util
58#include "inis.h" // StartIniEditor
59#include "systemf.h" // ExecOnList
60#include "shadow.h" // OpenObject
61#include "viewer.h" // StartMLEEditor
62#include "newview.h" // StartViewer
63#include "mainwnd.h" // Data declaration(s)
64#include "misc.h" // ExecFile, ViewHelp
65
66// Data definitions
67static PSZ pszSrcFile = __FILE__;
68
69#pragma data_seg(GLOBAL2)
70PCSZ Default = "DEFAULT";
71
72/**
73 * ShowMultimedia uses MMOS2 if available to check if files are media types
74 * It will play them as media if they are. There are several work arounds
75 * to handle newer media types which are misidentified or which don't play
76 * in our default player/viewer
77 */
78
79BOOL ShowMultimedia(CHAR * filename)
80{
81
82 static BOOL no_mmos2 = FALSE;
83 BOOL played = FALSE;
84 CHAR loaderror[CCHMAXPATH];
85 HMODULE MMIOModHandle = NULLHANDLE;
86 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
87 FOURCC fccStorageSystem = 0;
88 MMFORMATINFO mmFormatInfo;
89 APIRET rc;
90 HWND hwnd = HWND_DESKTOP;
91 char *p;
92
93 if (no_mmos2 || !filename || !*filename)
94 return played;
95
96 //load MMPM/2, if available.
97 *loaderror = 0;
98 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
99 if (rc) {
100 no_mmos2 = TRUE;
101 return played;
102 }
103 else {
104 if (DosQueryProcAddr(MMIOModHandle,
105 0,
106 "mmioIdentifyFile", (PFN *) &pMMIOIdentifyFile)) {
107 DosFreeModule(MMIOModHandle);
108 no_mmos2 = TRUE;
109 return played;
110 }
111 }
112 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
113 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
114 rc = pMMIOIdentifyFile(filename, 0L, &mmFormatInfo,
115 &fccStorageSystem, 0L,
116 MMIO_FORCE_IDENTIFY_FF);
117 DosFreeModule(MMIOModHandle);
118 p = strrchr(filename, '.');
119 if (!p)
120 p = ".";
121 /* if identified and not FOURCC_DOS MPEGs are misidentified as DOS*/
122 //DbgMsg(pszSrcFile, __LINE__, "FOUCC %x %s %i", mmFormatInfo.fccIOProc,
123 // mmFormatInfo.szDefaultFormatExt, mmFormatInfo.ulMediaType);
124 if (!rc && (mmFormatInfo.fccIOProc != FOURCC_DOS ||
125 !stricmp(p, PCSZ_DOTMPG) || !stricmp(p, PCSZ_DOTMPEG))) {
126 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
127 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
128 if (!stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG))
129 OpenObject(filename, Default, hwnd); //Image fails to display these
130 else // is an image that can be translated
131 RunFM2Util(PCSZ_IMAGEEXE, filename);
132 played = TRUE;
133 }
134 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
135 /* is a multimedia file (WAV, MID, AVI, etc.) */
136 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC))
137 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
138 else
139 RunFM2Util(PCSZ_FM2PLAYEXE, filename);
140 played = TRUE;
141 }
142 }
143
144 return played;
145}
146
147VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
148 SWP * swp, CHAR * filename)
149{
150 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
151 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
152 else if (shiftstate & KC_CTRL)
153 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
154 else if (shiftstate & KC_SHIFT)
155 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
156 else
157 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
158}
159
160/**
161 * DefaultView runs multiple checks for opening files including checking
162 * for associations, archives, executables, help, ini, warpin, multimedia and
163 * viewing as binary or text.
164 */
165
166VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
167 ULONG flags, CHAR * filename)
168{
169 /*
170 * bitmapped flags:
171 * ---------------
172 * 1 = View directly
173 * 2 = Open WPS default view
174 * 4 = Open WPS settings view
175 * 8 = Edit
176 * 16 = Info
177 * 32 = No view info
178 */
179
180 HWND hwndArc = (HWND) 0;
181 char *p, *dummy[3];
182
183 if (!hwndParent)
184 hwndParent = HWND_DESKTOP;
185
186 if (flags & 32) {
187 flags &= (~16);
188 if (!IsFile(filename)) {
189 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
190 return;
191 }
192 }
193
194 if (flags & 1) /* directly view the file */
195 goto ViewIt;
196
197 if (flags & 2) { /* open default WPS view of file */
198 OpenObject(filename, Default, hwnd);
199 return;
200 }
201
202 if (flags & 4) { /* open WPS settings notebook for file */
203 OpenObject(filename, Settings, hwnd);
204 return;
205 }
206
207 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
208
209 char fullname[CCHMAXPATH];
210
211 if (!IsFullName(filename)) {
212 if (!DosQueryPathInfo(filename,
213 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
214 filename = fullname;
215 }
216 if (IsFullName(filename) &&
217 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
218 if (!IsRoot(filename)) {
219 dummy[0] = filename;
220 dummy[1] = NULL;
221 WinDlgBox(HWND_DESKTOP,
222 HWND_DESKTOP,
223 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
224 }
225 else
226 WinDlgBox(HWND_DESKTOP,
227 HWND_DESKTOP,
228 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
229 }
230 return;
231 }
232
233 if (flags & 8) { /* edit file */
234
235 ULONG type = IDM_EDITTEXT;
236
237 dummy[0] = filename;
238 dummy[1] = NULL;
239 if (TestBinary(filename))
240 type = IDM_EDITBINARY;
241 switch (type) {
242 case IDM_EDITBINARY:
243 if (*bined) {
244 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
245 pszSrcFile, __LINE__);
246 break;
247 }
248 /* else intentional fallthru */
249 case IDM_EDITTEXT:
250 if (*editor)
251 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
252 pszSrcFile, __LINE__);
253 else {
254 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
255 type |= 4;
256 StartMLEEditor(hwndParent, type, filename, hwndFrame);
257 }
258 break;
259 }
260 return;
261 }
262
263 if (ExecAssociation(hwnd, filename) == -1 &&
264 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
265 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
266 strcmp(realappname, FM3Str)) ?
267 HWND_DESKTOP :
268 hwndParent, hwndFrame, filename, 4, NULL);
269 if (!hwndArc) {
270 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
271 p = strrchr(filename, '.');
272 if (!p)
273 p = ".";
274 if (!stricmp(p, ".WPI")) {
275 OpenObject(filename, Default, hwnd);
276 return;
277 }
278 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
279 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
280 if (!fCheckMM || !ShowMultimedia(filename)) {
281 ViewIt:
282 if (TestBinary(filename)) {
283 if (*binview) {
284 dummy[0] = filename;
285 dummy[1] = NULL;
286 ExecOnList(hwnd,
287 binview,
288 WINDOWED | SEPARATE |
289 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
290 pszSrcFile, __LINE__);
291 }
292 else if (fUseNewViewer) {
293 if (fExternalViewer || strcmp(realappname, FM3Str))
294 hwndParent = HWND_DESKTOP;
295 StartViewer(hwndParent, 5, filename, hwndFrame);
296 }
297 else
298 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
299 }
300 else {
301 if (*viewer) {
302 dummy[0] = filename;
303 dummy[1] = NULL;
304 ExecOnList(hwnd,
305 viewer,
306 WINDOWED | SEPARATE |
307 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
308 pszSrcFile, __LINE__);
309 }
310 else if (fUseNewViewer) {
311 if (fExternalViewer || strcmp(realappname, FM3Str))
312 hwndParent = HWND_DESKTOP;
313 StartViewer(hwndParent, 5, filename, hwndFrame);
314 }
315 else
316 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
317 }
318 }
319 }
320 }
321 }
322 }
323 else {
324 if ((swp &&
325 !fExternalArcboxes &&
326 !strcmp(realappname, FM3Str)) &&
327 !ParentIsDesktop(hwnd, hwndParent))
328 WinSetWindowPos(hwndArc,
329 HWND_TOP,
330 swp->x,
331 swp->y,
332 swp->cx,
333 swp->cy,
334 SWP_MOVE | SWP_SIZE | SWP_SHOW |
335 SWP_ZORDER | SWP_ACTIVATE);
336 }
337 }
338}
339
340#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.