Windows NT 4.0 source code leak
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.

586 lines
9.6 KiB

4 years ago
  1. /* Setup Instatllation Program
  2. * (C) Copyright 1987 by Microsoft
  3. * Written By Steven Zeck
  4. *
  5. * This module constains all the system specific code (DOS, OS/2, XENIX)
  6. *************************************************************************/
  7. #if !defined(OS2) && !defined(DOS)
  8. #define OS2
  9. #endif
  10. #include "core.h"
  11. #include <crtapi.h>
  12. #undef TRUE
  13. #if defined(DOS)
  14. #include <dos.h>
  15. extern int pascal int10 (void * regs);
  16. #define TRUE 1
  17. #elif defined(OS2)
  18. #define INCL_DOS
  19. #define INCL_VIO
  20. #include <os2def.h>
  21. #include <bsedos.h>
  22. #include <bsesub.h>
  23. FILEFINDBUF findBuff;
  24. #endif
  25. UINT cCrtLineMax = 25; /* number of lines on crt */
  26. UCHAR oldCrtAttr;
  27. /* readFar - a untranslated file into memory
  28. *
  29. * Inputs
  30. * open file handle
  31. * Far buffer to place file
  32. * Returns
  33. *
  34. ****************************************************************************/
  35. UINT pascal readFar (fh, pFarBuff, cb)
  36. int fh;
  37. char far *pFarBuff;
  38. UINT cb;
  39. {
  40. UINT cbRead;
  41. #if defined(DOS)
  42. if (_dos_read(fh, pFarBuff, cb, &cbRead))
  43. #elif defined(OS2)
  44. if (DosRead(fh, pFarBuff, cb, &cbRead))
  45. #endif
  46. terminate("Error reading file");
  47. return (cbRead);
  48. }
  49. UINT pascal writeFar (fh, pFarBuff, cb)
  50. int fh;
  51. char far *pFarBuff;
  52. UINT cb;
  53. {
  54. UINT cbWritten;
  55. #if defined(DOS)
  56. if (_dos_write(fh, pFarBuff, cb, &cbWritten) || cbWritten != cb)
  57. #elif defined(OS2)
  58. if (DosWrite(fh, pFarBuff, cb, &cbWritten) || cbWritten != cb)
  59. #endif
  60. terminate("not enough diskspace for files.");
  61. return (cbWritten);
  62. }
  63. /* setCreateDate - Make creation date of two files equal
  64. *
  65. * Inputs
  66. * Open file handles of files
  67. * Returns
  68. ****************************************************************************/
  69. void pascal setCreateDate(fhFrom, fhTo)
  70. int fhFrom;
  71. int fhTo;
  72. {
  73. #if defined(DOS)
  74. UINT time, date;
  75. _dos_getftime(fhFrom, &date, &time);
  76. _dos_setftime(fhTo, date, time);
  77. #elif defined(OS2)
  78. FILESTATUS aFileInfo;
  79. DosQFileInfo(fhFrom, 1, (PBYTE) &aFileInfo, sizeof(aFileInfo));
  80. DosSetFileInfo(fhTo, 1, (PBYTE) &aFileInfo, sizeof(aFileInfo));
  81. #endif
  82. }
  83. write(fh, pBuff, cb)
  84. char *pBuff;
  85. {
  86. return (writeFar(fh, pBuff, cb));
  87. }
  88. /* fileAttrFet - fet a files attributes
  89. *
  90. * Inputs
  91. * File name to fetch
  92. * Returns
  93. * word of file attributes
  94. *
  95. ****************************************************************************/
  96. UINT pascal fileAttrFet( pFileName)
  97. pSZ pFileName;
  98. {
  99. UINT attr;
  100. #if defined(DOS)
  101. attr = 0x8000;
  102. _dos_getfileattr(pFileName, &attr);
  103. #elif defined(OS2)
  104. if (DosQFileMode(pFileName, &attr, 0L))
  105. return (0x8000);
  106. #endif
  107. return(attr);
  108. }
  109. /* getFirstFile/getNextFile - read through a directory
  110. *
  111. * Inputs
  112. * A pattern of files to search for
  113. * a return buffer to store file name
  114. * Returns
  115. *
  116. ****************************************************************************/
  117. Bool pascal getFristFile(pPath, FindHandle)
  118. pSZ pPath;
  119. FILEFILE *FindHandle;
  120. {
  121. #if defined(DOS)
  122. if (!_dos_findfirst(pPath, _A_NORMAL | _A_RDONLY | _A_ARCH | _A_SUBDIR,
  123. (struct find_t *) FindHandle)){
  124. strcpy(strrchr(pPath, '\\')+1, ((struct find_t *) FindHandle)->name);
  125. return(TRUE);
  126. #elif defined(OS2)
  127. int one = 1;
  128. FindHandle->dirHandle = HDIR_CREATE;
  129. if (! DosFindFirst(pPath, &FindHandle->dirHandle, FILE_NORMAL|FILE_READONLY|FILE_DIRECTORY|FILE_ARCHIVED,
  130. &findBuff, sizeof(findBuff), &one, 0L)) {
  131. strcpy(strrchr(pPath, '\\')+1, findBuff.achName);
  132. return(TRUE);
  133. #endif
  134. }
  135. else
  136. return(FALSE);
  137. }
  138. Bool pascal getNextFile(pNameOut, FindHandle)
  139. pSZ pNameOut;
  140. FILEFILE *FindHandle;
  141. {
  142. int one = 1;
  143. #if defined(DOS)
  144. if (!_dos_findnext((struct find_t *) FindHandle)){
  145. strcpy(strrchr(pNameOut, '\\')+1, ((struct find_t *) FindHandle)->name);
  146. return(TRUE);
  147. #elif defined(OS2)
  148. if (! DosFindNext(FindHandle->dirHandle, &findBuff, sizeof(findBuff), &one)) {
  149. strcpy(strrchr(pNameOut, '\\')+1, findBuff.achName);
  150. return(TRUE);
  151. #endif
  152. }
  153. else
  154. return(FALSE);
  155. }
  156. /* cdDrive - change drive
  157. *
  158. * Inputs
  159. * Drive letter to change to
  160. * Returns
  161. *
  162. ****************************************************************************/
  163. Bool pascal cdDrive(drive)
  164. UCHAR drive;
  165. {
  166. static UINT driveT;
  167. drive = (drive|0x20) - 'a' + 1;
  168. #if defined(DOS)
  169. _dos_setdrive(drive, &driveT);
  170. _dos_getdrive(&driveT);
  171. if (driveT != drive)
  172. #elif defined(OS2)
  173. if (DosSelectDisk(drive))
  174. #endif
  175. terminate("Couldn't change to drive");
  176. }
  177. /* volIDFet - Get the volumn ID of drive A
  178. *
  179. * Returns
  180. * Stores return in global
  181. *
  182. ****************************************************************************/
  183. void pascal volIDFet ()
  184. {
  185. struct { /* OS Query file system info structure */
  186. UINT date;
  187. UINT time;
  188. UCHAR cb;
  189. UCHAR name[32];
  190. } FSinfo;
  191. volId[0] = NIL;
  192. #if defined(DOS)
  193. {
  194. static char driveT[] = "A:\\*.*";
  195. struct find_t findBuff;
  196. driveT[0] = pCopyDrive->v.pVal[0];
  197. if (!_dos_findfirst(driveT, _A_VOLID, &findBuff)){
  198. strcpy(volId, findBuff.name);
  199. }
  200. }
  201. #elif defined(OS2)
  202. if (!DosQFSInfo((pCopyDrive->v.pVal[0]|0x20) - 'a' + 1,
  203. 2, (char far *) &FSinfo, sizeof(FSinfo)))
  204. strcpy(volId, FSinfo.name);
  205. #endif
  206. }
  207. /* FreeSpaceFet - Get the free space on the reguest drive
  208. *
  209. * Returns
  210. * number of 10K bytes free
  211. *
  212. ****************************************************************************/
  213. UINT pascal freeSpaceFet (drive)
  214. UCHAR drive;
  215. {
  216. UINT cbFree = 0;
  217. drive = (drive|0x20) - 'a' + 1;
  218. #if defined(DOS)
  219. {
  220. union REGS regs;
  221. regs.h.ah = 0x36;
  222. regs.h.dl = drive;
  223. RpcInt86(0x21, &regs, &regs);
  224. if (regs.x.ax != -1)
  225. cbFree = ((long) regs.x.cx * regs.x.ax * regs.x.bx) / 10000L;
  226. }
  227. #elif defined(OS2)
  228. {
  229. FSALLOCATE aFS;
  230. if (! DosQFSInfo(drive, 1, (char far *)&aFS, sizeof(aFS)))
  231. cbFree = (long) aFS.cSectorUnit * aFS.cbSector * aFS.cUnitAvail / 10000L;
  232. }
  233. #endif
  234. return (cbFree);
  235. }
  236. /* fillCrt - write fill character to the screen
  237. *
  238. * Inputs
  239. * top row and column
  240. * bottom row and column
  241. * attribute to fill with
  242. * character to write
  243. *
  244. ****************************************************************************/
  245. void pascal fillCrt( tRow, tCol, bRow, bCol, attr, fill)
  246. int tRow, tCol;
  247. int bRow, bCol;
  248. UCHAR attr;
  249. char fill;
  250. {
  251. char cell[2];
  252. #if defined(DOS)
  253. union REGS regs;
  254. moveTo(tRow, tCol);
  255. regs.h.ah = 9;
  256. regs.h.al = fill;
  257. regs.h.bh = 0;
  258. regs.h.bl = attr;
  259. regs.x.cx = bCol-tCol + (bRow - tRow)*80 + 1;
  260. int10(&regs);
  261. #elif defined(OS2)
  262. cell[0] = fill;
  263. cell[1] = attr;
  264. VioWrtNCell(cell, bCol-tCol + (bRow - tRow)*80 + 1, tRow-1, tCol-1, 0);
  265. #endif
  266. }
  267. void pascal moveTo (row, column)
  268. int row, column;
  269. {
  270. #if defined(DOS)
  271. union REGS regs;
  272. regs.h.ah = 2;
  273. regs.h.bh = 0;
  274. regs.h.dh = row-1;
  275. regs.h.dl = column-1;
  276. int10(&regs);
  277. #elif defined(OS2)
  278. VioSetCurPos(row-1, column-1, 0);
  279. #endif
  280. }
  281. /* charOut - write a charactor to the output screen
  282. *
  283. * Inputs
  284. * row and column
  285. * text to write
  286. *
  287. ****************************************************************************/
  288. void pascal charOut (row, column, ch)
  289. int row, column;
  290. char ch;
  291. {
  292. char rgCh[2];
  293. rgCh[0] = ch;
  294. rgCh[1] = NIL;
  295. textOut(row, column, rgCh);
  296. }
  297. /* textOut - write text to the output screen
  298. *
  299. * Inputs
  300. * row and column
  301. * text to write
  302. *
  303. ****************************************************************************/
  304. void pascal textOut (row, column, pText)
  305. int row, column;
  306. pSZ pText;
  307. {
  308. #if defined(DOS)
  309. union REGS regs;
  310. moveTo(row, column);
  311. regs.h.ah = 9;
  312. regs.h.bh = 0;
  313. regs.h.bl = defCrtAttr;
  314. regs.x.cx = 1;
  315. while (*pText) {
  316. regs.h.al = *pText++;
  317. int10(&regs);
  318. moveTo(row, ++column);
  319. }
  320. #elif defined(OS2)
  321. int cb;
  322. cb = strlen(pText);
  323. VioWrtCharStrAtt(pText, cb, row-1, column-1, &defCrtAttr, 0);
  324. moveTo(row, column+cb);
  325. #endif
  326. }
  327. /* atrrOut - write attribute only to the output screen
  328. *
  329. * Inputs
  330. * row and column
  331. * length of attribute
  332. * and the attribute
  333. *
  334. ****************************************************************************/
  335. void pascal attrOut (row, column, cb, attr)
  336. int row, column;
  337. int cb;
  338. char attr;
  339. {
  340. #if defined(DOS)
  341. union REGS regs;
  342. regs.h.bl = attr;
  343. regs.h.bh = 0;
  344. regs.x.cx = 1;
  345. while (cb--) {
  346. moveTo(row, column++);
  347. // first get the current character
  348. regs.h.ah = 8;
  349. regs.h.al = int10(&regs);
  350. // then write the current char with a new attribute
  351. regs.h.ah = 9;
  352. int10(&regs);
  353. }
  354. #elif defined(OS2)
  355. VioWrtNAttr(&attr, cb, row-1, column-1, 0);
  356. #endif
  357. }
  358. void scrollUp()
  359. {
  360. char cell[2];
  361. #if defined(DOS)
  362. union REGS regs;
  363. regs.h.ah = 6;
  364. regs.h.al = 1;
  365. regs.h.bh = defCrtAttr;
  366. regs.x.cx = (*pSTCur->title)? 0x0200: 0;
  367. regs.h.dl = 79;
  368. regs.h.dh = curCrtLine-1;
  369. int10(&regs);
  370. #elif defined(OS2)
  371. cell[0] = ' ';
  372. cell[1] = defCrtAttr;
  373. VioScrollUp((*pSTCur->title)? 2: 0, 0, curCrtLine-1, 79, 1, cell, 0);
  374. #endif
  375. }
  376. /* get/reset CRT - do crt initialization and reset
  377. *
  378. * Inputs
  379. * Returns
  380. *
  381. ****************************************************************************/
  382. void resetCrt()
  383. {
  384. fillCrt(cCrtLineMax, 1, cCrtLineMax, 79, oldCrtAttr, ' ');
  385. moveTo(cCrtLineMax-1, 1);
  386. }
  387. void getCrt()
  388. {
  389. #if defined(DOS)
  390. union REGS regs;
  391. regs.h.ah = 0x8;
  392. regs.h.bh = 0;
  393. RpcInt86(0x10, &regs, &regs);
  394. defCrtAttr = oldCrtAttr = regs.h.ah;
  395. dispatcher("set protMode=0");
  396. #elif defined(OS2)
  397. char cell[2];
  398. int cbCell = sizeof(cell);
  399. VIOMODEINFO Viomi;
  400. Viomi.cb = sizeof(Viomi);
  401. VioGetMode(&Viomi, 0);
  402. cCrtLineMax = Viomi.row;
  403. VioReadCellStr(cell, &cbCell, 0, 0, 0);
  404. defCrtAttr = oldCrtAttr = cell[1];
  405. dispatcher("set protMode=1");
  406. #endif
  407. }