Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
7.1 KiB

  1. // File: NmMigrat.c
  2. //
  3. // 16-bit Windows 98 Migration DLL for NetMeeting 3.0
  4. #include "NmMigrat.h"
  5. #include "stdio.h"
  6. // Win98 ships with NM 2.1 build 2203 and will force it to be installed
  7. static const char * g_pcszInfNm = "msnetmtg.inf";
  8. static const char * g_pcszVersion = "; Version 4,3,0,2203";
  9. static const char * g_pcszHeader = ";msnetmtg.inf (removed by NmMigrat.dll)\r\n[Version]\r\nsignature=\"$CHICAGO$\"\r\nSetupClass=Base\r\nLayoutFile=layout.inf, layout1.inf, layout2.inf\r\n";
  10. // In Win98's subase.inf, under [winother.oldlinks] there is a bogus line
  11. static const char * g_pcszInfSubase = "subase.inf";
  12. static const char * g_pcszWinOther = "[winother.oldlinks]";
  13. static const char * g_pcszNukeLink = "setup.ini, groupPrograms,, \"\"\"%Old_NetMeeting_DESC%\"\"\"";
  14. ///////////////////////////////////////////////////////////////////////
  15. typedef struct {
  16. HFILE hf; // File Handle
  17. LONG lPos; // current position in the file
  18. int ichCurr; // current character position in rgch
  19. int cchRemain; // number of remaining chars in rgch
  20. char rgch[8*1024]; // a really large buffer!
  21. } FD; // File Data
  22. ///////////////////////////////////////////////////////////////////////
  23. // Debug Utilities
  24. #ifdef DEBUG
  25. VOID ErrMsg2(LPCSTR pszFormat, LPVOID p1, LPVOID p2)
  26. {
  27. char szMsg[1024];
  28. OutputDebugString("NmMigration: ");
  29. wsprintf(szMsg, pszFormat, p1, p2);
  30. OutputDebugString(szMsg);
  31. OutputDebugString("\r\n");
  32. }
  33. VOID ErrMsg1(LPCSTR pszFormat, LPVOID p1)
  34. {
  35. ErrMsg2(pszFormat, p1, NULL);
  36. }
  37. #else
  38. #define ErrMsg1(psz, p1)
  39. #define ErrMsg2(psz, p1, p2)
  40. #endif /* DEBUG */
  41. ///////////////////////////////////////////////////////////////////////
  42. /* L I B M A I N */
  43. /*-------------------------------------------------------------------------
  44. %%Function: LibMain
  45. -------------------------------------------------------------------------*/
  46. int FAR PASCAL LibMain(HANDLE hInst, WORD wDataseg, WORD wHeapsize, LPSTR lpszcmdl)
  47. {
  48. Reference(hInst);
  49. Reference(wDataseg);
  50. Reference(wHeapsize);
  51. Reference(lpszcmdl);
  52. return 1;
  53. }
  54. /* F O P E N F I L E */
  55. /*-------------------------------------------------------------------------
  56. %%Function: FOpenFile
  57. Open the file from the temporary Win98 INF directory.
  58. -------------------------------------------------------------------------*/
  59. BOOL FOpenFile(LPCSTR pszFile, FD * pFd, BOOL fCreate)
  60. {
  61. char szPath[MAX_PATH];
  62. // LDID_SETUPTEMP = temp INF directory "C:\WININST0.400"
  63. UINT retVal = CtlGetLddPath(LDID_SETUPTEMP, szPath);
  64. if (0 != retVal)
  65. {
  66. ErrMsg1("CtlGetLddPath(TEMP) failed. Err=%d", (LPVOID) retVal);
  67. return FALSE;
  68. }
  69. // Nuke the temporary 2.1 inf so it doesn't get installed
  70. lstrcat(szPath, "\\");
  71. lstrcat(szPath, pszFile);
  72. if (fCreate)
  73. {
  74. pFd->hf = _lcreat(szPath, 0); // read/write
  75. }
  76. else
  77. {
  78. pFd->hf = _lopen(szPath, OF_READWRITE);
  79. }
  80. if (HFILE_ERROR == pFd->hf)
  81. {
  82. ErrMsg2("Unable to open [%s] Error=%d", szPath, (LPVOID) GetLastError());
  83. return FALSE;
  84. }
  85. pFd->lPos = 0;
  86. pFd->ichCurr = 0;
  87. pFd->cchRemain = 0;
  88. ErrMsg1("Opened [%s]", szPath);
  89. return TRUE;
  90. }
  91. /* R E A D L I N E */
  92. /*-------------------------------------------------------------------------
  93. %%Function: ReadLine
  94. Read a line (up to MAX_PATH chars) from the buffered file.
  95. Returns the number of characters read.
  96. -------------------------------------------------------------------------*/
  97. int ReadLine(char * pchDest, FD * pFd)
  98. {
  99. int cch;
  100. for (cch = 0; cch < MAX_PATH; cch++)
  101. {
  102. if (0 == pFd->cchRemain)
  103. {
  104. pFd->cchRemain = _lread(pFd->hf, pFd->rgch, sizeof(pFd->rgch));
  105. if (HFILE_ERROR == pFd->cchRemain)
  106. {
  107. ErrMsg1("End of file reached at pos=%d", (LPVOID) pFd->lPos);
  108. break;
  109. }
  110. pFd->ichCurr = 0;
  111. }
  112. pFd->lPos++;
  113. pFd->cchRemain--;
  114. *pchDest = pFd->rgch[pFd->ichCurr++];
  115. if ('\n' == *pchDest)
  116. {
  117. break;
  118. }
  119. if ('\r' != *pchDest)
  120. {
  121. pchDest++;
  122. }
  123. }
  124. *pchDest = '\0'; // Always null terminate the string
  125. return cch;
  126. }
  127. /* R E M O V E I N F */
  128. /*-------------------------------------------------------------------------
  129. %%Function: RemoveInf
  130. Remove the NM2.1 inf from Win98's list of inf's
  131. -------------------------------------------------------------------------*/
  132. void RemoveInf(void)
  133. {
  134. FD fd;
  135. if (!FOpenFile(g_pcszInfNm, &fd, FALSE))
  136. {
  137. return;
  138. }
  139. for ( ; ; ) // Find the version comment before the first section
  140. {
  141. char szLine[MAX_PATH];
  142. if (0 == ReadLine(szLine, &fd))
  143. {
  144. break;
  145. }
  146. if ('[' == szLine[0])
  147. {
  148. ErrMsg1("No version number found?", 0);
  149. break;
  150. }
  151. // Must match build 2203 since a Win98 update or an OEM
  152. // could ship a newer version than NM 2.11, which we would
  153. // want to upgrade us.
  154. if (0 == lstrcmp(szLine, g_pcszVersion))
  155. {
  156. // Re-write the older MSNETMTG.INF with a empty header
  157. _lclose(fd.hf);
  158. if (FOpenFile(g_pcszInfNm, &fd, TRUE))
  159. {
  160. _llseek(fd.hf, 0, 0);
  161. _lwrite(fd.hf, (LPCSTR) g_pcszHeader, lstrlen(g_pcszHeader)+1);
  162. ErrMsg1("Removed older NetMeeting INF", 0);
  163. }
  164. break;
  165. }
  166. }
  167. _lclose(fd.hf);
  168. }
  169. /* F I X S U B A S E */
  170. /*-------------------------------------------------------------------------
  171. %%Function: FixSubase
  172. Delete the line from subase.inf that deletes the NetMeeting link.
  173. See NM4DB bug 5937, Win98 bug 65154.
  174. This code shouldn't be necessary with Win98 SP1 and later.
  175. -------------------------------------------------------------------------*/
  176. void FixSubase(void)
  177. {
  178. FD fd;
  179. char szLine[MAX_PATH];
  180. if (!FOpenFile(g_pcszInfSubase, &fd, FALSE))
  181. return;
  182. for ( ; ; ) // Find the section
  183. {
  184. if (0 == ReadLine(szLine, &fd))
  185. {
  186. break;
  187. }
  188. if (('[' == szLine[0]) && (0 == lstrcmp(szLine, g_pcszWinOther)))
  189. {
  190. ErrMsg1("Found the section at pos=%d", (LPVOID) fd.lPos);
  191. break;
  192. }
  193. }
  194. for ( ; ; ) // Find the line
  195. {
  196. LONG lPosPrev = fd.lPos; // Remember the start of the line
  197. if (0 == ReadLine(szLine, &fd))
  198. {
  199. break;
  200. }
  201. if (0 == lstrcmp(szLine, g_pcszNukeLink))
  202. {
  203. // comment out the line
  204. _llseek(fd.hf, lPosPrev, 0 /* FILE_BEGIN */);
  205. _lwrite(fd.hf, (LPCSTR) ";", 1);
  206. ErrMsg1("Commented out line at pos=%d", (LPVOID) lPosPrev);
  207. break;
  208. }
  209. if ('[' == szLine[0])
  210. {
  211. ErrMsg1("End of section? at pos=%d", (LPVOID) lPosPrev);
  212. break;
  213. }
  214. }
  215. _lclose(fd.hf);
  216. }
  217. /* N M M I G R A T I O N */
  218. /*-------------------------------------------------------------------------
  219. %%Function: NmMigration
  220. This is called by the Windows 98 setup system.
  221. -------------------------------------------------------------------------*/
  222. DWORD FAR PASCAL NmMigration(DWORD dwStage, LPSTR lpszParams, LPARAM lParam)
  223. {
  224. Reference(lpszParams);
  225. Reference(lParam);
  226. ErrMsg2("NM Build=[%s] stage=%08X", lpszParams, (LPVOID) dwStage);
  227. switch (dwStage)
  228. {
  229. case SU_MIGRATE_PREINFLOAD:
  230. {
  231. RemoveInf();
  232. FixSubase();
  233. break;
  234. }
  235. default:
  236. break;
  237. }
  238. return 0;
  239. }