Add optional command-line parameter to suppress message box in case the installation requires reboot or aborted. This supports use case when the UsbDk is installed along with other product and restart is required regardless installation status of UsbDk. When installation helper runs with -in or -iN, the message boxes are suppressed. Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
136 lines
3.9 KiB
C++
136 lines
3.9 KiB
C++
/**********************************************************************
|
|
* Copyright (c) 2013-2014 Red Hat, Inc.
|
|
*
|
|
* Developed by Daynix Computing LTD.
|
|
*
|
|
* Authors:
|
|
* Dmitry Fleytman <dmitry@daynix.com>
|
|
* Pavel Gurvich <pavel@daynix.com>
|
|
*
|
|
* 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;
|
|
}
|