source: trunk/dll/defview.c@ 1780

Last change on this file since 1780 was 1780, checked in by Gregg Young, 11 years ago

Fixed errors found by cppcheck. Most had the potential to cause difficult to reproduce traps. Also fixed retry code for failure to create an archive work directory and the failure of the mailto code to drop trailing >.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: defview.c 1780 2014-06-28 18:05:22Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2003, 2012 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 02 Jan 12 GKY Completely rework ShowMultimedia to only test and try to open files with known multimedia extensions
31 This fixes some traps in GBM.DLL and PMCTLS.DLL; mmioIdentifyFile appears to pretty much be broken.
32 28 Jun 14 GKY Fix errors identified with CPPCheck
33
34***********************************************************************/
35
36#include <string.h>
37#include <ctype.h>
38
39#define INCL_DOS
40#define INCL_WIN
41#define INCL_GPI
42#define INCL_MMIOOS2
43#define INCL_LONGLONG // dircnrs.h
44#include <os2.h>
45#include <os2me.h>
46
47#include "fm3dll.h"
48#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
49#include "mainwnd2.h" // Data declaration(s)
50#include "init.h" // Data declaration(s)
51#include "fm3dlg.h"
52#include "arccnrs.h" // StartArcCnr
53#include "errutil.h" // Dos_Error...
54#include "notebook.h" // external viewers
55#include "defview.h"
56#include "info.h" // DrvInfoProc
57#include "assoc.h" // ExecAssociation
58#include "info.h" // FileInfoProc
59#include "valid.h" // IsExecutable
60#include "srchpath.h" // RunFM2Util
61#include "inis.h" // StartIniEditor
62#include "systemf.h" // ExecOnList
63#include "shadow.h" // OpenObject
64#include "viewer.h" // StartMLEEditor
65#include "newview.h" // StartViewer
66#include "mainwnd.h" // Data declaration(s)
67#include "misc.h" // ExecFile, ViewHelp
68
69// Data definitions
70static PSZ pszSrcFile = __FILE__;
71
72#pragma data_seg(GLOBAL2)
73PCSZ Default = "DEFAULT";
74
75/**
76 * ShowMultimedia uses MMOS2 if available to check if files are media types
77 * It will play them as media if they are. There are several work arounds
78 * to handle newer media types which are misidentified or which don't play
79 * in our default player/viewer
80 */
81
82BOOL ShowMultimedia(CHAR * filename)
83{
84
85 static BOOL no_mmos2 = FALSE;
86 BOOL played = FALSE;
87 CHAR loaderror[CCHMAXPATH];
88 HMODULE MMIOModHandle = NULLHANDLE;
89 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
90 FOURCC fccStorageSystem = 0;
91 MMFORMATINFO mmFormatInfo;
92 APIRET rc;
93 HWND hwnd = HWND_DESKTOP;
94 char *p;
95
96 if (no_mmos2 || !filename || !*filename)
97 return played;
98
99 //load MMPM/2, if available.
100 *loaderror = 0;
101 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
102 if (rc) {
103 no_mmos2 = TRUE;
104 return played;
105 }
106 else {
107 ULONG cmp;
108 CHAR cmps[6];
109
110 p = strrchr(filename, '.');
111 if (p) {
112 cmps[0] = '.';
113 cmps[1] = toupper(p[1]);
114 cmps[2] = toupper(p[2]);
115 cmps[3] = toupper(p[3]);
116 if (p[4]) {
117 cmps[4] = toupper(p[4]);
118 cmps[5] = 0;
119 }
120 else
121 cmps[4] = 0;
122
123 cmp = *(ULONG *) cmps;
124 if (cmp == *(ULONG *) PCSZ_DOTBMP || cmp == *(ULONG *) PCSZ_DOTJPEG ||
125 cmp == *(ULONG *) PCSZ_DOTMP3 || cmp == *(ULONG *) PCSZ_DOTJPG ||
126 cmp == *(ULONG *) PCSZ_DOTMPEG || cmp == *(ULONG *) PCSZ_DOTFLAC ||
127 cmp == *(ULONG *) ".TIF" || cmp == *(ULONG *) ".PCX" ||
128 cmp == *(ULONG *) ".TGA" || cmp == *(ULONG *) ".MOV" ||
129 cmp == *(ULONG *) ".PNG" || cmp == *(ULONG *) ".AVI" ||
130 cmp == *(ULONG *) ".OGG" || cmp == *(ULONG *) ".MID" ||
131 cmp == *(ULONG *) ".PCD" || cmp == *(ULONG *) ".FLC" ||
132 cmp == *(ULONG *) ".GIF" || cmp == *(ULONG *) ".FLA" ||
133 cmp == *(ULONG *) ".IFF" || cmp == *(ULONG *) ".SND" ||
134 cmp == *(ULONG *) "._AU" || cmp == *(ULONG *) ".AIF" ||
135 cmp == *(ULONG *) ".VID" || cmp == *(ULONG *) ".WAV" ||
136 cmp == *(ULONG *) "._IM" || cmp == *(ULONG *) ".RDI" ||
137 cmp == *(ULONG *) PCSZ_DOTMPG) {
138 if (DosQueryProcAddr(MMIOModHandle, 0,
139 "mmioIdentifyFile", (PFN *) &pMMIOIdentifyFile)) {
140 DosFreeModule(MMIOModHandle);
141 no_mmos2 = TRUE;
142 return played;
143 }
144 }
145 else
146 return played;
147 }
148 else
149 return played;
150 }
151 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
152 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
153 rc = pMMIOIdentifyFile(filename, 0L, &mmFormatInfo,
154 &fccStorageSystem, 0L,
155 MMIO_FORCE_IDENTIFY_FF);
156 DosFreeModule(MMIOModHandle);
157
158 // if identified and not FOURCC_DOS MPEGs are misidentified as DOS
159 //DbgMsg(pszSrcFile, __LINE__, "FOUCC %x %s %i", mmFormatInfo.fccIOProc,
160 // mmFormatInfo.szDefaultFormatExt, mmFormatInfo.ulMediaType);
161 if (!rc && (mmFormatInfo.fccIOProc != FOURCC_DOS ||
162 !stricmp(p, PCSZ_DOTMPG) || !stricmp(p, PCSZ_DOTMPEG))) {
163 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
164 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
165 //if (!stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG))
166 OpenObject(filename, Default, hwnd); //Image fails to display these
167 // else // is an image that can be translated
168 // RunFM2Util(PCSZ_IMAGEEXE, filename); // 29 Oct 11 GKY Image.exe doesn't handle multilayer bitmaps or jpgs
169 played = TRUE;
170 }
171 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
172 // is a multimedia file (WAV, MID, AVI, etc.)
173 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC))
174 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
175 else
176 RunFM2Util(PCSZ_FM2PLAYEXE, filename);
177 played = TRUE;
178 }
179 }
180
181 return played;
182}
183
184VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
185 SWP * swp, CHAR * filename)
186{
187 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
188 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
189 else if (shiftstate & KC_CTRL)
190 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
191 else if (shiftstate & KC_SHIFT)
192 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
193 else
194 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
195}
196
197/**
198 * DefaultView runs multiple checks for opening files including checking
199 * for associations, archives, executables, help, ini, warpin, multimedia and
200 * viewing as binary or text.
201 */
202
203VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
204 ULONG flags, CHAR * filename)
205{
206 /**
207 * bitmapped flags:
208 * ---------------
209 * 1 = View directly
210 * 2 = Open WPS default view
211 * 4 = Open WPS settings view
212 * 8 = Edit
213 * 16 = Info
214 * 32 = No view info
215 */
216
217 HWND hwndArc = (HWND) 0;
218 char *p, *dummy[3];
219
220 if (!hwndParent)
221 hwndParent = HWND_DESKTOP;
222
223 if (flags & 32) {
224 flags &= (~16);
225 if (!IsFile(filename)) {
226 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
227 return;
228 }
229 }
230
231 if (flags & 1) // directly view the file
232 goto ViewIt;
233
234 if (flags & 2) { // open default WPS view of file
235 OpenObject(filename, Default, hwnd);
236 return;
237 }
238
239 if (flags & 4) { // open WPS settings notebook for file
240 OpenObject(filename, Settings, hwnd);
241 return;
242 }
243
244 if ((flags & 16) || !IsFile(filename)) { // open info for directories
245
246 char fullname[CCHMAXPATH];
247
248 if (!IsFullName(filename)) {
249 if (!DosQueryPathInfo(filename,
250 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
251 filename = fullname;
252 }
253 if (IsFullName(filename) &&
254 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
255 if (!IsRoot(filename)) {
256 dummy[0] = filename;
257 dummy[1] = NULL;
258 WinDlgBox(HWND_DESKTOP,
259 HWND_DESKTOP,
260 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
261 }
262 else
263 WinDlgBox(HWND_DESKTOP,
264 HWND_DESKTOP,
265 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
266 }
267 return;
268 }
269
270 if (flags & 8) { // edit file
271
272 ULONG type = IDM_EDITTEXT;
273
274 dummy[0] = filename;
275 dummy[1] = NULL;
276 if (TestBinary(filename))
277 type = IDM_EDITBINARY;
278 switch (type) {
279 case IDM_EDITBINARY:
280 if (*bined) {
281 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
282 pszSrcFile, __LINE__);
283 break;
284 }
285 // else intentional fallthru
286 case IDM_EDITTEXT:
287 if (*editor)
288 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
289 pszSrcFile, __LINE__);
290 else {
291 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
292 type |= 4;
293 StartMLEEditor(hwndParent, type, filename, hwndFrame);
294 }
295 break;
296 }
297 return;
298 }
299
300 if (ExecAssociation(hwnd, filename) == -1 &&
301 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
302 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
303 strcmp(realappname, FM3Str)) ?
304 HWND_DESKTOP :
305 hwndParent, hwndFrame, filename, 4, NULL);
306 if (!hwndArc) {
307 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
308 p = strrchr(filename, '.');
309 if (!p)
310 p = ".";
311 if (!stricmp(p, ".WPI")) {
312 OpenObject(filename, Default, hwnd);
313 return;
314 }
315 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
316 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
317 ViewIt:
318 if (TestBinary(filename)) {
319 if (!fCheckMM || !ShowMultimedia(filename)) {
320 if (*binview) {
321 dummy[0] = filename;
322 dummy[1] = NULL;
323 ExecOnList(hwnd,
324 binview,
325 WINDOWED | SEPARATE |
326 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
327 pszSrcFile, __LINE__);
328 }
329 else if (fUseNewViewer) {
330 if (fExternalViewer || strcmp(realappname, FM3Str))
331 hwndParent = HWND_DESKTOP;
332 StartViewer(hwndParent, 5, filename, hwndFrame);
333 }
334 else
335 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
336 }
337 }
338 else {
339 if (*viewer) {
340 dummy[0] = filename;
341 dummy[1] = NULL;
342 ExecOnList(hwnd,
343 viewer,
344 WINDOWED | SEPARATE |
345 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
346 pszSrcFile, __LINE__);
347 }
348 else if (fUseNewViewer) {
349 if (fExternalViewer || strcmp(realappname, FM3Str))
350 hwndParent = HWND_DESKTOP;
351 StartViewer(hwndParent, 5, filename, hwndFrame);
352 }
353 else
354 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
355 }
356 //}
357 }
358 }
359 }
360 }
361 else {
362 if ((swp &&
363 !fExternalArcboxes &&
364 !strcmp(realappname, FM3Str)) &&
365 !ParentIsDesktop(hwnd, hwndParent))
366 WinSetWindowPos(hwndArc,
367 HWND_TOP,
368 swp->x,
369 swp->y,
370 swp->cx,
371 swp->cy,
372 SWP_MOVE | SWP_SIZE | SWP_SHOW |
373 SWP_ZORDER | SWP_ACTIVATE);
374 }
375 }
376}
377
378#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.