diff options
| author | a1xd <[email protected]> | 2020-07-22 19:34:13 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-07-22 19:34:13 -0400 |
| commit | 78156f34166c110fcad47aef166684b8e25ac4fa (patch) | |
| tree | b6121a5e1725639800c266c865f9067b3cd31a17 /installer | |
| parent | Add .gitignore and .gitattributes. (diff) | |
| download | rawaccel-78156f34166c110fcad47aef166684b8e25ac4fa.tar.xz rawaccel-78156f34166c110fcad47aef166684b8e25ac4fa.zip | |
Add project files.v0.1-test
Diffstat (limited to 'installer')
| -rw-r--r-- | installer/installer.cpp | 80 | ||||
| -rw-r--r-- | installer/installer.vcxproj | 98 |
2 files changed, 178 insertions, 0 deletions
diff --git a/installer/installer.cpp b/installer/installer.cpp new file mode 100644 index 0000000..ac426af --- /dev/null +++ b/installer/installer.cpp @@ -0,0 +1,80 @@ +#include <iostream> + +#include <utility-install.hpp> + +void add_service(const fs::path& target) { + SC_HANDLE schSCManager = OpenSCManager( + NULL, // local computer + NULL, // ServicesActive database + SC_MANAGER_ALL_ACCESS // full access rights + ); + + if (schSCManager == NULL) throw std::runtime_error("OpenSCManager failed"); + + SC_HANDLE schService = CreateService( + schSCManager, // SCM database + DRIVER_NAME.c_str(), // name of service + DRIVER_NAME.c_str(), // service name to display + SERVICE_ALL_ACCESS, // desired access + SERVICE_KERNEL_DRIVER, // service type + SERVICE_DEMAND_START, // start type + SERVICE_ERROR_NORMAL, // error control type + target.c_str(), // path to service's binary + NULL, // no load ordering group + NULL, // no tag identifier + NULL, // no dependencies + NULL, // LocalSystem account + NULL // no password + ); + + if (schService) { + CloseServiceHandle(schService); + CloseServiceHandle(schSCManager); + return; + } + + if (auto err = GetLastError(); err != ERROR_SERVICE_EXISTS) { + CloseServiceHandle(schSCManager); + throw std::runtime_error("CreateService failed"); + } +} + +int main() { + try { + fs::path source = fs::path(L"driver") / DRIVER_FILE_NAME; + + if (!fs::exists(source)) { + throw std::runtime_error(source.generic_string() + " does not exist"); + } + + fs::path target = get_target_path(); + + add_service(target); + + fs::path tmp = make_temp_path(target); + + // schedule tmp to be deleted if rename target -> tmp is successful + if (MoveFileExW(target.c_str(), tmp.c_str(), MOVEFILE_REPLACE_EXISTING)) { + MoveFileExW(tmp.c_str(), NULL, MOVEFILE_DELAY_UNTIL_REBOOT); + } + + fs::copy_file(source, target, fs::copy_options::overwrite_existing); + + modify_upper_filters([](std::vector<std::wstring>& filters) { + auto driver_pos = std::find(filters.begin(), filters.end(), DRIVER_NAME); + + if (driver_pos != filters.end()) return; + + auto mouclass_pos = std::find(filters.begin(), filters.end(), L"mouclass"); + filters.insert(mouclass_pos, DRIVER_NAME); + }); + + std::cout << "Install complete, change will take effect after restart.\n"; + } + catch (std::exception e) { + std::cerr << "Error: " << e.what() << '\n'; + } + + std::cout << "Press any key to close this window . . .\n"; + _getwch(); +} diff --git a/installer/installer.vcxproj b/installer/installer.vcxproj new file mode 100644 index 0000000..45ef0c8 --- /dev/null +++ b/installer/installer.vcxproj @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>16.0</VCProjectVersion> + <ProjectGuid>{896950D1-520A-420A-B6B1-73014B92A68C}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>installer</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + <Import Project="..\common-install\common-install.vcxitems" Label="Shared" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level4</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories> + <LanguageStandard>stdcpplatest</LanguageStandard> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <UACExecutionLevel>RequireAdministrator</UACExecutionLevel> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level4</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <LanguageStandard>stdcpplatest</LanguageStandard> + <InlineFunctionExpansion>Default</InlineFunctionExpansion> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + <UACExecutionLevel>RequireAdministrator</UACExecutionLevel> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="installer.cpp" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file |