| [92] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: defview.c 1497 2010-01-08 04:39:40Z 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) | 
|---|
| [1484] | 22 | 05 Jan 09 GKY Use TestBinary so that text viewer isn't used for hex files by default | 
|---|
| [1402] | 23 | 08 Mar 09 GKY Additional strings move to PCSZs | 
|---|
| [1479] | 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 | 
|---|
| [1481] | 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. | 
|---|
| [92] | 30 |  | 
|---|
|  | 31 | ***********************************************************************/ | 
|---|
|  | 32 |  | 
|---|
| [907] | 33 | #include <string.h> | 
|---|
|  | 34 | #include <ctype.h> | 
|---|
|  | 35 |  | 
|---|
| [2] | 36 | #define INCL_DOS | 
|---|
|  | 37 | #define INCL_WIN | 
|---|
|  | 38 | #define INCL_GPI | 
|---|
|  | 39 | #define INCL_MMIOOS2 | 
|---|
| [907] | 40 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| [2] | 41 | #include <os2.h> | 
|---|
|  | 42 | #include <os2me.h> | 
|---|
| [347] | 43 |  | 
|---|
| [1206] | 44 | #include "fm3dll.h" | 
|---|
| [1222] | 45 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc. | 
|---|
| [1206] | 46 | #include "mainwnd2.h"                   // Data declaration(s) | 
|---|
|  | 47 | #include "init.h"                       // Data declaration(s) | 
|---|
| [907] | 48 | #include "fm3dlg.h" | 
|---|
|  | 49 | #include "arccnrs.h"                    // StartArcCnr | 
|---|
|  | 50 | #include "errutil.h"                    // Dos_Error... | 
|---|
| [985] | 51 | #include "notebook.h"                   // external viewers | 
|---|
| [1164] | 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 | 
|---|
| [1189] | 59 | #include "systemf.h"                    // ExecOnList | 
|---|
|  | 60 | #include "shadow.h"                     // OpenObject | 
|---|
|  | 61 | #include "viewer.h"                     // StartMLEEditor | 
|---|
|  | 62 | #include "newview.h"                    // StartViewer | 
|---|
| [1206] | 63 | #include "mainwnd.h"                    // Data declaration(s) | 
|---|
| [1164] | 64 | #include "misc.h"                       // ExecFile, ViewHelp | 
|---|
| [2] | 65 |  | 
|---|
| [1206] | 66 | // Data definitions | 
|---|
| [347] | 67 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 68 |  | 
|---|
| [1206] | 69 | #pragma data_seg(GLOBAL2) | 
|---|
| [1402] | 70 | PCSZ Default  = "DEFAULT"; | 
|---|
| [1206] | 71 |  | 
|---|
| [1481] | 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 |  | 
|---|
| [551] | 79 | BOOL ShowMultimedia(CHAR * filename) | 
|---|
| [92] | 80 | { | 
|---|
| [2] | 81 |  | 
|---|
| [551] | 82 | static BOOL no_mmos2 = FALSE; | 
|---|
|  | 83 | BOOL played = FALSE; | 
|---|
|  | 84 | CHAR loaderror[CCHMAXPATH]; | 
|---|
|  | 85 | HMODULE MMIOModHandle = NULLHANDLE; | 
|---|
| [92] | 86 | PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL; | 
|---|
| [551] | 87 | FOURCC fccStorageSystem = 0; | 
|---|
|  | 88 | MMFORMATINFO mmFormatInfo; | 
|---|
| [1481] | 89 | APIRET rc; | 
|---|
| [689] | 90 | HWND hwnd = HWND_DESKTOP; | 
|---|
| [570] | 91 | char *p; | 
|---|
| [2] | 92 |  | 
|---|
| [551] | 93 | if (no_mmos2 || !filename || !*filename) | 
|---|
| [92] | 94 | return played; | 
|---|
| [2] | 95 |  | 
|---|
| [1481] | 96 | //load MMPM/2, if available. | 
|---|
| [2] | 97 | *loaderror = 0; | 
|---|
| [551] | 98 | rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle); | 
|---|
| [92] | 99 | if (rc) { | 
|---|
|  | 100 | no_mmos2 = TRUE; | 
|---|
|  | 101 | return played; | 
|---|
| [2] | 102 | } | 
|---|
|  | 103 | else { | 
|---|
| [92] | 104 | if (DosQueryProcAddr(MMIOModHandle, | 
|---|
| [551] | 105 | 0, | 
|---|
| [1481] | 106 | "mmioIdentifyFile", (PFN *) &pMMIOIdentifyFile)) { | 
|---|
| [2] | 107 | DosFreeModule(MMIOModHandle); | 
|---|
| [92] | 108 | no_mmos2 = TRUE; | 
|---|
|  | 109 | return played; | 
|---|
| [2] | 110 | } | 
|---|
|  | 111 | } | 
|---|
| [551] | 112 | memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO)); | 
|---|
| [2] | 113 | mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO); | 
|---|
| [1481] | 114 | rc = pMMIOIdentifyFile(filename, 0L, &mmFormatInfo, | 
|---|
| [901] | 115 | &fccStorageSystem, 0L, | 
|---|
|  | 116 | MMIO_FORCE_IDENTIFY_FF); | 
|---|
| [2] | 117 | DosFreeModule(MMIOModHandle); | 
|---|
| [1481] | 118 | p = strrchr(filename, '.'); | 
|---|
| [1479] | 119 | if (!p) | 
|---|
|  | 120 | p = "."; | 
|---|
| [1481] | 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))) { | 
|---|
| [92] | 126 | if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE && | 
|---|
| [901] | 127 | (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) { | 
|---|
| [1481] | 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; | 
|---|
| [2] | 133 | } | 
|---|
| [92] | 134 | else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) { | 
|---|
| [901] | 135 | /* is a multimedia file (WAV, MID, AVI, etc.) */ | 
|---|
| [1481] | 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; | 
|---|
| [2] | 141 | } | 
|---|
|  | 142 | } | 
|---|
|  | 143 |  | 
|---|
| [92] | 144 | return played; | 
|---|
| [2] | 145 | } | 
|---|
|  | 146 |  | 
|---|
| [551] | 147 | VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent, | 
|---|
|  | 148 | SWP * swp, CHAR * filename) | 
|---|
| [347] | 149 | { | 
|---|
| [551] | 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); | 
|---|
| [2] | 156 | else | 
|---|
| [551] | 157 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename); | 
|---|
| [2] | 158 | } | 
|---|
|  | 159 |  | 
|---|
| [1481] | 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 |  | 
|---|
| [551] | 166 | VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp, | 
|---|
|  | 167 | ULONG flags, CHAR * filename) | 
|---|
| [347] | 168 | { | 
|---|
| [2] | 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 |  | 
|---|
| [551] | 180 | HWND hwndArc = (HWND) 0; | 
|---|
|  | 181 | char *p, *dummy[3]; | 
|---|
| [2] | 182 |  | 
|---|
| [551] | 183 | if (!hwndParent) | 
|---|
| [2] | 184 | hwndParent = HWND_DESKTOP; | 
|---|
|  | 185 |  | 
|---|
| [551] | 186 | if (flags & 32) { | 
|---|
| [2] | 187 | flags &= (~16); | 
|---|
| [551] | 188 | if (!IsFile(filename)) { | 
|---|
| [347] | 189 | Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename); | 
|---|
| [2] | 190 | return; | 
|---|
|  | 191 | } | 
|---|
|  | 192 | } | 
|---|
|  | 193 |  | 
|---|
| [551] | 194 | if (flags & 1)                        /* directly view the file */ | 
|---|
| [2] | 195 | goto ViewIt; | 
|---|
|  | 196 |  | 
|---|
| [551] | 197 | if (flags & 2) {                      /* open default WPS view of file */ | 
|---|
|  | 198 | OpenObject(filename, Default, hwnd); | 
|---|
| [2] | 199 | return; | 
|---|
|  | 200 | } | 
|---|
|  | 201 |  | 
|---|
| [551] | 202 | if (flags & 4) {                      /* open WPS settings notebook for file */ | 
|---|
|  | 203 | OpenObject(filename, Settings, hwnd); | 
|---|
| [2] | 204 | return; | 
|---|
|  | 205 | } | 
|---|
|  | 206 |  | 
|---|
| [551] | 207 | if ((flags & 16) || !IsFile(filename)) {      /* open info for directories */ | 
|---|
| [2] | 208 |  | 
|---|
|  | 209 | char fullname[CCHMAXPATH]; | 
|---|
|  | 210 |  | 
|---|
| [551] | 211 | if (!IsFullName(filename)) { | 
|---|
|  | 212 | if (!DosQueryPathInfo(filename, | 
|---|
|  | 213 | FIL_QUERYFULLNAME, fullname, sizeof(fullname))) | 
|---|
| [92] | 214 | filename = fullname; | 
|---|
| [2] | 215 | } | 
|---|
| [551] | 216 | if (IsFullName(filename) && | 
|---|
|  | 217 | !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) { | 
|---|
|  | 218 | if (!IsRoot(filename)) { | 
|---|
| [92] | 219 | dummy[0] = filename; | 
|---|
|  | 220 | dummy[1] = NULL; | 
|---|
|  | 221 | WinDlgBox(HWND_DESKTOP, | 
|---|
|  | 222 | HWND_DESKTOP, | 
|---|
| [551] | 223 | FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy); | 
|---|
| [2] | 224 | } | 
|---|
|  | 225 | else | 
|---|
| [92] | 226 | WinDlgBox(HWND_DESKTOP, | 
|---|
|  | 227 | HWND_DESKTOP, | 
|---|
| [551] | 228 | DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename); | 
|---|
| [2] | 229 | } | 
|---|
|  | 230 | return; | 
|---|
|  | 231 | } | 
|---|
|  | 232 |  | 
|---|
| [551] | 233 | if (flags & 8) {                      /* edit file */ | 
|---|
| [2] | 234 |  | 
|---|
|  | 235 | ULONG type = IDM_EDITTEXT; | 
|---|
|  | 236 |  | 
|---|
|  | 237 | dummy[0] = filename; | 
|---|
|  | 238 | dummy[1] = NULL; | 
|---|
| [551] | 239 | if (TestBinary(filename)) | 
|---|
| [2] | 240 | type = IDM_EDITBINARY; | 
|---|
| [551] | 241 | switch (type) { | 
|---|
|  | 242 | case IDM_EDITBINARY: | 
|---|
|  | 243 | if (*bined) { | 
|---|
| [1497] | 244 | ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL, | 
|---|
| [901] | 245 | pszSrcFile, __LINE__); | 
|---|
| [551] | 246 | break; | 
|---|
|  | 247 | } | 
|---|
| [2] | 248 | /* else intentional fallthru */ | 
|---|
| [551] | 249 | case IDM_EDITTEXT: | 
|---|
|  | 250 | if (*editor) | 
|---|
| [1497] | 251 | ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL, | 
|---|
| [901] | 252 | pszSrcFile, __LINE__); | 
|---|
| [551] | 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; | 
|---|
| [2] | 259 | } | 
|---|
|  | 260 | return; | 
|---|
|  | 261 | } | 
|---|
|  | 262 |  | 
|---|
| [1120] | 263 | if (ExecAssociation(hwnd, filename) == -1 && | 
|---|
|  | 264 | CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) { | 
|---|
| [2] | 265 | hwndArc = StartArcCnr((fExternalArcboxes || !swp || | 
|---|
| [551] | 266 | strcmp(realappname, FM3Str)) ? | 
|---|
| [92] | 267 | HWND_DESKTOP : | 
|---|
| [551] | 268 | hwndParent, hwndFrame, filename, 4, NULL); | 
|---|
|  | 269 | if (!hwndArc) { | 
|---|
| [1479] | 270 | if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) { | 
|---|
|  | 271 | p = strrchr(filename, '.'); | 
|---|
|  | 272 | if (!p) | 
|---|
|  | 273 | p = "."; | 
|---|
| [1481] | 274 | if (!stricmp(p, ".WPI")) { | 
|---|
|  | 275 | OpenObject(filename, Default, hwnd); | 
|---|
|  | 276 | return; | 
|---|
|  | 277 | } | 
|---|
| [1479] | 278 | if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) { | 
|---|
|  | 279 | if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) { | 
|---|
| [1481] | 280 | if (!fCheckMM || !ShowMultimedia(filename)) { | 
|---|
| [1386] | 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 | | 
|---|
| [1497] | 289 | ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL, | 
|---|
| [1386] | 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 | | 
|---|
| [1497] | 307 | ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL, | 
|---|
| [1386] | 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 | } | 
|---|
| [92] | 318 | } | 
|---|
|  | 319 | } | 
|---|
|  | 320 | } | 
|---|
| [2] | 321 | } | 
|---|
|  | 322 | } | 
|---|
|  | 323 | else { | 
|---|
| [551] | 324 | if ((swp && | 
|---|
|  | 325 | !fExternalArcboxes && | 
|---|
|  | 326 | !strcmp(realappname, FM3Str)) && | 
|---|
|  | 327 | !ParentIsDesktop(hwnd, hwndParent)) | 
|---|
| [92] | 328 | WinSetWindowPos(hwndArc, | 
|---|
|  | 329 | HWND_TOP, | 
|---|
|  | 330 | swp->x, | 
|---|
|  | 331 | swp->y, | 
|---|
|  | 332 | swp->cx, | 
|---|
|  | 333 | swp->cy, | 
|---|
| [551] | 334 | SWP_MOVE | SWP_SIZE | SWP_SHOW | | 
|---|
| [92] | 335 | SWP_ZORDER | SWP_ACTIVATE); | 
|---|
| [2] | 336 | } | 
|---|
|  | 337 | } | 
|---|
|  | 338 | } | 
|---|
| [793] | 339 |  | 
|---|
|  | 340 | #pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys) | 
|---|