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
RevLine 
[92]1
2/***********************************************************************
3
4 $Id: defview.c 1402 2009-03-14 17:17:59Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
[907]7 Copyright (c) 2003, 2008 Steven H.Levine
[92]8
[347]9 Default file viewer
[92]10
[347]11 20 Nov 03 SHL ShowMultimedia: try to convince fmplay to not play exes (Gregg Young)
12 14 Jul 06 SHL Use Runtime_Error
[570]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
[627]15 21 Apr 07 GKY Find FM2Utils by path or utils directory
[689]16 09 Jun 07 SHL ShowMultimedia: Initialize hwnd so that OpenObject might work
[793]17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[888]18 20 Dec 07 GKY Open jpg files with OS2 object default since image.exe fails
[985]19 29 Feb 08 GKY Refactor global command line variables to notebook.h
[1120]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)
[1387]22 05 Jan 09 GKY Use TestBinary so that text veiwer isn't used for hex files by default
[1402]23 08 Mar 09 GKY Additional strings move to PCSZs
[92]24
25***********************************************************************/
26
[907]27#include <string.h>
28#include <ctype.h>
29
[2]30#define INCL_DOS
31#define INCL_WIN
32#define INCL_GPI
33#define INCL_MMIOOS2
[907]34#define INCL_LONGLONG // dircnrs.h
[2]35#include <os2.h>
36#include <os2me.h>
[347]37
[1206]38#include "fm3dll.h"
[1222]39#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1206]40#include "mainwnd2.h" // Data declaration(s)
41#include "init.h" // Data declaration(s)
[907]42#include "fm3dlg.h"
43#include "arccnrs.h" // StartArcCnr
44#include "errutil.h" // Dos_Error...
[985]45#include "notebook.h" // external viewers
[1164]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
[1189]53#include "systemf.h" // ExecOnList
54#include "shadow.h" // OpenObject
55#include "viewer.h" // StartMLEEditor
56#include "newview.h" // StartViewer
[1206]57#include "mainwnd.h" // Data declaration(s)
[1164]58#include "misc.h" // ExecFile, ViewHelp
[2]59
[1206]60// Data definitions
[347]61static PSZ pszSrcFile = __FILE__;
62
[1206]63#pragma data_seg(GLOBAL2)
[1402]64PCSZ Default = "DEFAULT";
[1206]65
[551]66BOOL ShowMultimedia(CHAR * filename)
[92]67{
[2]68
[551]69 static BOOL no_mmos2 = FALSE;
70 BOOL played = FALSE;
71 CHAR loaderror[CCHMAXPATH];
72 HMODULE MMIOModHandle = NULLHANDLE;
[92]73 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
[570]74 PMMIOGETINFO pMMIOGetInfo = NULL;
75 PMMIOCLOSE pMMIOClose = NULL;
76 PMMIOOPEN pMMIOOpen = NULL;
77 MMIOINFO mmioinfo;
[901]78 HMMIO hmmio;
[551]79 FOURCC fccStorageSystem = 0;
80 MMFORMATINFO mmFormatInfo;
[570]81 APIRET rc, rc1;
[689]82 HWND hwnd = HWND_DESKTOP;
[570]83 char *p;
[2]84
[551]85 if (no_mmos2 || !filename || !*filename)
[92]86 return played;
[2]87
88 /* load MMPM/2, if available. */
89 *loaderror = 0;
[551]90 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
[92]91 if (rc) {
92 no_mmos2 = TRUE;
93 return played;
[2]94 }
95 else {
[92]96 if (DosQueryProcAddr(MMIOModHandle,
[551]97 0,
98 "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
[2]99 DosFreeModule(MMIOModHandle);
[92]100 no_mmos2 = TRUE;
101 return played;
[2]102 }
[570]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 }
[2]124 }
125
126 /* attempt to identify the file using MMPM/2 */
[570]127 memset( &mmioinfo, '\0', sizeof(MMIOINFO) );
128 /*Eliminate non multimedia files*/
129 hmmio = pMMIOOpen(filename,
[901]130 &mmioinfo,
[1402]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 }
[901]155 rc1 = pMMIOGetInfo(hmmio, &mmioinfo, 0L);
[551]156 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
[2]157 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
[92]158 rc = pMMIOIdentifyFile(filename,
[570]159 &mmioinfo,
[92]160 &mmFormatInfo,
[901]161 &fccStorageSystem, 0L,
162 MMIO_FORCE_IDENTIFY_FF);
[2]163 /* free module handle */
[570]164 rc1 = pMMIOClose(hmmio, 0L);
[2]165 DosFreeModule(MMIOModHandle);
166
[92]167 /* if identified and not FOURCC_DOS */
[551]168 if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
[92]169 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
[901]170 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
[887]171 p = strrchr(filename, '.');
172 if (!p)
[901]173 p = ".";
[1398]174 if (!stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG))
[901]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;
[2]179 }
[92]180 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
[901]181 /* is a multimedia file (WAV, MID, AVI, etc.) */
182 p = strrchr(filename, '.');
[570]183 if (!p)
[901]184 p = ".";
[1398]185 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC))
[901]186 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
187 else
[1398]188 RunFM2Util(PCSZ_FM2PLAYEXE, filename);
[901]189 played = TRUE;
[2]190 }
191 }
192
[92]193 return played;
[2]194}
195
[551]196VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
197 SWP * swp, CHAR * filename)
[347]198{
[551]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);
[2]205 else
[551]206 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
[2]207}
208
[551]209VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
210 ULONG flags, CHAR * filename)
[347]211{
[2]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
[551]223 HWND hwndArc = (HWND) 0;
224 char *p, *dummy[3];
[2]225
[551]226 if (!hwndParent)
[2]227 hwndParent = HWND_DESKTOP;
228
[551]229 if (flags & 32) {
[2]230 flags &= (~16);
[551]231 if (!IsFile(filename)) {
[347]232 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
[2]233 return;
234 }
235 }
236
[551]237 if (flags & 1) /* directly view the file */
[2]238 goto ViewIt;
239
[551]240 if (flags & 2) { /* open default WPS view of file */
241 OpenObject(filename, Default, hwnd);
[2]242 return;
243 }
244
[551]245 if (flags & 4) { /* open WPS settings notebook for file */
246 OpenObject(filename, Settings, hwnd);
[2]247 return;
248 }
249
[551]250 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
[2]251
252 char fullname[CCHMAXPATH];
253
[551]254 if (!IsFullName(filename)) {
255 if (!DosQueryPathInfo(filename,
256 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
[92]257 filename = fullname;
[2]258 }
[551]259 if (IsFullName(filename) &&
260 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
261 if (!IsRoot(filename)) {
[92]262 dummy[0] = filename;
263 dummy[1] = NULL;
264 WinDlgBox(HWND_DESKTOP,
265 HWND_DESKTOP,
[551]266 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
[2]267 }
268 else
[92]269 WinDlgBox(HWND_DESKTOP,
270 HWND_DESKTOP,
[551]271 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
[2]272 }
273 return;
274 }
275
[551]276 if (flags & 8) { /* edit file */
[2]277
278 ULONG type = IDM_EDITTEXT;
279
280 dummy[0] = filename;
281 dummy[1] = NULL;
[551]282 if (TestBinary(filename))
[2]283 type = IDM_EDITBINARY;
[551]284 switch (type) {
285 case IDM_EDITBINARY:
286 if (*bined) {
[901]287 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
288 pszSrcFile, __LINE__);
[551]289 break;
290 }
[2]291 /* else intentional fallthru */
[551]292 case IDM_EDITTEXT:
293 if (*editor)
[901]294 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
295 pszSrcFile, __LINE__);
[551]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;
[2]302 }
303 return;
304 }
305
[1120]306 if (ExecAssociation(hwnd, filename) == -1 &&
307 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
[2]308 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
[551]309 strcmp(realappname, FM3Str)) ?
[92]310 HWND_DESKTOP :
[551]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)
[92]317 p = ".";
[551]318 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
[1398]319 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
[1386]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 }
[92]357 }
358 }
359 }
[2]360 }
361 }
362 else {
[551]363 if ((swp &&
364 !fExternalArcboxes &&
365 !strcmp(realappname, FM3Str)) &&
366 !ParentIsDesktop(hwnd, hwndParent))
[92]367 WinSetWindowPos(hwndArc,
368 HWND_TOP,
369 swp->x,
370 swp->y,
371 swp->cx,
372 swp->cy,
[551]373 SWP_MOVE | SWP_SIZE | SWP_SHOW |
[92]374 SWP_ZORDER | SWP_ACTIVATE);
[2]375 }
376 }
377}
[793]378
379#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.