|
|
1.1 root 1: #define MAXBUF 256
2: #define MAXPATH 64
3:
4: #include <assert.h>
5: #include <dos.h>
6: #include <io.h>
7: #include <stdio.h>
8: #include <string.h>
9: #include <stdlib.h>
10: #include <windows.h>
11:
12: #include "iniupd.h"
13:
14: #define FALSE 0
15: #define TRUE 1
16:
17: FILE *fpSysIni;
18: FILE *fpSysPre;
19: char *psz1;
20: char *psz2;
21: char *psz3;
22: char rgchBuf[MAXBUF];
23: char szTmpBuf[MAXBUF];
24: char szSysIni[MAXBUF];
25: char szSysOld[MAXBUF];
26: char szTempFile[MAXBUF];
27: char *szWinPath;
28: char *szVxdPath;
29:
30: BOOL my_strnicmp( char *szStr1, char *szStr2, int count);
31: VOID stcpyf2n(char FAR *in, char *out);
32:
33: /****************************************************************************
34: FUNCTION: LibMain(HANDLE, WORD, WORD, LPSTR)
35:
36: PURPOSE: Is called by LibEntry. LibEntry is called by Windows when
37: the DLL is loaded. The LibEntry routine is provided in
38: the LIBENTRY.OBJ in the SDK Link Libraries disk. (The
39: source LIBENTRY.ASM is also provided.)
40:
41: LibEntry initializes the DLL's heap, if a HEAPSIZE value is
42: specified in the DLL's DEF file. Then LibEntry calls
43: LibMain. The LibMain function below satisfies that call.
44:
45: The LibMain function should perform additional initialization
46: tasks required by the DLL. In this example, no initialization
47: tasks are required. LibMain should return a value of 1 if
48: the initialization is successful.
49:
50: *******************************************************************************/
51: int FAR PASCAL LibMain(hModule, wDataSeg, cbHeapSize, lpszCmdLine)
52: HANDLE hModule;
53: WORD wDataSeg;
54: WORD cbHeapSize;
55: LPSTR lpszCmdLine;
56: {
57: return 1;
58: }
59:
60: /****************************************************************************
61:
62: FUNCTION: BOOL my_strnicmp(char *szStr1, char *szStr2, int count )
63:
64: PURPOSE: my_strnicmp is the same as the strnicmp function. Strnicmp
65: was not used because the linker could not find it in the library.
66:
67: TRUE is returned if the first "count" characters of szStr1 are
68: the same as szStr2. FALSE is returned otherwise.
69:
70: *******************************************************************************/
71:
72: BOOL my_strnicmp(char *szStr1, char *szStr2, int count )
73: {
74: int i;
75:
76: for (i = 0; i < count; i++)
77: {
78: if (toupper(szStr1[i]) != toupper(szStr2[i]))
79: return FALSE;
80: }
81: return TRUE;
82: }
83:
84: /****************************************************************************
85:
86: FUNCTION: VOID strcpyf2n(char FAR *in, char *out )
87:
88: PURPOSE: strcpyf2n copyies the contents of the far string in to the
89: near string out. Memory must be allocated for out for the
90: full string length including the terminatined '\0'
91:
92: *******************************************************************************/
93:
94: VOID strcpyf2n (char FAR *in, char *out)
95: {
96: while (*out++ = *in++);
97: }
98:
99: /****************************************************************************
100: FUNCTION: WEP(int)
101:
102: PURPOSE: Performs cleanup tasks when the DLL is unloaded. WEP() is
103: called automatically by Windows when the DLL is unloaded (no
104: remaining tasks still have the DLL loaded). It is strongly
105: recommended that a DLL have a WEP() function, even if it does
106: nothing but returns success (1), as in this example.
107:
108: *******************************************************************************/
109: int FAR PASCAL WEP (bSystemExit)
110: int bSystemExit;
111: {
112: return(1);
113: }
114:
115:
116:
117: /****************************************************************************
118: ****************************************************************************/
119:
120: BOOL FAR PASCAL MakeSystemIni(LPSTR lpszWinPath, LPSTR lpszVxdPath)
121: {
122: unsigned char fDevAdded = FALSE;
123:
124: //Using Windows as DPMI provider ...
125:
126: szWinPath = (char *) malloc (lstrlen(lpszWinPath)+1);
127: szVxdPath = (char *) malloc (lstrlen(lpszVxdPath)+1);
128:
129: strcpyf2n(lpszWinPath, szWinPath);
130: strcpyf2n(lpszVxdPath, szVxdPath);
131:
132: szSysIni[0] = '\0';
133: strcat(strcpy(szSysIni, szWinPath), "SYSTEM.INI");
134:
135: szTempFile[0] = '\0';
136: strcat(strcpy(szTempFile, szWinPath), "$win32s$.tmp" );
137:
138: if ((fpSysIni = fopen(szSysIni, "r")) == NULL)
139: {
140: wsprintf(szTmpBuf, "%s cannot be opened for read from %s. Setup is unable to make modifications.", szSysIni, szWinPath);
141: MessageBox((HWND)NULL, szTmpBuf, "Setup Message", MB_OK | MB_ICONEXCLAMATION);
142: return(FALSE);
143: }
144:
145: strcat(strcpy(szSysOld, szWinPath), "SYSTEM.OLD");
146: if ((fpSysPre = fopen(szSysOld, "wt")) == NULL)
147: {
148: sprintf(szTmpBuf, "%s cannot be opened for write. Setup is unable to make modifications.", szSysOld);
149: MessageBox((HWND)NULL, szTmpBuf, "Setup Message", MB_OK | MB_ICONEXCLAMATION);
150: fclose(fpSysIni);
151: return(FALSE);
152: }
153:
154: while (fgets(rgchBuf, MAXBUF, fpSysIni))
155: {
156: fputs(rgchBuf, fpSysPre);
157: if (my_strnicmp(rgchBuf, "[386Enh]", 8)==TRUE)
158: {
159: // only add to the [386Enh] section.
160: if (fDevAdded == FALSE)
161: {
162: fputs("device=", fpSysPre);
163: fputs(szVxdPath, fpSysPre);
164: fputc('\n', fpSysPre);
165: fDevAdded = TRUE;
166: }
167: do
168: {
169: if (!(psz1 = fgets(rgchBuf, MAXBUF, fpSysIni)))
170: break;
171: if (my_strnicmp(rgchBuf, "device", 6) == FALSE)
172: fputs(rgchBuf, fpSysPre);
173: else
174: {
175: if ((psz2 = strchr(psz1, '=')) != NULL)
176: {
177: if ( ((psz3 = strchr(psz2, szVxdPath[0])) != NULL) &&
178: (my_strnicmp(psz3, szVxdPath, strlen(szVxdPath)) == TRUE) )
179: continue;
180: else
181: fputs(rgchBuf, fpSysPre);
182: }
183: else
184: fputs(rgchBuf, fpSysPre);
185: }
186: } while (*psz1 != '[');
187: }
188: }
189:
190: fclose(fpSysIni);
191: fclose(fpSysPre);
192:
193: // Rename o' rama
194: rename( szSysIni, szTempFile );
195: rename( szSysOld, szSysIni );
196: rename( szTempFile, szSysOld );
197:
198: /* PostMessage(NULL, STF_SHL_INTERP, 0, 0L); */
199: return(TRUE);
200: }
201: /*
202: */
203:
204: BOOL FAR PASCAL RestartWindows( LPSTR lpszOleCliPath )
205: {
206: // Guarantee that OleCli.Dll is locked. This will result
207: // in setup doing appriate reboot via ExitExecRestart()
208: LoadLibrary ( lpszOleCliPath );
209: return(TRUE);
210: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.