[3] | 1 |
|
---|
| 2 | // ù Ä ÄÄÄÄÍÍ = Ä ù Ä = ÍÍÄÄÄÄ Ä ù
|
---|
| 3 | // ³ ³
|
---|
| 4 | // ÜÛÛÛÛÛÛÛÜ ÜÛÜ ÜÛÛÛÛÛÛÛÛÜ ú úÄÄÄÍÄÄÍÄÍÍÄÄÍÍÍÍÄÍÍÍÍÍÍÍÍÍÎÄ
|
---|
| 5 | // ³ ÛÛÛÛßßßÛÛÛÛ ÛÛÛÛÛ ÛÛÛß ßÛÛÛ ³ MINSTALL Front-End º
|
---|
| 6 | // º ÛÛÛÛÜÜÜÛÛÛÛ ÛÛÛÛÛ ÛÛÛÜ ÜÛÛÛ º ú ÄÄÄÄÍÄÍÍÄÄÍÍÍÍÄÍÍÍÍÍÍÍÍÄÍÍÍÍÍÎÄ
|
---|
| 7 | // º ÛÛÛÛÛÛÛÛÛÛÛ ÛÛÛÛÛ ÛÛÛÛÛÛÛÛÛß º Section: MMOS/2 for eCS º
|
---|
| 8 | // º ÛÛÛÛ ÛÛÛÛ ÛÛÛÛÛ ÛÛÛÛ ßÛÛÛÛÜ º ³ Created: 28/10/02 º
|
---|
| 9 | // ³ ßÛÛß ßÛÛß ßÛß ßÛÛß ßÛÛß ³ ³ Last Modified: ³
|
---|
| 10 | // ÜÜÜ ³ Number Of Modifications: 000 ³
|
---|
| 11 | // ù ÜÛÛß ù ³ INCs required: *none* ³
|
---|
| 12 | // ÄÄÄÄÄÄÄ ÜÛÛß º Written By: Martin Kiewitz ³
|
---|
| 13 | // ³ Ú¿Ú¿³ÜÛÛÛÜÜÛÛÛÜ ³ º (c) Copyright by ³
|
---|
| 14 | // º ÀÙ³ÀÙßÛÛÛßßÜÛÛß º º AiR ON-Line Software '02 ú
|
---|
| 15 | // º ÄÄÄÄÄÄÄ ÜÛÛÝ º º All rights reserved.
|
---|
| 16 | // º ÜÛÛÛÄÄÄÄÄÄÄÄÄ º ÄÎÍÍÍÄÍÍÍÍÍÄÍÍÍÍÄÍÍÄÄÍÄÄÍÄÄÄúÄÄ ú
|
---|
| 17 | // º ÜÛÛÛݳ ³Ú¿³³Ä º
|
---|
| 18 | // ³ ÜÛÛÛÛ Àij³ÀÙ³Ä ³
|
---|
| 19 | // ßÛÛÛÛÝÄÄÄÄÄÄÄÄÄÄ
|
---|
| 20 | // ³ ßß ³
|
---|
| 21 | // ù ÄŽ-=iç éï-Liïî SéâWçî=-ÃÄÄ ù
|
---|
| 22 |
|
---|
| 23 | #define INCL_NOPMAPI
|
---|
| 24 | #define INCL_BASE
|
---|
| 25 | #define INCL_DOSMODULEMGR
|
---|
| 26 | #include <os2.h>
|
---|
| 27 |
|
---|
| 28 | #include <global.h>
|
---|
| 29 | #include <crcs.h>
|
---|
| 30 | #include <file.h>
|
---|
| 31 |
|
---|
| 32 | // PCHAR FILE_CONFIGSYS = 0;
|
---|
| 33 | // PCHAR FILE_DelayUtilFileName = 0;
|
---|
| 34 | // PCHAR FILE_DelayListFileName = 0;
|
---|
| 35 | // PCHAR FILE_DelayDirectory = 0;
|
---|
| 36 |
|
---|
| 37 | // Copies a file, will not replace existing file. Replies TRUE, if succeeded
|
---|
| 38 | APIRET FILE_Copy (PSZ SourceFileName, PSZ DestFileName) {
|
---|
| 39 | APIRET rc;
|
---|
| 40 | if (!(rc = DosCopy (SourceFileName, DestFileName, 0)))
|
---|
| 41 | rc = FILE_ResetAttributes (DestFileName);
|
---|
| 42 | return rc;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | // Copies a file, replaces existing file. Replies TRUE, if succeeded
|
---|
| 46 | BOOL FILE_Replace (PSZ SourceFileName, PSZ DestFileName) {
|
---|
| 47 | APIRET rc;
|
---|
| 48 | if (!(rc = DosCopy (SourceFileName, DestFileName, DCPY_EXISTING)))
|
---|
| 49 | FILE_ResetAttributes (DestFileName);
|
---|
| 50 | return rc;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // This creates a multi-level directory... Needs a FQ-directory/filename as
|
---|
| 54 | // input. "C:\test\test" is not correct. Use "C:\test\test\".
|
---|
| 55 | BOOL FILE_CreateDirectory (PSZ DirectoryName) {
|
---|
| 56 | CHAR TempDirectoryName[MAXFILELENGTH];
|
---|
| 57 | PCHAR CurPos = (PCHAR)&TempDirectoryName;
|
---|
| 58 | PCHAR EndPos = (PCHAR)((ULONG)&TempDirectoryName+strlen(DirectoryName));
|
---|
| 59 | APIRET rc = 0;
|
---|
| 60 |
|
---|
| 61 | if ((EndPos-CurPos)>=MAXFILELENGTH)
|
---|
| 62 | return FALSE; // due Buffer-Overflow
|
---|
| 63 |
|
---|
| 64 | // Copy Directory-Name...
|
---|
| 65 | strcpy (TempDirectoryName, DirectoryName);
|
---|
| 66 |
|
---|
| 67 | CurPos += 3; // skip over "x:\"
|
---|
| 68 | while (CurPos<EndPos) {
|
---|
| 69 | if (*CurPos==0x5C) {
|
---|
| 70 | *CurPos = 0; // Set terminating NUL...
|
---|
| 71 | rc = DosCreateDir (TempDirectoryName, NULL);
|
---|
| 72 | if ((rc!=0) && (rc!=ERROR_ACCESS_DENIED))
|
---|
| 73 | return FALSE;
|
---|
| 74 | *CurPos = 0x5C; // Set '\' again...
|
---|
| 75 | }
|
---|
| 76 | CurPos++;
|
---|
| 77 | }
|
---|
| 78 | return TRUE;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | // Will reset R/O, System, Hidden and Archive attributes on a given file
|
---|
| 82 | BOOL FILE_ResetAttributes (PSZ FileName) {
|
---|
| 83 | FILESTATUS3 CurFileInfo = {0};
|
---|
| 84 | CurFileInfo.attrFile = FILE_NORMAL;
|
---|
| 85 | if (DosSetPathInfo (FileName, FIL_STANDARD, &CurFileInfo, sizeof(CurFileInfo), 0))
|
---|
| 86 | return FALSE;
|
---|
| 87 | return TRUE;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | // Loads in a maximum of 128k of a control file. We don't support more for
|
---|
| 91 | // security, because we load the whole file at once and we dont know IF the
|
---|
| 92 | // file actually IS a control file.
|
---|
| 93 | BOOL FILE_LoadFileControl (PFILECONTROL FileControl, ULONG MaxFileSize) {
|
---|
| 94 | FILE *FileHandle = 0;
|
---|
| 95 |
|
---|
| 96 | FileControl->BufferPtr = 0;
|
---|
| 97 | FileControl->BufferSize = 0;
|
---|
| 98 |
|
---|
| 99 | FileHandle = fopen(FileControl->Name, "rb");
|
---|
| 100 | if (FileHandle==NULL)
|
---|
| 101 | return FALSE;
|
---|
| 102 |
|
---|
| 103 | // Get File-Length of INI-File, check for maximum buffer-length
|
---|
| 104 | fseek (FileHandle, 0, SEEK_END);
|
---|
| 105 | FileControl->BufferSize = ftell(FileHandle);
|
---|
| 106 | if (FileControl->BufferSize>=MaxFileSize) FileControl->BufferSize = MaxFileSize;
|
---|
| 107 |
|
---|
| 108 | FileControl->BufferPtr = malloc(FileControl->BufferSize+1);
|
---|
| 109 | if (FileControl->BufferPtr==NULL) {
|
---|
| 110 | fclose (FileHandle);
|
---|
| 111 | return FALSE;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | FileControl->BufferEndPtr = (PCHAR)((ULONG)FileControl->BufferPtr+FileControl->BufferSize);
|
---|
| 115 |
|
---|
| 116 | // Read in CONTROL.SCR-File (maximum MaxFileSize)
|
---|
| 117 | fseek (FileHandle, 0, SEEK_SET); // Seek back to start
|
---|
| 118 | if (FileControl->BufferSize != fread(FileControl->BufferPtr, 1, FileControl->BufferSize, FileHandle)) {
|
---|
| 119 | fclose (FileHandle);
|
---|
| 120 | FILE_UnLoadFileControl (FileControl);
|
---|
| 121 | return FALSE;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | // Put ending NUL for safety
|
---|
| 125 | *FileControl->BufferEndPtr = 0;
|
---|
| 126 |
|
---|
| 127 | // And close INI-File afterwards...
|
---|
| 128 | fclose (FileHandle);
|
---|
| 129 | return TRUE;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | VOID FILE_UnLoadFileControl (PFILECONTROL FileControl) {
|
---|
| 133 | if (FileControl->BufferPtr) {
|
---|
| 134 | free (FileControl->BufferPtr);
|
---|
| 135 | FileControl->BufferPtr = 0;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | // Replaces all comments and LFs with CRs in a Control-File buffer, so the
|
---|
| 140 | // actual parse routines will not process this data.
|
---|
| 141 | VOID FILE_PreProcessControlFile (PFILECONTROL FileControl) {
|
---|
| 142 | PCHAR CurPos = FileControl->BufferPtr;
|
---|
| 143 | PCHAR StartPos = CurPos;
|
---|
| 144 | CHAR CurChar = 0;
|
---|
| 145 |
|
---|
| 146 | while (CurPos<FileControl->BufferEndPtr) {
|
---|
| 147 | if (*(PUSHORT)CurPos==0x2A2F) {
|
---|
| 148 | *(PUSHORT)CurPos = 0x2020; StartPos = CurPos; CurPos += 2;
|
---|
| 149 | while (CurPos<FileControl->BufferEndPtr) {
|
---|
| 150 | if (*(PUSHORT)CurPos==0x2F2A) { // Got End-Of-Comment
|
---|
| 151 | *(PUSHORT)CurPos = 0x2020; CurPos++;
|
---|
| 152 | break;
|
---|
| 153 | } else if (*CurPos!=0x0D)
|
---|
| 154 | *CurPos = 0x20; // Fill in spaces...
|
---|
| 155 | CurPos++;
|
---|
| 156 | }
|
---|
| 157 | } else {
|
---|
| 158 | CurChar = *CurPos;
|
---|
| 159 | if ((CurChar==0x0A) || (CurChar==0x1A) || (CurChar==0x09))
|
---|
| 160 | *CurPos = 0x20; // Replace LF, EOF and TAB with space
|
---|
| 161 | }
|
---|
| 162 | CurPos++;
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | ULONG FILE_CountControlFileLines (PFILECONTROL FileControl) {
|
---|
| 167 | PCHAR CurPos = FileControl->BufferPtr;
|
---|
| 168 | PCHAR StartPos = CurPos;
|
---|
| 169 | ULONG TotalLines = 0;
|
---|
| 170 |
|
---|
| 171 | while (CurPos<FileControl->BufferEndPtr) {
|
---|
| 172 | if (*CurPos!=0x0D) {
|
---|
| 173 | StartPos = CurPos;
|
---|
| 174 | while ((CurPos<FileControl->BufferEndPtr) & (*CurPos!=0x0D)) {
|
---|
| 175 | if ((*CurPos!=0x20)) { // Count line, if not empty...
|
---|
| 176 | TotalLines++;
|
---|
| 177 | while ((CurPos<FileControl->BufferEndPtr) & (*CurPos!=0x0D))
|
---|
| 178 | CurPos++;
|
---|
| 179 | break;
|
---|
| 180 | } else CurPos++;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | CurPos++;
|
---|
| 184 | }
|
---|
| 185 | return TotalLines;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | // Checks, if FileName consists of path and filename, or filename only.
|
---|
| 189 | // will return FALSE; when no path got found (by looking for '\' character.
|
---|
| 190 | BOOL FILE_IncludesPath (PSZ FileName) {
|
---|
| 191 | PCHAR CurPos = FileName;
|
---|
| 192 |
|
---|
| 193 | while (*CurPos!=0) {
|
---|
| 194 | if (*CurPos==0x5C)
|
---|
| 195 | return TRUE;
|
---|
| 196 | CurPos++;
|
---|
| 197 | }
|
---|
| 198 | return FALSE;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | VOID FILE_SetDefaultExtension (PSZ FileName, ULONG FileNameMaxSize, PSZ DefaultExtension) {
|
---|
| 202 | ULONG FileNameLen = strlen(FileName);
|
---|
| 203 | PCHAR EndPos = (PCHAR)((ULONG)FileName+FileNameLen);
|
---|
| 204 | PCHAR CurPos = EndPos;
|
---|
| 205 | ULONG DefaultLen;
|
---|
| 206 |
|
---|
| 207 | // Don't modify NUL filenames
|
---|
| 208 | if (!FileNameLen) return;
|
---|
| 209 |
|
---|
| 210 | while (CurPos>FileName) {
|
---|
| 211 | if (*CurPos==0x5C) // If '\' is found, add extension
|
---|
| 212 | break;
|
---|
| 213 | if (*CurPos=='.') // Got '.' so has extension, exit
|
---|
| 214 | return;
|
---|
| 215 | CurPos--;
|
---|
| 216 | }
|
---|
| 217 | // Check, if we have enough place left
|
---|
| 218 | DefaultLen = strlen(DefaultExtension);
|
---|
| 219 | if ((FileNameMaxSize-FileNameLen)>DefaultLen) {
|
---|
| 220 | // Copy extension over including terminating NUL
|
---|
| 221 | memcpy (EndPos, DefaultExtension, DefaultLen+1);
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | VOID FILE_PutS (HFILE FileHandle, PSZ String) {
|
---|
| 226 | ULONG StringLen = strlen(String);
|
---|
| 227 | ULONG Written;
|
---|
| 228 |
|
---|
| 229 | DosWrite (FileHandle, String, StringLen, &Written);
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | BOOL FILE_GetCurrentPath (PSZ DestCurrentPath, ULONG PathMaxSize) {
|
---|
| 233 | ULONG CurrentDisk = 0;
|
---|
| 234 | ULONG CurrentLogDisks = 0;
|
---|
| 235 | CHAR CurrentDir[MAXFILELENGTH];
|
---|
| 236 | ULONG CurrentDirMaxSize = MAXFILELENGTH;
|
---|
| 237 |
|
---|
| 238 | // Find out path, where we currently are...
|
---|
| 239 | if (DosQueryCurrentDisk (&CurrentDisk, &CurrentLogDisks))
|
---|
| 240 | return FALSE;
|
---|
| 241 | if (DosQueryCurrentDir (0, CurrentDir, &CurrentDirMaxSize))
|
---|
| 242 | return FALSE;
|
---|
| 243 | if (strlen(CurrentDir)+3>=PathMaxSize)
|
---|
| 244 | return FALSE; // due Buffer-overflow
|
---|
| 245 |
|
---|
| 246 | sprintf (DestCurrentPath, "%c:\\%s", CurrentDisk+64, CurrentDir);
|
---|
| 247 | return TRUE;
|
---|
| 248 | }
|
---|