source: trunk/dll/defview.c@ 1402

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

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: defview.c 1402 2009-03-14 17:17:59Z 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 veiwer isn't used for hex files by default
23 08 Mar 09 GKY Additional strings move to PCSZs
24
25***********************************************************************/
26
27#include <string.h>
28#include <ctype.h>
29
30#define INCL_DOS
31#define INCL_WIN
32#define INCL_GPI
33#define INCL_MMIOOS2
34#define INCL_LONGLONG // dircnrs.h
35#include <os2.h>
36#include <os2me.h>
37
38#include "fm3dll.h"
39#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
40#include "mainwnd2.h" // Data declaration(s)
41#include "init.h" // Data declaration(s)
42#include "fm3dlg.h"
43#include "arccnrs.h" // StartArcCnr
44#include "errutil.h" // Dos_Error...
45#include "notebook.h" // external viewers
46#include "defview.h"
47#include "info.h" // DrvInfoProc
48#include "assoc.h" // ExecAssociation
49#include "info.h" // FileInfoProc
50#include "valid.h" // IsExecutable
51#include "srchpath.h" // RunFM2Util
52#include "inis.h" // StartIniEditor
53#include "systemf.h" // ExecOnList
54#include "shadow.h" // OpenObject
55#include "viewer.h" // StartMLEEditor
56#include "newview.h" // StartViewer
57#include "mainwnd.h" // Data declaration(s)
58#include "misc.h" // ExecFile, ViewHelp
59
60// Data definitions
61static PSZ pszSrcFile = __FILE__;
62
63#pragma data_seg(GLOBAL2)
64PCSZ Default = "DEFAULT";
65
66BOOL ShowMultimedia(CHAR * filename)
67{
68
69 static BOOL no_mmos2 = FALSE;
70 BOOL played = FALSE;
71 CHAR loaderror[CCHMAXPATH];
72 HMODULE MMIOModHandle = NULLHANDLE;
73 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
74 PMMIOGETINFO pMMIOGetInfo = NULL;
75 PMMIOCLOSE pMMIOClose = NULL;
76 PMMIOOPEN pMMIOOpen = NULL;
77 MMIOINFO mmioinfo;
78 HMMIO hmmio;
79 FOURCC fccStorageSystem = 0;
80 MMFORMATINFO mmFormatInfo;
81 APIRET rc, rc1;
82 HWND hwnd = HWND_DESKTOP;
83 char *p;
84
85 if (no_mmos2 || !filename || !*filename)
86 return played;
87
88 /* load MMPM/2, if available. */
89 *loaderror = 0;
90 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
91 if (rc) {
92 no_mmos2 = TRUE;
93 return played;
94 }
95 else {
96 if (DosQueryProcAddr(MMIOModHandle,
97 0,
98 "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
99 DosFreeModule(MMIOModHandle);
100 no_mmos2 = TRUE;
101 return played;
102 }
103 if (DosQueryProcAddr(MMIOModHandle,
104 0,
105 "mmioGetInfo", (PFN *) & pMMIOGetInfo)) {
106 DosFreeModule(MMIOModHandle);
107 no_mmos2 = TRUE;
108 return played;
109 }
110 if (DosQueryProcAddr(MMIOModHandle,
111 0,
112 "mmioClose", (PFN *) & pMMIOClose)) {
113 DosFreeModule(MMIOModHandle);
114 no_mmos2 = TRUE;
115 return played;
116 }
117 if (DosQueryProcAddr(MMIOModHandle,
118 0,
119 "mmioOpen", (PFN *) & pMMIOOpen)) {
120 DosFreeModule(MMIOModHandle);
121 no_mmos2 = TRUE;
122 return played;
123 }
124 }
125
126 /* attempt to identify the file using MMPM/2 */
127 memset( &mmioinfo, '\0', sizeof(MMIOINFO) );
128 /*Eliminate non multimedia files*/
129 hmmio = pMMIOOpen(filename,
130 &mmioinfo,
131 MMIO_READ);
132 if (!hmmio) {
133 p = strrchr(filename, '.'); //Added to save mp3, ogg & flac which fail above test
134 if (!p)
135 p = ".";
136 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC) ||
137 !stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG)) {
138 hmmio = pMMIOOpen(filename,
139 &mmioinfo,
140 MMIO_READ | MMIO_NOIDENTIFY);
141 if (!hmmio){
142 DosFreeModule(MMIOModHandle);
143 return played;
144 }
145 }
146 else {
147 DosFreeModule(MMIOModHandle);
148 return played;
149 }
150 }
151 if (!hmmio) {
152 DosFreeModule(MMIOModHandle);
153 return played;
154 }
155 rc1 = pMMIOGetInfo(hmmio, &mmioinfo, 0L);
156 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
157 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
158 rc = pMMIOIdentifyFile(filename,
159 &mmioinfo,
160 &mmFormatInfo,
161 &fccStorageSystem, 0L,
162 MMIO_FORCE_IDENTIFY_FF);
163 /* free module handle */
164 rc1 = pMMIOClose(hmmio, 0L);
165 DosFreeModule(MMIOModHandle);
166
167 /* if identified and not FOURCC_DOS */
168 if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
169 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
170 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
171 p = strrchr(filename, '.');
172 if (!p)
173 p = ".";
174 if (!stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG))
175 OpenObject(filename, Default, hwnd); //Image fails to display these
176 else // is an image that can be translated
177 RunFM2Util("IMAGE.EXE", filename);
178 played = TRUE;
179 }
180 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
181 /* is a multimedia file (WAV, MID, AVI, etc.) */
182 p = strrchr(filename, '.');
183 if (!p)
184 p = ".";
185 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC))
186 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
187 else
188 RunFM2Util(PCSZ_FM2PLAYEXE, filename);
189 played = TRUE;
190 }
191 }
192
193 return played;
194}
195
196VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
197 SWP * swp, CHAR * filename)
198{
199 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
200 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
201 else if (shiftstate & KC_CTRL)
202 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
203 else if (shiftstate & KC_SHIFT)
204 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
205 else
206 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
207}
208
209VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
210 ULONG flags, CHAR * filename)
211{
212 /*
213 * bitmapped flags:
214 * ---------------
215 * 1 = View directly
216 * 2 = Open WPS default view
217 * 4 = Open WPS settings view
218 * 8 = Edit
219 * 16 = Info
220 * 32 = No view info
221 */
222
223 HWND hwndArc = (HWND) 0;
224 char *p, *dummy[3];
225
226 if (!hwndParent)
227 hwndParent = HWND_DESKTOP;
228
229 if (flags & 32) {
230 flags &= (~16);
231 if (!IsFile(filename)) {
232 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
233 return;
234 }
235 }
236
237 if (flags & 1) /* directly view the file */
238 goto ViewIt;
239
240 if (flags & 2) { /* open default WPS view of file */
241 OpenObject(filename, Default, hwnd);
242 return;
243 }
244
245 if (flags & 4) { /* open WPS settings notebook for file */
246 OpenObject(filename, Settings, hwnd);
247 return;
248 }
249
250 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
251
252 char fullname[CCHMAXPATH];
253
254 if (!IsFullName(filename)) {
255 if (!DosQueryPathInfo(filename,
256 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
257 filename = fullname;
258 }
259 if (IsFullName(filename) &&
260 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
261 if (!IsRoot(filename)) {
262 dummy[0] = filename;
263 dummy[1] = NULL;
264 WinDlgBox(HWND_DESKTOP,
265 HWND_DESKTOP,
266 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
267 }
268 else
269 WinDlgBox(HWND_DESKTOP,
270 HWND_DESKTOP,
271 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
272 }
273 return;
274 }
275
276 if (flags & 8) { /* edit file */
277
278 ULONG type = IDM_EDITTEXT;
279
280 dummy[0] = filename;
281 dummy[1] = NULL;
282 if (TestBinary(filename))
283 type = IDM_EDITBINARY;
284 switch (type) {
285 case IDM_EDITBINARY:
286 if (*bined) {
287 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
288 pszSrcFile, __LINE__);
289 break;
290 }
291 /* else intentional fallthru */
292 case IDM_EDITTEXT:
293 if (*editor)
294 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
295 pszSrcFile, __LINE__);
296 else {
297 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
298 type |= 4;
299 StartMLEEditor(hwndParent, type, filename, hwndFrame);
300 }
301 break;
302 }
303 return;
304 }
305
306 if (ExecAssociation(hwnd, filename) == -1 &&
307 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
308 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
309 strcmp(realappname, FM3Str)) ?
310 HWND_DESKTOP :
311 hwndParent, hwndFrame, filename, 4, NULL);
312 if (!hwndArc) {
313 if (!fCheckMM || !ShowMultimedia(filename)) {
314 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
315 p = strrchr(filename, '.');
316 if (!p)
317 p = ".";
318 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
319 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
320 ViewIt:
321 if (TestBinary(filename)) {
322 if (*binview) {
323 dummy[0] = filename;
324 dummy[1] = NULL;
325 ExecOnList(hwnd,
326 binview,
327 WINDOWED | SEPARATE |
328 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
329 pszSrcFile, __LINE__);
330 }
331 else if (fUseNewViewer) {
332 if (fExternalViewer || strcmp(realappname, FM3Str))
333 hwndParent = HWND_DESKTOP;
334 StartViewer(hwndParent, 5, filename, hwndFrame);
335 }
336 else
337 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
338 }
339 else {
340 if (*viewer) {
341 dummy[0] = filename;
342 dummy[1] = NULL;
343 ExecOnList(hwnd,
344 viewer,
345 WINDOWED | SEPARATE |
346 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
347 pszSrcFile, __LINE__);
348 }
349 else if (fUseNewViewer) {
350 if (fExternalViewer || strcmp(realappname, FM3Str))
351 hwndParent = HWND_DESKTOP;
352 StartViewer(hwndParent, 5, filename, hwndFrame);
353 }
354 else
355 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
356 }
357 }
358 }
359 }
360 }
361 }
362 else {
363 if ((swp &&
364 !fExternalArcboxes &&
365 !strcmp(realappname, FM3Str)) &&
366 !ParentIsDesktop(hwnd, hwndParent))
367 WinSetWindowPos(hwndArc,
368 HWND_TOP,
369 swp->x,
370 swp->y,
371 swp->cx,
372 swp->cy,
373 SWP_MOVE | SWP_SIZE | SWP_SHOW |
374 SWP_ZORDER | SWP_ACTIVATE);
375 }
376 }
377}
378
379#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.