annotate vidix/dhahelperwin/dhasetup.c @ 31349:92d75e703bc0

Rename configure.log file to the more standard name config.log.
author diego
date Mon, 14 Jun 2010 15:17:48 +0000
parents 0f1b5b68af32
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26726
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
1 /*
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
2 * dhasetup - dhahelper setup program
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
3 *
26726
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
4 * Copyright (c) 2004 - 2007 Sascha Sommer (MPlayer)
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
5 *
26726
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
6 * some parts from dhasetup.c source code
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
7 * http://svn.tilp.info/cgi-bin/viewcvs.cgi/libticables/trunk/src/win32/dha/
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
8 *
26726
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
9 * Copyright (C) 2007 Romain Lievin (tilp)
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
10 *
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
11 * This file is part of MPlayer.
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
12 *
26726
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
13 * MPlayer is free software; you can redistribute it and/or modify
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
14 * it under the terms of the GNU General Public License as published by
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
15 * the Free Software Foundation; either version 2 of the License, or
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
16 * (at your option) any later version.
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
17 *
26726
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
18 * MPlayer is distributed in the hope that it will be useful,
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
21 * GNU General Public License for more details.
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
22 *
26726
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
23 * You should have received a copy of the GNU General Public License along
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
24 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
a1c020529cc0 Use standard license header with standard formatting.
diego
parents: 24542
diff changeset
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
26 */
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
27
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
28 #include <windows.h>
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
29 #include <stdio.h>
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
30 #include <winioctl.h>
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
31
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
32 static void print_last_error(char *s){
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
33 LPTSTR lpMsgBuf;
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
34
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
35 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
36 FORMAT_MESSAGE_FROM_SYSTEM |
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
37 FORMAT_MESSAGE_IGNORE_INSERTS,
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
38 NULL, GetLastError(),
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
39 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
40 (LPTSTR) & lpMsgBuf, 0, NULL);
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
41 if(strlen(lpMsgBuf) >= 2)
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
42 lpMsgBuf[strlen(lpMsgBuf)-2] = 0;
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
43
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
44 printf("%s (%i -> %s)\n", s, GetLastError(), lpMsgBuf);
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
45 LocalFree(lpMsgBuf);
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
46 }
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
47
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
48 int main(int argc,char* argv[]){
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
49 SC_HANDLE hSCManager = NULL;
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
50 SC_HANDLE hService = NULL;
12058
faust3
parents: 12057
diff changeset
51 char path[MAX_PATH];
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
52 printf("dhasetup (c) 2004 Sascha Sommer\n");
12098
73ee9bd3b537 Error message improved, wording.
diego
parents: 12058
diff changeset
53 GetWindowsDirectory(path,MAX_PATH);
73ee9bd3b537 Error message improved, wording.
diego
parents: 12058
diff changeset
54 strcpy(path+strlen(path),"\\system32\\drivers\\dhahelper.sys");
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
55 if(argc==1){
12098
73ee9bd3b537 Error message improved, wording.
diego
parents: 12058
diff changeset
56 printf("Usage:\n");
73ee9bd3b537 Error message improved, wording.
diego
parents: 12058
diff changeset
57 printf("dhasetup install - Copies dhahelper.sys from the current directory to\n%s and configures it to start at boot.\n", path);
73ee9bd3b537 Error message improved, wording.
diego
parents: 12058
diff changeset
58 printf("dhasetup remove - Removes the dhahelper utility.\n");
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
59 return 0;
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
60 }
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
61 hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
62 if(!strcmp(argv[1],"install")){
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
63 printf("Installing dhahelper...");
12453
faust3
parents: 12452
diff changeset
64 if(!CopyFile("dhahelper.sys",path,FALSE)){
12098
73ee9bd3b537 Error message improved, wording.
diego
parents: 12058
diff changeset
65 printf("Copying dhahelper.sys failed.\nEither dhahelper.sys is not in the current directory or you lack sufficient\nprivileges to write to %s.", path);
73ee9bd3b537 Error message improved, wording.
diego
parents: 12058
diff changeset
66 return 1;
12453
faust3
parents: 12452
diff changeset
67 }
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
68 // Install the driver
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
69 hService = CreateService(hSCManager,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
70 "DHAHELPER",
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
71 "DHAHELPER",
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
72 SERVICE_ALL_ACCESS,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
73 SERVICE_KERNEL_DRIVER,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
74 SERVICE_SYSTEM_START,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
75 SERVICE_ERROR_NORMAL,
12058
faust3
parents: 12057
diff changeset
76 path,
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
77 NULL,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
78 NULL,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
79 NULL,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
80 NULL,
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
81 NULL);
12450
238820c0ee48 report if the service creation failed
faust3
parents: 12098
diff changeset
82 if(!hService){
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
83 print_last_error("Unable to register DhaHelper Service");
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
84 return 1;
12450
238820c0ee48 report if the service creation failed
faust3
parents: 12098
diff changeset
85 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26726
diff changeset
86
24542
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
87 if(!StartService(hService, 0, NULL)){
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
88 print_last_error("Error while starting service");
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
89 return 1;
a36693ffbb17 it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents: 24540
diff changeset
90 }
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
91
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
92 printf("Success!\n");
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
93 }
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
94 else if(!strcmp(argv[1],"remove")){
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
95 SERVICE_STATUS ServiceStatus;
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
96
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
97 printf("Removing dhahelper... ");
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
98 hService = OpenService(hSCManager, "DHAHELPER", SERVICE_ALL_ACCESS);
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
99 if(!hService){
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
100 print_last_error("Error opening dhahelper service");
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
101 return 1;
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
102 }
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
103 if(!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
104 print_last_error("Error while stopping service");
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
105 if(!DeleteService(hService))
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
106 print_last_error("Error while deleting service");
12058
faust3
parents: 12057
diff changeset
107 DeleteFile(path);
24540
40a61e5ef8ca Make dhasetup more verbose based on code by
faust3
parents: 22900
diff changeset
108 printf("Done!\n");
12057
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
109 }
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
110 else {
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
111 printf("unknown parameter: %s\n",argv[1]);
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
112 }
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
113 CloseServiceHandle(hService);
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
114 CloseServiceHandle(hSCManager);
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
115 return 0;
0f058e9cd422 Windows XP support
faust3
parents:
diff changeset
116 }