| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: av2.c 907 2008-01-06 07:26:17Z stevenhl $ | 
|---|
| 5 |  | 
|---|
| 6 | Archive viewer applet | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| 9 | Copyright (c) 2007 Steven H. Levine | 
|---|
| 10 |  | 
|---|
| 11 | 23 Sep 07 SHL Sync with standards | 
|---|
| 12 | 23 Sep 07 SHL Get rid of statics | 
|---|
| 13 |  | 
|---|
| 14 | ***********************************************************************/ | 
|---|
| 15 |  | 
|---|
| 16 | #include <stdlib.h> | 
|---|
| 17 | #include <string.h> | 
|---|
| 18 |  | 
|---|
| 19 | #define INCL_DOS | 
|---|
| 20 | #define INCL_WIN | 
|---|
| 21 | #define INCL_LONGLONG | 
|---|
| 22 |  | 
|---|
| 23 | #include "dll\version.h" | 
|---|
| 24 | #include "dll\fm3str.h" | 
|---|
| 25 | #include "dll\arccnrs.h" | 
|---|
| 26 | #include "dll\fm3dll.h" | 
|---|
| 27 |  | 
|---|
| 28 | HMTX av2Sem; | 
|---|
| 29 |  | 
|---|
| 30 | VOID APIENTRY deinit(ULONG why) | 
|---|
| 31 | { | 
|---|
| 32 | /* cleanup before exiting */ | 
|---|
| 33 |  | 
|---|
| 34 | DosCloseMutexSem(av2Sem); | 
|---|
| 35 | if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) { | 
|---|
| 36 | CHAR s[CCHMAXPATH];                 // 23 Sep 07 SHL | 
|---|
| 37 | CHAR *enddir; | 
|---|
| 38 | HDIR search_handle; | 
|---|
| 39 | ULONG num_matches; | 
|---|
| 40 | FILEFINDBUF3 ffb3; | 
|---|
| 41 |  | 
|---|
| 42 | save_dir(s); | 
|---|
| 43 | if (s[strlen(s) - 1] != '\\') | 
|---|
| 44 | strcat(s, "\\"); | 
|---|
| 45 | enddir = &s[strlen(s)]; | 
|---|
| 46 | if (*ArcTempRoot) { | 
|---|
| 47 | strcat(s, ArcTempRoot); | 
|---|
| 48 | strcat(s, "*"); | 
|---|
| 49 | search_handle = HDIR_CREATE; | 
|---|
| 50 | num_matches = 1; | 
|---|
| 51 | if (!DosFindFirst(s, | 
|---|
| 52 | &search_handle, | 
|---|
| 53 | FILE_NORMAL | FILE_DIRECTORY | FILE_SYSTEM | | 
|---|
| 54 | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED, | 
|---|
| 55 | &ffb3, | 
|---|
| 56 | sizeof(ffb3), | 
|---|
| 57 | &num_matches, | 
|---|
| 58 | FIL_STANDARD)) { | 
|---|
| 59 | do { | 
|---|
| 60 | strcpy(enddir, ffb3.achName); | 
|---|
| 61 | if (ffb3.attrFile & FILE_DIRECTORY) { | 
|---|
| 62 | wipeallf("%s\\*", s); | 
|---|
| 63 | DosDeleteDir(s); | 
|---|
| 64 | } | 
|---|
| 65 | else | 
|---|
| 66 | unlinkf("%s", s); | 
|---|
| 67 | } while (!DosFindNext(search_handle, | 
|---|
| 68 | &ffb3, sizeof(FILEFINDBUF3), &num_matches)); | 
|---|
| 69 | DosFindClose(search_handle); | 
|---|
| 70 | } | 
|---|
| 71 | } | 
|---|
| 72 | } | 
|---|
| 73 | else | 
|---|
| 74 | DosCloseMutexSem(av2Sem); | 
|---|
| 75 |  | 
|---|
| 76 | DosExitList(EXLST_REMOVE, deinit); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | int main(int argc, char *argv[]) | 
|---|
| 80 | { | 
|---|
| 81 | HAB hab; | 
|---|
| 82 | HMQ hmq; | 
|---|
| 83 | QMSG qmsg; | 
|---|
| 84 | HWND hwndFrame = (HWND) 0; | 
|---|
| 85 | static CHAR fullname[CCHMAXPATH];     // 23 Sep 07 SHL fixme to not be static | 
|---|
| 86 | CHAR *thisarg = NULL; | 
|---|
| 87 | INT x; | 
|---|
| 88 |  | 
|---|
| 89 | *fullname = 0; | 
|---|
| 90 | strcpy(appname, "AV/2"); | 
|---|
| 91 | fAmAV2 = TRUE; | 
|---|
| 92 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 93 | for (x = 1; x < argc; x++) { | 
|---|
| 94 | if (!strchr("/;,`\'", *argv[x]) && | 
|---|
| 95 | !thisarg && | 
|---|
| 96 | (IsFile(argv[x]) == 1 || | 
|---|
| 97 | (strchr(argv[x], '?') || strchr(argv[x], '*') || | 
|---|
| 98 | !strchr(argv[x], '.')))) { | 
|---|
| 99 | thisarg = argv[x]; | 
|---|
| 100 | break; | 
|---|
| 101 | } | 
|---|
| 102 | } | 
|---|
| 103 | DosExitList(EXLST_ADD, deinit); | 
|---|
| 104 | if (DosOpenMutexSem("\\SEM32\\AV2", &av2Sem)) | 
|---|
| 105 | DosCreateMutexSem("\\SEM32\\AV2", &av2Sem, DC_SEM_SHARED, FALSE); | 
|---|
| 106 | if (thisarg) { | 
|---|
| 107 | if (DosQueryPathInfo(thisarg, | 
|---|
| 108 | FIL_QUERYFULLNAME, fullname, sizeof(fullname))) | 
|---|
| 109 | strcpy(fullname, thisarg); | 
|---|
| 110 | if (*fullname && (strchr(fullname, '?') || | 
|---|
| 111 | strchr(fullname, '*') || !strchr(fullname, '.'))) { | 
|---|
| 112 |  | 
|---|
| 113 | FILEFINDBUF3 ffb3; | 
|---|
| 114 | ULONG nm; | 
|---|
| 115 | HDIR hdir; | 
|---|
| 116 | CHAR *enddir; | 
|---|
| 117 |  | 
|---|
| 118 | if (!strchr(fullname, '.')) | 
|---|
| 119 | strcat(fullname, ".*"); | 
|---|
| 120 | enddir = strrchr(fullname, '\\'); | 
|---|
| 121 | if (enddir) { | 
|---|
| 122 | enddir++; | 
|---|
| 123 | hdir = HDIR_CREATE; | 
|---|
| 124 | nm = 1; | 
|---|
| 125 | if (!DosFindFirst(fullname, | 
|---|
| 126 | &hdir, | 
|---|
| 127 | FILE_NORMAL | FILE_SYSTEM | | 
|---|
| 128 | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED, | 
|---|
| 129 | &ffb3, sizeof(FILEFINDBUF3), &nm, FIL_STANDARD)) { | 
|---|
| 130 | strcpy(enddir, ffb3.achName); | 
|---|
| 131 | DosFindClose(hdir); | 
|---|
| 132 | } | 
|---|
| 133 | } | 
|---|
| 134 | } | 
|---|
| 135 | } | 
|---|
| 136 | hab = WinInitialize(0); | 
|---|
| 137 | if (hab) { | 
|---|
| 138 | hmq = WinCreateMsgQueue(hab, 1024); | 
|---|
| 139 | if (hmq) { | 
|---|
| 140 | { | 
|---|
| 141 | CHAR path[CCHMAXPATH]; | 
|---|
| 142 | CHAR *env; | 
|---|
| 143 | FILESTATUS3 fs; | 
|---|
| 144 |  | 
|---|
| 145 | env = getenv("FM3INI"); | 
|---|
| 146 | if (env && *env) { | 
|---|
| 147 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 148 | if (!DosQueryPathInfo(env, FIL_QUERYFULLNAME, path, sizeof(path))) { | 
|---|
| 149 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 150 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) { | 
|---|
| 151 | if (!(fs.attrFile & FILE_DIRECTORY)) { | 
|---|
| 152 | env = strrchr(path, '\\'); | 
|---|
| 153 | if (env) | 
|---|
| 154 | *env = 0; | 
|---|
| 155 | } | 
|---|
| 156 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 157 | if (!DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs))) { | 
|---|
| 158 | if (fs.attrFile & FILE_DIRECTORY) | 
|---|
| 159 | switch_to(path); | 
|---|
| 160 | } | 
|---|
| 161 | } | 
|---|
| 162 | } | 
|---|
| 163 | } | 
|---|
| 164 | } | 
|---|
| 165 | if (InitFM3DLL(hab, argc, argv)) { | 
|---|
| 166 | if (CheckVersion(VERMAJOR, VERMINOR)) { | 
|---|
| 167 | fAmAV2 = TRUE; | 
|---|
| 168 | if (!*fullname) { | 
|---|
| 169 | strcpy(fullname, "*"); | 
|---|
| 170 | if (!insert_filename(HWND_DESKTOP, | 
|---|
| 171 | fullname, | 
|---|
| 172 | TRUE, | 
|---|
| 173 | FALSE) || !*fullname || *fullname == '*') | 
|---|
| 174 | goto Abort; | 
|---|
| 175 | } | 
|---|
| 176 | if (*fullname) { | 
|---|
| 177 | if (ExecAssociation(HWND_DESKTOP, fullname) == -1) { | 
|---|
| 178 | hwndFrame = StartArcCnr(HWND_DESKTOP, | 
|---|
| 179 | (HWND) 0, fullname, 0, NULL); | 
|---|
| 180 | if (!hwndFrame) { | 
|---|
| 181 |  | 
|---|
| 182 | CHAR *p = strrchr(fullname, '.'); | 
|---|
| 183 |  | 
|---|
| 184 | if (p) { | 
|---|
| 185 | if (!stricmp(p, ".INI")) | 
|---|
| 186 | hwndFrame = StartIniEditor(HWND_DESKTOP, fullname, 0); | 
|---|
| 187 | } | 
|---|
| 188 | if (!ShowMultimedia(fullname)) | 
|---|
| 189 | hwndFrame = StartMLEEditor(HWND_DESKTOP, | 
|---|
| 190 | 1, | 
|---|
| 191 | ((*fullname) ? | 
|---|
| 192 | fullname : NULL), (HWND) 0); | 
|---|
| 193 | } | 
|---|
| 194 | if (hwndFrame && WinIsWindow(hab, hwndFrame)) { | 
|---|
| 195 | if (hwndHelp) | 
|---|
| 196 | WinAssociateHelpInstance(hwndHelp, hwndFrame); | 
|---|
| 197 | for (;;) { | 
|---|
| 198 | if (!WinGetMsg(hab, &qmsg, (HWND) 0, 0, 0)) { | 
|---|
| 199 | if (!WinIsWindow(hab, hwndFrame)) | 
|---|
| 200 | break; | 
|---|
| 201 | if (qmsg.hwnd) | 
|---|
| 202 | qmsg.msg = WM_CLOSE; | 
|---|
| 203 | else | 
|---|
| 204 | break; | 
|---|
| 205 | } | 
|---|
| 206 | if (hwndBubble && | 
|---|
| 207 | ((qmsg.msg > (WM_BUTTON1DOWN - 1) && | 
|---|
| 208 | qmsg.msg < (WM_BUTTON3DBLCLK + 1)) || | 
|---|
| 209 | (qmsg.msg > (WM_CHORD - 1) && | 
|---|
| 210 | qmsg.msg < (WM_BUTTON3CLICK + 1))) && | 
|---|
| 211 | WinIsWindowVisible(hwndBubble)) | 
|---|
| 212 | WinShowWindow(hwndBubble, FALSE); | 
|---|
| 213 | WinDispatchMsg(hab, &qmsg); | 
|---|
| 214 | } | 
|---|
| 215 | DosSleep(125); | 
|---|
| 216 | } | 
|---|
| 217 | } | 
|---|
| 218 | } | 
|---|
| 219 | } | 
|---|
| 220 | } | 
|---|
| 221 | Abort: | 
|---|
| 222 | DosSleep(125); | 
|---|
| 223 | WinDestroyMsgQueue(hmq); | 
|---|
| 224 | } | 
|---|
| 225 | WinTerminate(hab); | 
|---|
| 226 | } | 
|---|
| 227 | return 0; | 
|---|
| 228 | } | 
|---|