source: contrib/installer/uninstall/insthlp.cpp@ 406

Last change on this file since 406 was 406, checked in by Brendan Oakley, 17 years ago

New install/uninstall src, from Lars

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1#include "insthlp.h"
2
3char errBuf[1024]={0};
4char strBuf[1024]={0};
5char retBuf[MAX_DEVICE_NAME]={0};
6
7BOOL DeleteDevices(ULONG ulDevType,PSZ devInstallName)
8{
9 MCI_SYSINFO_PARMS sysParms={0};
10 ULONG rc = NO_ERROR;
11 BOOL fRC = FALSE;
12
13 memset(&sysParms,0,sizeof(sysParms));
14 sysParms.usDeviceType = ulDevType;
15 sysParms.pszReturn = retBuf;
16 sysParms.ulRetSize = sizeof(retBuf);
17 rc = mciSendCommand(0,MCI_SYSINFO,MCI_SYSINFO_QUANTITY|MCI_WAIT,&sysParms,0);
18 mciGetErrorString(rc,errBuf,sizeof(errBuf));
19 printf("Get Num installed Drvs for %s, rc:%s\n",devInstallName,errBuf);
20 if (LOUSHORT(rc) == MCIERR_SUCCESS)
21 {
22 ULONG i;
23 ULONG ulNumDevices = atoi(sysParms.pszReturn);
24 for (i=0;i<ulNumDevices;i++)
25 {
26 memset(&sysParms,0,sizeof(sysParms));
27 sysParms.usDeviceType = ulDevType;
28 sysParms.ulNumber = i;
29 sysParms.pszReturn = retBuf;
30 sysParms.ulRetSize = sizeof(retBuf);
31
32 rc = mciSendCommand(0,MCI_SYSINFO,MCI_SYSINFO_INSTALLNAME|MCI_WAIT,&sysParms,0);
33 mciGetErrorString(rc,errBuf,sizeof(errBuf));
34 printf("Get Drv instance name for %s, rc:%s\n",sysParms.pszReturn,errBuf);
35 if (LOUSHORT(rc) == MCIERR_SUCCESS && strstr(sysParms.pszReturn,devInstallName))
36 {
37 sysParms.ulItem = MCI_SYSINFO_DELETE_DRIVER;
38 sysParms.pSysInfoParm = sysParms.pszReturn;
39 rc = mciSendCommand(0,MCI_SYSINFO,MCI_SYSINFO_ITEM|MCI_WAIT,&sysParms,0);
40 mciGetErrorString(rc,errBuf,sizeof(errBuf));
41 printf("Del Drv instance %s, rc:%s\n",sysParms.pszReturn,errBuf);
42 fRC = (LOUSHORT(rc) == MCIERR_SUCCESS);
43 }
44 }
45 }
46 return fRC;
47}
48
49BOOL UpdateMMPM2Ini(VOID)
50{
51 MCI_SYSINFO_PARMS sysParms={0};
52 ULONG rc;
53
54 rc = mciSendCommand(0,MCI_SYSINFO,MCI_SYSINFO_INI_LOCK|MCI_WAIT,&sysParms,0);
55 mciGetErrorString(rc,errBuf,sizeof(errBuf));
56 printf("Locking MMPM2.INI, rc:%s\n",errBuf);
57 return (LOUSHORT(rc) == MCIERR_SUCCESS);
58}
59
60BOOL DeleteConfigSysEntries(ULONG ulNum,PAPSZ StringArray)
61{
62 CHAR szLine[1024];
63 CHAR szPath[CCHMAXPATH+4];
64 APIRET rc=NO_ERROR;
65 ULONG ulBootDrive=0,i=0;
66 FILE *fp=NULL,*fptmp=NULL;
67 BOOL fFound=FALSE,fRC = FALSE;
68 CHAR cBootDrive[_MAX_DRIVE]={0};
69
70 for (i=0;i<ulNum;i++)
71 {
72 sscanf(*StringArray[i],"%*[^\\]%[^ ]",szLine);
73 strcpy(*StringArray[i],szLine);
74 }
75
76 rc = DosQuerySysInfo(QSV_BOOT_DRIVE,QSV_BOOT_DRIVE,&ulBootDrive,sizeof(ulBootDrive));
77 if (rc == NO_ERROR)
78 {
79 cBootDrive[0] = 'A'+ulBootDrive-1;
80 _makepath(szPath,cBootDrive,"\\","CONFIG","SYS");
81 fp = fopen(szPath,"rb");
82 fptmp = tmpfile();
83 if (fp && fptmp)
84 {
85 while(!feof(fp))
86 {
87 if (fgets(strBuf,sizeof(strBuf)-1,fp))
88 {
89 fFound=FALSE;
90 for (i=0;i<ulNum;i++)
91 {
92 if (strstr(strBuf,*StringArray[i]))
93 {
94 fFound = TRUE;
95 break;
96 }
97 }
98 if (!fFound)
99 {
100 fputs(strBuf,fptmp);
101 }
102 }
103 }
104 fclose(fp);
105 fseek(fptmp,0,SEEK_SET);
106
107 fp = fopen(szPath,"wb");
108 while(!feof(fptmp))
109 {
110 if (fgets(strBuf,sizeof(strBuf)-1,fptmp))
111 {
112 fputs(strBuf,fp);
113 }
114 }
115 fRC = TRUE;
116 }
117 if (fp) fclose(fp);
118 if (fptmp) fclose(fptmp);
119 }
120 return fRC;
121}
122
123BOOL RebootSystem(VOID)
124{
125 HFILE hDriver = NULLHANDLE;
126 ULONG ulAction=0;
127 APIRET rc = NO_ERROR;
128 BOOL fRC = FALSE;
129
130 rc = DosOpen(
131 "\\DEV\\DOS$",
132 &hDriver,
133 &ulAction,
134 0,
135 FILE_NORMAL,
136 OPEN_ACTION_OPEN_IF_EXISTS,
137 OPEN_SHARE_DENYNONE|OPEN_ACCESS_READWRITE,
138 NULL);
139 if (rc == NO_ERROR)
140 {
141 rc = DosShutdown(0);
142 if (rc == NO_ERROR)
143 {
144 rc = DosDevIOCtl(
145 hDriver,
146 IOCTL_DOS,
147 DOS_REBOOT,
148 NULL,
149 0,
150 NULL,
151 NULL,
152 0,
153 NULL);
154 fRC = (rc == NO_ERROR);
155 }
156 }
157 if (hDriver)
158 {
159 rc = DosClose(hDriver);
160 }
161 return fRC;
162}
163
164
Note: See TracBrowser for help on using the repository browser.