-
Notifications
You must be signed in to change notification settings - Fork 142
/
UsbDkInstHelper.cpp
136 lines (118 loc) · 3.9 KB
/
UsbDkInstHelper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**********************************************************************
* Copyright (c) 2013-2014 Red Hat, Inc.
*
* Developed by Daynix Computing LTD.
*
* Authors:
* Dmitry Fleytman <[email protected]>
* Pavel Gurvich <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************/
#include "stdafx.h"
#include "UsbDkHelper.h"
using namespace std;
static BOOL suppressInstallMessageBox = FALSE;
static int Controller_InstallDriver()
{
//Clean up any previous versions before reinstalling
UsbDk_UninstallDriver();
auto res = UsbDk_InstallDriver();
switch (res)
{
case InstallSuccess:
return 0;
case InstallFailure:
return 1;
case InstallAborted:
if (!suppressInstallMessageBox)
{
MessageBox(NULL,
TEXT("Failed to start the driver on the system, installation aborted!\nPlease make sure you are installing a signed version of UsbDk or else try to disable \"driver signature enforcement\" on the system"),
TEXT("UsbDk Runtime Libraries Installer"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL);
}
else
{
OutputDebugString(TEXT("UsbDkInstHelper: Installation aborted"));
}
return 4;
case InstallSuccessNeedReboot:
if (!suppressInstallMessageBox)
{
MessageBox(NULL,
TEXT("Please restart your computer to complete the installation"),
TEXT("UsbDk Runtime Libraries Installer"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL);
}
else
{
OutputDebugString(TEXT("UsbDkInstHelper: reboot required to complete the installation"));
}
return 0;
default:
assert(0);
return 3;
}
}
static int Controller_UninstallDriver()
{
return UsbDk_UninstallDriver() ? 0 : 1;
}
static bool _ChdirToPackageFolder()
{
TCHAR PackagePath[MAX_PATH];
auto Length = GetModuleFileName(NULL, PackagePath, ARRAY_SIZE(PackagePath));
if ((Length == 0) || (Length == ARRAY_SIZE(PackagePath)))
{
OutputDebugString(TEXT("UsbDkInstHelper: Failed to get executable path."));
return false;
}
if (!PathRemoveFileSpec(PackagePath))
{
OutputDebugString(TEXT("UsbDkInstHelper: Failed to get package directory."));
return false;
}
if (!SetCurrentDirectory(PackagePath))
{
OutputDebugString(TEXT("UsbDkInstHelper: Failed to make package directory current"));
return false;
}
return true;
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
if (!_ChdirToPackageFolder())
{
return -1;
}
if (lpCmdLine[0] == 'i')
{
if (lpCmdLine[1] == 'n' || lpCmdLine[1] == 'N')
{
suppressInstallMessageBox = TRUE;
}
OutputDebugString(TEXT("UsbDkInstHelper: Install"));
return Controller_InstallDriver();
}
if (lpCmdLine[0] == 'u')
{
OutputDebugString(TEXT("UsbDkInstHelper: Uninstall"));
return Controller_UninstallDriver();
}
OutputDebugString(TEXT("UsbDkInstHelper: Wrong command line"));
return -2;
}