Refactored utilities
This commit is contained in:
Родитель
b739324e81
Коммит
f0ec7b6a1e
13
Demos.sln
13
Demos.sln
|
@ -1,14 +1,12 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27004.2010
|
||||
VisualStudioVersion = 15.0.27130.2024
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DownloadDemo", "demos\download\DownloadDemo.vcxproj", "{1C3574A4-C647-4B24-A713-E3DE99822D3B}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFC.Controls", "controls\MFC.Controls.vcxproj", "{5936EB01-037A-4148-A512-DAD975C24CBD}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFC.Language", "language\MFC.Language.vcxproj", "{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua", "lua\Lua.vcxproj", "{D3051AAC-8129-45F9-A755-9CBB7C61D91D}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TinyXml2", "tinyxml2\TinyXml2.vcxproj", "{284538AC-D315-437E-AD31-D40934A43236}"
|
||||
|
@ -45,14 +43,6 @@ Global
|
|||
{5936EB01-037A-4148-A512-DAD975C24CBD}.Release|Win32.Build.0 = Release|Win32
|
||||
{5936EB01-037A-4148-A512-DAD975C24CBD}.Release|x64.ActiveCfg = Release|x64
|
||||
{5936EB01-037A-4148-A512-DAD975C24CBD}.Release|x64.Build.0 = Release|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|x64.Build.0 = Debug|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|Win32.Build.0 = Release|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|x64.ActiveCfg = Release|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|x64.Build.0 = Release|x64
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D}.Debug|x64.ActiveCfg = Debug|x64
|
||||
|
@ -92,7 +82,6 @@ Global
|
|||
GlobalSection(NestedProjects) = preSolution
|
||||
{1C3574A4-C647-4B24-A713-E3DE99822D3B} = {B5F9E73F-AD05-4D70-898D-3B8920DCAC9A}
|
||||
{5936EB01-037A-4148-A512-DAD975C24CBD} = {BE196BF6-C664-44D4-8863-85FC76FAD89A}
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE} = {BE196BF6-C664-44D4-8863-85FC76FAD89A}
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D} = {BE196BF6-C664-44D4-8863-85FC76FAD89A}
|
||||
{284538AC-D315-437E-AD31-D40934A43236} = {BE196BF6-C664-44D4-8863-85FC76FAD89A}
|
||||
{4B291D95-C2CA-49E3-9EB5-B9F855D32AA0} = {BE196BF6-C664-44D4-8863-85FC76FAD89A}
|
||||
|
|
|
@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.27130.2024
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFC.Controls", "controls\MFC.Controls.vcxproj", "{5936EB01-037A-4148-A512-DAD975C24CBD}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFC.Language", "language\MFC.Language.vcxproj", "{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua", "lua\Lua.vcxproj", "{D3051AAC-8129-45F9-A755-9CBB7C61D91D}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TinyXml2", "tinyxml2\TinyXml2.vcxproj", "{284538AC-D315-437E-AD31-D40934A43236}"
|
||||
|
@ -37,14 +35,6 @@ Global
|
|||
{5936EB01-037A-4148-A512-DAD975C24CBD}.Release|Win32.Build.0 = Release|Win32
|
||||
{5936EB01-037A-4148-A512-DAD975C24CBD}.Release|x64.ActiveCfg = Release|x64
|
||||
{5936EB01-037A-4148-A512-DAD975C24CBD}.Release|x64.Build.0 = Release|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Debug|x64.Build.0 = Debug|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|Win32.Build.0 = Release|Win32
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|x64.ActiveCfg = Release|x64
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}.Release|x64.Build.0 = Release|x64
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D}.Debug|x64.ActiveCfg = Debug|x64
|
||||
|
@ -91,7 +81,6 @@ Global
|
|||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{5936EB01-037A-4148-A512-DAD975C24CBD} = {3340709D-0389-4D49-9960-4281CB30F1E4}
|
||||
{8F02F1BD-9F9F-439C-9686-3961C64FC8EE} = {3340709D-0389-4D49-9960-4281CB30F1E4}
|
||||
{D3051AAC-8129-45F9-A755-9CBB7C61D91D} = {3340709D-0389-4D49-9960-4281CB30F1E4}
|
||||
{284538AC-D315-437E-AD31-D40934A43236} = {3340709D-0389-4D49-9960-4281CB30F1E4}
|
||||
{4B291D95-C2CA-49E3-9EB5-B9F855D32AA0} = {3340709D-0389-4D49-9960-4281CB30F1E4}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "MainApp.h"
|
||||
#include "MainDlg.h"
|
||||
#include "afxdialogex.h"
|
||||
#include <string>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
|
@ -85,10 +86,12 @@ void CMainDlg::Download()
|
|||
CString szPath;
|
||||
m_UrlEdit.GetWindowText(szUrl);
|
||||
m_PathEdit.GetWindowText(szPath);
|
||||
m_Download.Download(szUrl, szPath,
|
||||
[this](int nProgress, CString szStatus)
|
||||
m_Download.Download(
|
||||
std::wstring(CT2CW(szUrl)),
|
||||
std::wstring(CT2CW(szPath)),
|
||||
[this](int nProgress, std::wstring szStatus)
|
||||
{
|
||||
this->m_ProgressCtrl.SetPos(nProgress);
|
||||
m_EdtStatus.SetWindowText(szStatus);
|
||||
m_EdtStatus.SetWindowText(szStatus.c_str());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,249 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<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>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{8F02F1BD-9F9F-439C-9686-3961C64FC8EE}</ProjectGuid>
|
||||
<Keyword>MFCDLLProj</Keyword>
|
||||
<RootNamespace>MFCControls</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<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|Win32'">
|
||||
<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)'=='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|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>bin\$(Configuration)\$(Platform)\</OutDir>
|
||||
<IntDir>obj\$(Configuration)\$(Platform)\</IntDir>
|
||||
<IncludePath>..\;$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>bin\$(Configuration)\$(Platform)\</OutDir>
|
||||
<IntDir>obj\$(Configuration)\$(Platform)\</IntDir>
|
||||
<IncludePath>..\;$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>bin\$(Configuration)\$(Platform)\</OutDir>
|
||||
<IntDir>obj\$(Configuration)\$(Platform)\</IntDir>
|
||||
<IncludePath>..\;$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>bin\$(Configuration)\$(Platform)\</OutDir>
|
||||
<IntDir>obj\$(Configuration)\$(Platform)\</IntDir>
|
||||
<IncludePath>..\;$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<DisableSpecificWarnings>4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<ModuleDefinitionFile>
|
||||
</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<AdditionalDependencies>
|
||||
</AdditionalDependencies>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_WINDOWS;_DEBUG;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<DisableSpecificWarnings>4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<ModuleDefinitionFile>
|
||||
</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<AdditionalDependencies>
|
||||
</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DisableSpecificWarnings>4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<ModuleDefinitionFile>
|
||||
</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<AdditionalDependencies>
|
||||
</AdditionalDependencies>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_WINDOWS;NDEBUG;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DisableSpecificWarnings>4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<ModuleDefinitionFile>
|
||||
</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<AdditionalDependencies>
|
||||
</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="StdAfx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Language.h" />
|
||||
<ClInclude Include="LanguageContext.h" />
|
||||
<ClInclude Include="LanguageHelper.h" />
|
||||
<ClInclude Include="LanguagesList.h" />
|
||||
<ClInclude Include="StdAfx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\utilities\MFC.Utilities.vcxproj">
|
||||
<Project>{4b291d95-c2ca-49e3-9eb5-b9f855d32aa0}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Language.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LanguageHelper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LanguagesList.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LanguageContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="StdAfx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,4 +0,0 @@
|
|||
// Copyright (c) Wiesław Šoltés. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#include "StdAfx.h"
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright (c) Wiesław Šoltés. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef VC_EXTRALEAN
|
||||
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
|
||||
#endif
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
|
||||
|
||||
#include <afxwin.h> // MFC core and standard components
|
||||
#include <afxext.h> // MFC extensions
|
||||
|
||||
#ifndef _AFX_NO_OLE_SUPPORT
|
||||
#include <afxole.h> // MFC OLE classes
|
||||
#include <afxodlgs.h> // MFC OLE dialog classes
|
||||
#include <afxdisp.h> // MFC Automation classes
|
||||
#endif // _AFX_NO_OLE_SUPPORT
|
||||
|
||||
#ifndef _AFX_NO_DB_SUPPORT
|
||||
#include <afxdb.h> // MFC ODBC database classes
|
||||
#endif // _AFX_NO_DB_SUPPORT
|
||||
|
||||
#ifndef _AFX_NO_DAO_SUPPORT
|
||||
#include <afxdao.h> // MFC DAO database classes
|
||||
#endif // _AFX_NO_DAO_SUPPORT
|
||||
|
||||
#ifndef _AFX_NO_OLE_SUPPORT
|
||||
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
|
||||
#endif
|
||||
#ifndef _AFX_NO_AFXCMN_SUPPORT
|
||||
#include <afxcmn.h> // MFC support for Windows Common Controls
|
||||
#endif // _AFX_NO_AFXCMN_SUPPORT
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright (c) Wiesław Šoltés. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Including SDKDDKVer.h defines the highest available Windows platform.
|
||||
|
||||
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
||||
|
||||
#include <SDKDDKVer.h>
|
|
@ -225,10 +225,13 @@
|
|||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Utilities.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Download.h" />
|
||||
<ClInclude Include="Language.h" />
|
||||
<ClInclude Include="LanguageContext.h" />
|
||||
<ClInclude Include="LanguageHelper.h" />
|
||||
<ClInclude Include="LanguagesList.h" />
|
||||
<ClInclude Include="ListT.h" />
|
||||
<ClInclude Include="MapT.h" />
|
||||
<ClInclude Include="Pipe.h" />
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
<Filter Include="Header Files\IO">
|
||||
<UniqueIdentifier>{e957f4ae-f360-4fb1-ac06-249a04ae6b38}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Language">
|
||||
<UniqueIdentifier>{a6859b19-b54e-4767-8482-e1c8a0e43d7a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="targetver.h">
|
||||
|
@ -69,13 +72,22 @@
|
|||
<ClInclude Include="StringHelper.h">
|
||||
<Filter>Header Files\Strings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Language.h">
|
||||
<Filter>Header Files\Language</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LanguageContext.h">
|
||||
<Filter>Header Files\Language</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LanguageHelper.h">
|
||||
<Filter>Header Files\Language</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LanguagesList.h">
|
||||
<Filter>Header Files\Language</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="StdAfx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Utilities.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,546 +0,0 @@
|
|||
// Copyright (c) Wiesław Šoltés. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utilities.h"
|
||||
#include <Rpc.h>
|
||||
|
||||
namespace util
|
||||
{
|
||||
DWORD CountSetBits(ULONG_PTR bitMask)
|
||||
{
|
||||
DWORD LSHIFT = sizeof(ULONG_PTR) * 8 - 1;
|
||||
DWORD bitSetCount = 0;
|
||||
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
|
||||
DWORD i;
|
||||
|
||||
for (i = 0; i <= LSHIFT; ++i)
|
||||
{
|
||||
bitSetCount += ((bitMask & bitTest) ? 1 : 0);
|
||||
bitTest /= 2;
|
||||
}
|
||||
|
||||
return bitSetCount;
|
||||
}
|
||||
|
||||
int GetLogicalProcessorInformation(LogicalProcessorInformation* info)
|
||||
{
|
||||
LPFN_GLPI glpi;
|
||||
BOOL done = FALSE;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = nullptr;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = nullptr;
|
||||
DWORD returnLength = 0;
|
||||
DWORD byteOffset = 0;
|
||||
PCACHE_DESCRIPTOR Cache;
|
||||
|
||||
glpi = (LPFN_GLPI)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformation");
|
||||
if (nullptr == glpi)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nGetLogicalProcessorInformation is not supported.\n"));
|
||||
#endif
|
||||
return (1);
|
||||
}
|
||||
|
||||
while (!done)
|
||||
{
|
||||
DWORD rc = glpi(buffer, &returnLength);
|
||||
if (FALSE == rc)
|
||||
{
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
|
||||
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(returnLength);
|
||||
if (nullptr == buffer)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nError: Allocation failure\n"));
|
||||
#endif
|
||||
return (2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nError %d\n"), GetLastError());
|
||||
#endif
|
||||
return (3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
done = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
ptr = buffer;
|
||||
|
||||
while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength)
|
||||
{
|
||||
switch (ptr->Relationship)
|
||||
{
|
||||
case RelationNumaNode:
|
||||
// Non-NUMA systems report a single record of this type.
|
||||
info->numaNodeCount++;
|
||||
break;
|
||||
case RelationProcessorCore:
|
||||
info->processorCoreCount++;
|
||||
// A hyperthreaded core supplies more than one logical processor.
|
||||
info->logicalProcessorCount += CountSetBits(ptr->ProcessorMask);
|
||||
break;
|
||||
case RelationCache:
|
||||
// Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache.
|
||||
Cache = &ptr->Cache;
|
||||
if (Cache->Level == 1)
|
||||
{
|
||||
info->processorL1CacheCount++;
|
||||
}
|
||||
else if (Cache->Level == 2)
|
||||
{
|
||||
info->processorL2CacheCount++;
|
||||
}
|
||||
else if (Cache->Level == 3)
|
||||
{
|
||||
info->processorL3CacheCount++;
|
||||
}
|
||||
break;
|
||||
case RelationProcessorPackage:
|
||||
// Logical processors share a physical package.
|
||||
info->processorPackageCount++;
|
||||
break;
|
||||
default:
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nError: Unsupported LOGICAL_PROCESSOR_RELATIONSHIP value.\n"));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nGetLogicalProcessorInformation results:\n"));
|
||||
_tprintf(_T("Number of NUMA nodes: %d\n"), info->numaNodeCount);
|
||||
_tprintf(_T("Number of physical processor packages: %d\n"), info->processorPackageCount);
|
||||
_tprintf(_T("Number of processor cores: %d\n"), info->processorCoreCount);
|
||||
_tprintf(_T("Number of logical processors: %d\n"), info->logicalProcessorCount);
|
||||
_tprintf(_T("Number of processor L1/L2/L3 caches: %d/%d/%d\n"),
|
||||
info->processorL1CacheCount,
|
||||
info->processorL2CacheCount,
|
||||
info->processorL3CacheCount);
|
||||
#endif
|
||||
|
||||
free(buffer);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ShutdownWindows()
|
||||
{
|
||||
HANDLE m_hToken;
|
||||
if (::OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &m_hToken))
|
||||
{
|
||||
LUID m_Luid;
|
||||
if (::LookupPrivilegeValue(nullptr, _T("SeShutdownPrivilege"), &m_Luid))
|
||||
{
|
||||
TOKEN_PRIVILEGES tp;
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Luid = m_Luid;
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
::AdjustTokenPrivileges(m_hToken, FALSE, &tp, 0, nullptr, nullptr);
|
||||
}
|
||||
::CloseHandle(m_hToken);
|
||||
}
|
||||
::ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, 0);
|
||||
::PostQuitMessage(0);
|
||||
}
|
||||
|
||||
void LaunchAndWait(const std::wstring& file, const std::wstring& params, BOOL bWait)
|
||||
{
|
||||
SHELLEXECUTEINFO sei;
|
||||
::ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
|
||||
sei.cbSize = sizeof(SHELLEXECUTEINFO);
|
||||
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
||||
// leave sei.lpVerb uninitialized for default action
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
sei.lpFile = file.c_str();
|
||||
sei.lpParameters = params.c_str();
|
||||
::ShellExecuteEx(&sei);
|
||||
if (bWait == TRUE)
|
||||
::WaitForSingleObject(sei.hProcess, INFINITE);
|
||||
::CloseHandle(sei.hProcess);
|
||||
}
|
||||
|
||||
void SetComboBoxHeight(HWND hDlg, int nComboBoxID, int nSizeLimit)
|
||||
{
|
||||
HWND hComboxBox = ::GetDlgItem(hDlg, nComboBoxID);
|
||||
if (hComboxBox != nullptr)
|
||||
::SendMessage(hComboxBox, CB_SETMINVISIBLE, (WPARAM)nSizeLimit, 0);
|
||||
}
|
||||
|
||||
std::wstring CombinePath(const std::wstring& szPath, const std::wstring& szFile)
|
||||
{
|
||||
std::wstring szOutputFile = szFile;
|
||||
if (szPath.length() >= 1)
|
||||
{
|
||||
auto cLast = szPath[szPath.length() - 1];
|
||||
if ((cLast == '\\') || (cLast == '/'))
|
||||
szOutputFile = szPath + szOutputFile;
|
||||
else
|
||||
szOutputFile = szPath + L"\\" + szOutputFile;
|
||||
}
|
||||
return szOutputFile;
|
||||
}
|
||||
|
||||
std::wstring GetFileName(const std::wstring& szFilePath)
|
||||
{
|
||||
return ::PathFindFileName(szFilePath.c_str());
|
||||
}
|
||||
|
||||
std::wstring GetFilePath(const std::wstring& szFilePath)
|
||||
{
|
||||
std::wstring szFileName = util::GetFileName(szFilePath);
|
||||
return szFilePath.substr(0, szFilePath.length() - szFileName.length());
|
||||
}
|
||||
|
||||
std::wstring GetFileExtension(const std::wstring& szFilePath)
|
||||
{
|
||||
std::wstring szExt = ::PathFindExtension(szFilePath.c_str());
|
||||
size_t pos = szExt.find('.');
|
||||
if (pos != std::string::npos)
|
||||
return szExt.substr(pos + 1, szExt.length() - 1);
|
||||
return szExt;
|
||||
}
|
||||
|
||||
std::wstring GetOnlyFileName(const std::wstring& szFilePath)
|
||||
{
|
||||
std::wstring szFileName = util::GetFileName(szFilePath);
|
||||
std::wstring szExt = util::GetFileExtension(szFilePath);
|
||||
return szFileName.substr(0, szFileName.length() - szExt.length());
|
||||
}
|
||||
|
||||
ULONGLONG GetFileSize64(HANDLE hFile)
|
||||
{
|
||||
ULARGE_INTEGER liSize;
|
||||
liSize.LowPart = ::GetFileSize(hFile, &liSize.HighPart);
|
||||
if (liSize.LowPart == (DWORD)-1)
|
||||
{
|
||||
if (::GetLastError() != NO_ERROR)
|
||||
return(0);
|
||||
}
|
||||
return liSize.QuadPart;
|
||||
}
|
||||
|
||||
ULONGLONG GetFileSize64(const std::wstring& szFileName)
|
||||
{
|
||||
WIN32_FIND_DATA FindFileData;
|
||||
HANDLE hFind;
|
||||
ULARGE_INTEGER ulSize;
|
||||
ULONGLONG nFileSize;
|
||||
|
||||
hFind = ::FindFirstFile(szFileName.c_str(), &FindFileData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return 0;
|
||||
|
||||
::FindClose(hFind);
|
||||
|
||||
ulSize.HighPart = FindFileData.nFileSizeHigh;
|
||||
ulSize.LowPart = FindFileData.nFileSizeLow;
|
||||
nFileSize = ulSize.QuadPart;
|
||||
|
||||
return nFileSize;
|
||||
}
|
||||
|
||||
__int64 GetFileSizeInt64(FILE *fp)
|
||||
{
|
||||
__int64 nCurPos, nSize;
|
||||
nCurPos = _ftelli64(fp);
|
||||
_fseeki64(fp, 0, SEEK_END);
|
||||
nSize = _ftelli64(fp);
|
||||
_fseeki64(fp, nCurPos, SEEK_SET);
|
||||
return nSize;
|
||||
}
|
||||
|
||||
std::wstring GetExeFilePath()
|
||||
{
|
||||
TCHAR szExeFilePath[MAX_PATH + 1] = _T("");
|
||||
DWORD dwRet = ::GetModuleFileName(::GetModuleHandle(nullptr), szExeFilePath, MAX_PATH);
|
||||
if (dwRet > 0)
|
||||
{
|
||||
std::wstring szTempBuff1 = szExeFilePath;
|
||||
std::wstring szTempBuff2 = util::GetFileName(szTempBuff1);
|
||||
return szTempBuff1.substr(0, szTempBuff1.length() - szTempBuff2.length());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::wstring GetSettingsFilePath(const std::wstring& szFileName, const std::wstring& szConfigDirectory)
|
||||
{
|
||||
TCHAR szPath[MAX_PATH];
|
||||
if (SUCCEEDED(SHGetFolderPath(nullptr,
|
||||
CSIDL_APPDATA | CSIDL_FLAG_CREATE,
|
||||
nullptr,
|
||||
0,
|
||||
szPath)))
|
||||
{
|
||||
PathAppend(szPath, szConfigDirectory.c_str());
|
||||
PathAppend(szPath, szFileName.c_str());
|
||||
return szPath;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::wstring GetFullPathName(const std::wstring& szFilePath)
|
||||
{
|
||||
TCHAR szFullPath[MAX_PATH + 2] = _T("");
|
||||
LPTSTR pszFilePos = nullptr;
|
||||
::GetFullPathName(szFilePath.c_str(), MAX_PATH + 1, szFullPath, &pszFilePos);
|
||||
return szFullPath;
|
||||
}
|
||||
|
||||
BOOL DirectoryExists(const std::wstring& szPath)
|
||||
{
|
||||
if (_taccess_s(szPath.c_str(), 0) == 0)
|
||||
{
|
||||
struct _stat status;
|
||||
_tstat(szPath.c_str(), &status);
|
||||
return (status.st_mode & S_IFDIR) != 0;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool MakeFullPath(const std::wstring& szTargetPath)
|
||||
{
|
||||
std::wstring szPath = szTargetPath;
|
||||
if (szPath[szPath.length() - 1] != '\\')
|
||||
szPath = szPath + L"\\";
|
||||
|
||||
std::wstring szTmpDir = szPath.substr(0, 2);
|
||||
_tchdir(szTmpDir.c_str());
|
||||
|
||||
int nStart = 3;
|
||||
int nEnd = 0;
|
||||
while (true)
|
||||
{
|
||||
nEnd = szPath.find('\\', nStart);
|
||||
if (nEnd == -1)
|
||||
return true;
|
||||
|
||||
std::wstring szNextDir = szPath.substr(nStart, nEnd - nStart);
|
||||
std::wstring szCurDir = szTmpDir + L"\\" + szNextDir;
|
||||
if (_tchdir(szCurDir.c_str()) != 0)
|
||||
{
|
||||
_tchdir(szTmpDir.c_str());
|
||||
if (_tmkdir(szNextDir.c_str()) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
szTmpDir += L"\\" + szNextDir;
|
||||
nStart = nEnd + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileExists(const std::wstring& szPath)
|
||||
{
|
||||
WIN32_FIND_DATA w32FileData;
|
||||
ZeroMemory(&w32FileData, sizeof(WIN32_FIND_DATA));
|
||||
HANDLE hFind = ::FindFirstFile(szPath.c_str(), &w32FileData);
|
||||
bool bInvalidHandle = hFind == INVALID_HANDLE_VALUE;
|
||||
::FindClose(hFind);
|
||||
return bInvalidHandle == false;
|
||||
}
|
||||
|
||||
std::wstring GenerateUuidString()
|
||||
{
|
||||
std::wstring strKey;
|
||||
UUID uuid;
|
||||
if (UuidCreate(&uuid) == RPC_S_OK)
|
||||
{
|
||||
RPC_WSTR szUuid;
|
||||
if (UuidToString(&uuid, &szUuid) == RPC_S_OK)
|
||||
{
|
||||
strKey = (LPTSTR)szUuid;
|
||||
strKey = util::StringHelper::ToUpper(strKey);
|
||||
RpcStringFree(&szUuid);
|
||||
}
|
||||
}
|
||||
return strKey;
|
||||
}
|
||||
|
||||
void ConvertAnsiToUnicode(const char *szAnsi, wchar_t *szUnicode, ULONG nLength)
|
||||
{
|
||||
// use always + 1 to null-terminate string
|
||||
_mbstowcsz(szUnicode, szAnsi, nLength + 1);
|
||||
}
|
||||
|
||||
void ConvertUnicodeToAnsi(const wchar_t *szUnicode, char *szAnsi, ULONG nLength)
|
||||
{
|
||||
// use always + 1 to null-terminate string
|
||||
_wcstombsz(szAnsi, szUnicode, nLength + 1);
|
||||
}
|
||||
|
||||
PTCHAR* MyCommandLineToArgv(PTCHAR pszCmdLine, int *pnArgc)
|
||||
{
|
||||
BOOLEAN bHaveQuotationMark, bHaveText, bHaveSpace;
|
||||
ULONG nLength, nArgc, nI, nJ;
|
||||
PTCHAR *pszArgv;
|
||||
PTCHAR pszTmpArgv;
|
||||
TCHAR cNext;
|
||||
|
||||
nLength = _tcslen(pszCmdLine);
|
||||
nI = ((nLength + 2) / 2) * sizeof(PVOID) + sizeof(PVOID);
|
||||
pszArgv = (PTCHAR *)GlobalAlloc(GMEM_FIXED, nI + (nLength + 2) * sizeof(TCHAR));
|
||||
pszTmpArgv = (PTCHAR)(((PUCHAR)pszArgv) + nI);
|
||||
nArgc = nI = nJ = 0;
|
||||
pszArgv[nArgc] = pszTmpArgv;
|
||||
bHaveQuotationMark = FALSE;
|
||||
bHaveText = FALSE;
|
||||
bHaveSpace = TRUE;
|
||||
|
||||
while (cNext = pszCmdLine[nI])
|
||||
{
|
||||
if (bHaveQuotationMark)
|
||||
{
|
||||
if (cNext == '\"')
|
||||
{
|
||||
bHaveQuotationMark = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
pszTmpArgv[nJ] = cNext;
|
||||
nJ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cNext == '\"')
|
||||
{
|
||||
bHaveQuotationMark = TRUE;
|
||||
bHaveText = TRUE;
|
||||
|
||||
if (bHaveSpace)
|
||||
{
|
||||
pszArgv[nArgc] = pszTmpArgv + nJ;
|
||||
nArgc++;
|
||||
}
|
||||
|
||||
bHaveSpace = FALSE;
|
||||
}
|
||||
else if ((cNext == ' ') || (cNext == '\t') || (cNext == '\n') || (cNext == '\r'))
|
||||
{
|
||||
if (bHaveText)
|
||||
{
|
||||
pszTmpArgv[nJ] = '\0';
|
||||
nJ++;
|
||||
}
|
||||
|
||||
bHaveText = FALSE;
|
||||
bHaveSpace = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bHaveText = TRUE;
|
||||
|
||||
if (bHaveSpace)
|
||||
{
|
||||
pszArgv[nArgc] = pszTmpArgv + nJ;
|
||||
nArgc++;
|
||||
}
|
||||
|
||||
pszTmpArgv[nJ] = cNext;
|
||||
nJ++;
|
||||
bHaveSpace = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
nI++;
|
||||
}
|
||||
|
||||
pszTmpArgv[nJ] = '\0';
|
||||
pszArgv[nArgc] = nullptr;
|
||||
(*pnArgc) = nArgc;
|
||||
|
||||
return pszArgv;
|
||||
}
|
||||
|
||||
bool Unzip2Folder(BSTR lpZipFile, BSTR lpFolder)
|
||||
{
|
||||
IShellDispatch *pISD;
|
||||
Folder *pZippedFile = 0L;
|
||||
Folder *pDestination = 0L;
|
||||
long FilesCount = 0;
|
||||
IDispatch* pItem = 0L;
|
||||
FolderItems *pFilesInside = 0L;
|
||||
VARIANT Options, OutFolder, InZipFile, Item;
|
||||
CoInitialize(nullptr);
|
||||
|
||||
__try
|
||||
{
|
||||
if (CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD) != S_OK)
|
||||
return false;
|
||||
|
||||
InZipFile.vt = VT_BSTR;
|
||||
InZipFile.bstrVal = lpZipFile;
|
||||
pISD->NameSpace(InZipFile, &pZippedFile);
|
||||
if (!pZippedFile)
|
||||
{
|
||||
pISD->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
OutFolder.vt = VT_BSTR;
|
||||
OutFolder.bstrVal = lpFolder;
|
||||
pISD->NameSpace(OutFolder, &pDestination);
|
||||
if (!pDestination)
|
||||
{
|
||||
pZippedFile->Release();
|
||||
pISD->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
pZippedFile->Items(&pFilesInside);
|
||||
if (!pFilesInside)
|
||||
{
|
||||
pDestination->Release();
|
||||
pZippedFile->Release();
|
||||
pISD->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
pFilesInside->get_Count(&FilesCount);
|
||||
if (FilesCount < 1)
|
||||
{
|
||||
pFilesInside->Release();
|
||||
pDestination->Release();
|
||||
pZippedFile->Release();
|
||||
pISD->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
pFilesInside->QueryInterface(IID_IDispatch, (void**)&pItem);
|
||||
|
||||
Item.vt = VT_DISPATCH;
|
||||
Item.pdispVal = pItem;
|
||||
|
||||
Options.vt = VT_I4;
|
||||
Options.lVal = 1024 | 512 | 16 | 4;
|
||||
|
||||
bool retval = pDestination->CopyHere(Item, Options) == S_OK;
|
||||
|
||||
pItem->Release(); pItem = 0L;
|
||||
pFilesInside->Release(); pFilesInside = 0L;
|
||||
pDestination->Release(); pDestination = 0L;
|
||||
pZippedFile->Release(); pZippedFile = 0L;
|
||||
pISD->Release(); pISD = 0L;
|
||||
|
||||
return retval;
|
||||
}
|
||||
__finally
|
||||
{
|
||||
CoUninitialize();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,67 +3,551 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <Rpc.h>
|
||||
#include <Windows.h>
|
||||
#include <CommCtrl.h>
|
||||
#include <Shlwapi.h>
|
||||
#include <ShlObj.h>
|
||||
#include <string>
|
||||
#include <tchar.h>
|
||||
#include <cstringt.h>
|
||||
#include "StringHelper.h"
|
||||
|
||||
namespace util
|
||||
{
|
||||
typedef BOOL(WINAPI *LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
|
||||
|
||||
typedef struct tagLogicalProcessorInformation
|
||||
class Utilities
|
||||
{
|
||||
DWORD logicalProcessorCount = 0;
|
||||
DWORD numaNodeCount = 0;
|
||||
DWORD processorCoreCount = 0;
|
||||
DWORD processorL1CacheCount = 0;
|
||||
DWORD processorL2CacheCount = 0;
|
||||
DWORD processorL3CacheCount = 0;
|
||||
DWORD processorPackageCount = 0;
|
||||
} LogicalProcessorInformation;
|
||||
public:
|
||||
typedef BOOL(WINAPI *LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
|
||||
typedef struct tagLogicalProcessorInformation
|
||||
{
|
||||
DWORD logicalProcessorCount = 0;
|
||||
DWORD numaNodeCount = 0;
|
||||
DWORD processorCoreCount = 0;
|
||||
DWORD processorL1CacheCount = 0;
|
||||
DWORD processorL2CacheCount = 0;
|
||||
DWORD processorL3CacheCount = 0;
|
||||
DWORD processorPackageCount = 0;
|
||||
} LogicalProcessorInformation;
|
||||
DWORD CountSetBits(ULONG_PTR bitMask)
|
||||
{
|
||||
DWORD LSHIFT = sizeof(ULONG_PTR) * 8 - 1;
|
||||
DWORD bitSetCount = 0;
|
||||
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
|
||||
DWORD i;
|
||||
|
||||
int GetLogicalProcessorInformation(LogicalProcessorInformation* info);
|
||||
for (i = 0; i <= LSHIFT; ++i)
|
||||
{
|
||||
bitSetCount += ((bitMask & bitTest) ? 1 : 0);
|
||||
bitTest /= 2;
|
||||
}
|
||||
|
||||
void ShutdownWindows();
|
||||
return bitSetCount;
|
||||
}
|
||||
int GetLogicalProcessorInformation(LogicalProcessorInformation* info)
|
||||
{
|
||||
LPFN_GLPI glpi;
|
||||
BOOL done = FALSE;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = nullptr;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = nullptr;
|
||||
DWORD returnLength = 0;
|
||||
DWORD byteOffset = 0;
|
||||
PCACHE_DESCRIPTOR Cache;
|
||||
|
||||
void LaunchAndWait(const std::wstring& file, const std::wstring& params, BOOL bWait);
|
||||
glpi = (LPFN_GLPI)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformation");
|
||||
if (nullptr == glpi)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nGetLogicalProcessorInformation is not supported.\n"));
|
||||
#endif
|
||||
return (1);
|
||||
}
|
||||
|
||||
void SetComboBoxHeight(HWND hDlg, int nComboBoxID, int nSizeLimit);
|
||||
while (!done)
|
||||
{
|
||||
DWORD rc = glpi(buffer, &returnLength);
|
||||
if (FALSE == rc)
|
||||
{
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
|
||||
std::wstring CombinePath(const std::wstring& szPath, const std::wstring& szFile);
|
||||
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(returnLength);
|
||||
if (nullptr == buffer)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nError: Allocation failure\n"));
|
||||
#endif
|
||||
return (2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nError %d\n"), GetLastError());
|
||||
#endif
|
||||
return (3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
done = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring GetFileName(const std::wstring& szFilePath);
|
||||
ptr = buffer;
|
||||
|
||||
std::wstring GetFilePath(const std::wstring& szFilePath);
|
||||
while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength)
|
||||
{
|
||||
switch (ptr->Relationship)
|
||||
{
|
||||
case RelationNumaNode:
|
||||
// Non-NUMA systems report a single record of this type.
|
||||
info->numaNodeCount++;
|
||||
break;
|
||||
case RelationProcessorCore:
|
||||
info->processorCoreCount++;
|
||||
// A hyperthreaded core supplies more than one logical processor.
|
||||
info->logicalProcessorCount += CountSetBits(ptr->ProcessorMask);
|
||||
break;
|
||||
case RelationCache:
|
||||
// Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache.
|
||||
Cache = &ptr->Cache;
|
||||
if (Cache->Level == 1)
|
||||
{
|
||||
info->processorL1CacheCount++;
|
||||
}
|
||||
else if (Cache->Level == 2)
|
||||
{
|
||||
info->processorL2CacheCount++;
|
||||
}
|
||||
else if (Cache->Level == 3)
|
||||
{
|
||||
info->processorL3CacheCount++;
|
||||
}
|
||||
break;
|
||||
case RelationProcessorPackage:
|
||||
// Logical processors share a physical package.
|
||||
info->processorPackageCount++;
|
||||
break;
|
||||
default:
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nError: Unsupported LOGICAL_PROCESSOR_RELATIONSHIP value.\n"));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
std::wstring GetFileExtension(const std::wstring& szFilePath);
|
||||
#ifdef _DEBUG
|
||||
_tprintf(_T("\nGetLogicalProcessorInformation results:\n"));
|
||||
_tprintf(_T("Number of NUMA nodes: %d\n"), info->numaNodeCount);
|
||||
_tprintf(_T("Number of physical processor packages: %d\n"), info->processorPackageCount);
|
||||
_tprintf(_T("Number of processor cores: %d\n"), info->processorCoreCount);
|
||||
_tprintf(_T("Number of logical processors: %d\n"), info->logicalProcessorCount);
|
||||
_tprintf(_T("Number of processor L1/L2/L3 caches: %d/%d/%d\n"),
|
||||
info->processorL1CacheCount,
|
||||
info->processorL2CacheCount,
|
||||
info->processorL3CacheCount);
|
||||
#endif
|
||||
|
||||
std::wstring GetOnlyFileName(const std::wstring& szFilePath);
|
||||
free(buffer);
|
||||
return (0);
|
||||
}
|
||||
public:
|
||||
void ShutdownWindows()
|
||||
{
|
||||
HANDLE m_hToken;
|
||||
if (::OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &m_hToken))
|
||||
{
|
||||
LUID m_Luid;
|
||||
if (::LookupPrivilegeValue(nullptr, _T("SeShutdownPrivilege"), &m_Luid))
|
||||
{
|
||||
TOKEN_PRIVILEGES tp;
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Luid = m_Luid;
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
::AdjustTokenPrivileges(m_hToken, FALSE, &tp, 0, nullptr, nullptr);
|
||||
}
|
||||
::CloseHandle(m_hToken);
|
||||
}
|
||||
::ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, 0);
|
||||
::PostQuitMessage(0);
|
||||
}
|
||||
void LaunchAndWait(const std::wstring& file, const std::wstring& params, BOOL bWait)
|
||||
{
|
||||
SHELLEXECUTEINFO sei;
|
||||
::ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
|
||||
sei.cbSize = sizeof(SHELLEXECUTEINFO);
|
||||
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
||||
// leave sei.lpVerb uninitialized for default action
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
sei.lpFile = file.c_str();
|
||||
sei.lpParameters = params.c_str();
|
||||
::ShellExecuteEx(&sei);
|
||||
if (bWait == TRUE)
|
||||
::WaitForSingleObject(sei.hProcess, INFINITE);
|
||||
::CloseHandle(sei.hProcess);
|
||||
}
|
||||
public:
|
||||
void SetComboBoxHeight(HWND hDlg, int nComboBoxID, int nSizeLimit)
|
||||
{
|
||||
HWND hComboxBox = ::GetDlgItem(hDlg, nComboBoxID);
|
||||
if (hComboxBox != nullptr)
|
||||
::SendMessage(hComboxBox, CB_SETMINVISIBLE, (WPARAM)nSizeLimit, 0);
|
||||
}
|
||||
public:
|
||||
std::wstring CombinePath(const std::wstring& szPath, const std::wstring& szFile)
|
||||
{
|
||||
std::wstring szOutputFile = szFile;
|
||||
if (szPath.length() >= 1)
|
||||
{
|
||||
auto cLast = szPath[szPath.length() - 1];
|
||||
if ((cLast == '\\') || (cLast == '/'))
|
||||
szOutputFile = szPath + szOutputFile;
|
||||
else
|
||||
szOutputFile = szPath + L"\\" + szOutputFile;
|
||||
}
|
||||
return szOutputFile;
|
||||
}
|
||||
std::wstring GetFileName(const std::wstring& szFilePath)
|
||||
{
|
||||
return ::PathFindFileName(szFilePath.c_str());
|
||||
}
|
||||
std::wstring GetFilePath(const std::wstring& szFilePath)
|
||||
{
|
||||
std::wstring szFileName = GetFileName(szFilePath);
|
||||
return szFilePath.substr(0, szFilePath.length() - szFileName.length());
|
||||
}
|
||||
std::wstring GetFileExtension(const std::wstring& szFilePath)
|
||||
{
|
||||
std::wstring szExt = ::PathFindExtension(szFilePath.c_str());
|
||||
size_t pos = szExt.find('.');
|
||||
if (pos != std::string::npos)
|
||||
return szExt.substr(pos + 1, szExt.length() - 1);
|
||||
return szExt;
|
||||
}
|
||||
std::wstring GetOnlyFileName(const std::wstring& szFilePath)
|
||||
{
|
||||
std::wstring szFileName = GetFileName(szFilePath);
|
||||
std::wstring szExt = GetFileExtension(szFilePath);
|
||||
return szFileName.substr(0, szFileName.length() - szExt.length());
|
||||
}
|
||||
ULONGLONG GetFileSize64(HANDLE hFile)
|
||||
{
|
||||
ULARGE_INTEGER liSize;
|
||||
liSize.LowPart = ::GetFileSize(hFile, &liSize.HighPart);
|
||||
if (liSize.LowPart == (DWORD)-1)
|
||||
{
|
||||
if (::GetLastError() != NO_ERROR)
|
||||
return(0);
|
||||
}
|
||||
return liSize.QuadPart;
|
||||
}
|
||||
ULONGLONG GetFileSize64(const std::wstring& szFileName)
|
||||
{
|
||||
WIN32_FIND_DATA FindFileData;
|
||||
HANDLE hFind;
|
||||
ULARGE_INTEGER ulSize;
|
||||
ULONGLONG nFileSize;
|
||||
|
||||
ULONGLONG GetFileSize64(HANDLE hFile);
|
||||
hFind = ::FindFirstFile(szFileName.c_str(), &FindFileData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return 0;
|
||||
|
||||
ULONGLONG GetFileSize64(const std::wstring& szFileName);
|
||||
::FindClose(hFind);
|
||||
|
||||
__int64 GetFileSizeInt64(FILE *fp);
|
||||
ulSize.HighPart = FindFileData.nFileSizeHigh;
|
||||
ulSize.LowPart = FindFileData.nFileSizeLow;
|
||||
nFileSize = ulSize.QuadPart;
|
||||
|
||||
std::wstring GetExeFilePath();
|
||||
return nFileSize;
|
||||
}
|
||||
__int64 GetFileSizeInt64(FILE *fp)
|
||||
{
|
||||
__int64 nCurPos, nSize;
|
||||
nCurPos = _ftelli64(fp);
|
||||
_fseeki64(fp, 0, SEEK_END);
|
||||
nSize = _ftelli64(fp);
|
||||
_fseeki64(fp, nCurPos, SEEK_SET);
|
||||
return nSize;
|
||||
}
|
||||
std::wstring GetExeFilePath()
|
||||
{
|
||||
TCHAR szExeFilePath[MAX_PATH + 1] = _T("");
|
||||
DWORD dwRet = ::GetModuleFileName(::GetModuleHandle(nullptr), szExeFilePath, MAX_PATH);
|
||||
if (dwRet > 0)
|
||||
{
|
||||
std::wstring szTempBuff1 = szExeFilePath;
|
||||
std::wstring szTempBuff2 = GetFileName(szTempBuff1);
|
||||
return szTempBuff1.substr(0, szTempBuff1.length() - szTempBuff2.length());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
std::wstring GetSettingsFilePath(const std::wstring& szFileName, const std::wstring& szConfigDirectory)
|
||||
{
|
||||
TCHAR szPath[MAX_PATH];
|
||||
if (SUCCEEDED(SHGetFolderPath(nullptr,
|
||||
CSIDL_APPDATA | CSIDL_FLAG_CREATE,
|
||||
nullptr,
|
||||
0,
|
||||
szPath)))
|
||||
{
|
||||
PathAppend(szPath, szConfigDirectory.c_str());
|
||||
PathAppend(szPath, szFileName.c_str());
|
||||
return szPath;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
std::wstring GetFullPathName(const std::wstring& szFilePath)
|
||||
{
|
||||
TCHAR szFullPath[MAX_PATH + 2] = _T("");
|
||||
LPTSTR pszFilePos = nullptr;
|
||||
::GetFullPathName(szFilePath.c_str(), MAX_PATH + 1, szFullPath, &pszFilePos);
|
||||
return szFullPath;
|
||||
}
|
||||
bool FileExists(const std::wstring& szPath)
|
||||
{
|
||||
WIN32_FIND_DATA w32FileData;
|
||||
ZeroMemory(&w32FileData, sizeof(WIN32_FIND_DATA));
|
||||
HANDLE hFind = ::FindFirstFile(szPath.c_str(), &w32FileData);
|
||||
bool bInvalidHandle = hFind == INVALID_HANDLE_VALUE;
|
||||
::FindClose(hFind);
|
||||
return bInvalidHandle == false;
|
||||
}
|
||||
public:
|
||||
BOOL DirectoryExists(const std::wstring& szPath)
|
||||
{
|
||||
if (_taccess_s(szPath.c_str(), 0) == 0)
|
||||
{
|
||||
struct _stat status;
|
||||
_tstat(szPath.c_str(), &status);
|
||||
return (status.st_mode & S_IFDIR) != 0;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
bool MakeFullPath(const std::wstring& szTargetPath)
|
||||
{
|
||||
std::wstring szPath = szTargetPath;
|
||||
if (szPath[szPath.length() - 1] != '\\')
|
||||
szPath = szPath + L"\\";
|
||||
|
||||
std::wstring GetSettingsFilePath(const std::wstring& szFileName, const std::wstring& szConfigDirectory);
|
||||
std::wstring szTmpDir = szPath.substr(0, 2);
|
||||
_tchdir(szTmpDir.c_str());
|
||||
|
||||
std::wstring GetFullPathName(const std::wstring& szFilePath);
|
||||
int nStart = 3;
|
||||
int nEnd = 0;
|
||||
while (true)
|
||||
{
|
||||
nEnd = szPath.find('\\', nStart);
|
||||
if (nEnd == -1)
|
||||
return true;
|
||||
|
||||
BOOL DirectoryExists(const std::wstring& szPath);
|
||||
std::wstring szNextDir = szPath.substr(nStart, nEnd - nStart);
|
||||
std::wstring szCurDir = szTmpDir + L"\\" + szNextDir;
|
||||
if (_tchdir(szCurDir.c_str()) != 0)
|
||||
{
|
||||
_tchdir(szTmpDir.c_str());
|
||||
if (_tmkdir(szNextDir.c_str()) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MakeFullPath(const std::wstring& szTargetPath);
|
||||
szTmpDir += L"\\" + szNextDir;
|
||||
nStart = nEnd + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public:
|
||||
std::wstring GenerateUuidString()
|
||||
{
|
||||
std::wstring strKey;
|
||||
UUID uuid;
|
||||
if (UuidCreate(&uuid) == RPC_S_OK)
|
||||
{
|
||||
RPC_WSTR szUuid;
|
||||
if (UuidToString(&uuid, &szUuid) == RPC_S_OK)
|
||||
{
|
||||
strKey = (LPTSTR)szUuid;
|
||||
strKey = StringHelper::ToUpper(strKey);
|
||||
RpcStringFree(&szUuid);
|
||||
}
|
||||
}
|
||||
return strKey;
|
||||
}
|
||||
public:
|
||||
void ConvertAnsiToUnicode(const char *szAnsi, wchar_t *szUnicode, ULONG nLength)
|
||||
{
|
||||
// use always + 1 to null-terminate string
|
||||
_mbstowcsz(szUnicode, szAnsi, nLength + 1);
|
||||
}
|
||||
void ConvertUnicodeToAnsi(const wchar_t *szUnicode, char *szAnsi, ULONG nLength)
|
||||
{
|
||||
// use always + 1 to null-terminate string
|
||||
_wcstombsz(szAnsi, szUnicode, nLength + 1);
|
||||
}
|
||||
public:
|
||||
PTCHAR* MyCommandLineToArgv(PTCHAR pszCmdLine, int *pnArgc)
|
||||
{
|
||||
BOOLEAN bHaveQuotationMark, bHaveText, bHaveSpace;
|
||||
ULONG nLength, nArgc, nI, nJ;
|
||||
PTCHAR *pszArgv;
|
||||
PTCHAR pszTmpArgv;
|
||||
TCHAR cNext;
|
||||
|
||||
bool FileExists(const std::wstring& szPath);
|
||||
nLength = _tcslen(pszCmdLine);
|
||||
nI = ((nLength + 2) / 2) * sizeof(PVOID) + sizeof(PVOID);
|
||||
pszArgv = (PTCHAR *)GlobalAlloc(GMEM_FIXED, nI + (nLength + 2) * sizeof(TCHAR));
|
||||
pszTmpArgv = (PTCHAR)(((PUCHAR)pszArgv) + nI);
|
||||
nArgc = nI = nJ = 0;
|
||||
pszArgv[nArgc] = pszTmpArgv;
|
||||
bHaveQuotationMark = FALSE;
|
||||
bHaveText = FALSE;
|
||||
bHaveSpace = TRUE;
|
||||
|
||||
std::wstring GenerateUuidString();
|
||||
while (cNext = pszCmdLine[nI])
|
||||
{
|
||||
if (bHaveQuotationMark)
|
||||
{
|
||||
if (cNext == '\"')
|
||||
{
|
||||
bHaveQuotationMark = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
pszTmpArgv[nJ] = cNext;
|
||||
nJ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cNext == '\"')
|
||||
{
|
||||
bHaveQuotationMark = TRUE;
|
||||
bHaveText = TRUE;
|
||||
|
||||
void ConvertAnsiToUnicode(const char *szAnsi, wchar_t *szUnicode, ULONG nLength);
|
||||
if (bHaveSpace)
|
||||
{
|
||||
pszArgv[nArgc] = pszTmpArgv + nJ;
|
||||
nArgc++;
|
||||
}
|
||||
|
||||
void ConvertUnicodeToAnsi(const wchar_t *szUnicode, char *szAnsi, ULONG nLength);
|
||||
bHaveSpace = FALSE;
|
||||
}
|
||||
else if ((cNext == ' ') || (cNext == '\t') || (cNext == '\n') || (cNext == '\r'))
|
||||
{
|
||||
if (bHaveText)
|
||||
{
|
||||
pszTmpArgv[nJ] = '\0';
|
||||
nJ++;
|
||||
}
|
||||
|
||||
PTCHAR* MyCommandLineToArgv(PTCHAR pszCmdLine, int *pnArgc);
|
||||
bHaveText = FALSE;
|
||||
bHaveSpace = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bHaveText = TRUE;
|
||||
|
||||
bool Unzip2Folder(BSTR lpZipFile, BSTR lpFolder);
|
||||
if (bHaveSpace)
|
||||
{
|
||||
pszArgv[nArgc] = pszTmpArgv + nJ;
|
||||
nArgc++;
|
||||
}
|
||||
|
||||
pszTmpArgv[nJ] = cNext;
|
||||
nJ++;
|
||||
bHaveSpace = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
nI++;
|
||||
}
|
||||
|
||||
pszTmpArgv[nJ] = '\0';
|
||||
pszArgv[nArgc] = nullptr;
|
||||
(*pnArgc) = nArgc;
|
||||
|
||||
return pszArgv;
|
||||
}
|
||||
public:
|
||||
bool Unzip2Folder(BSTR lpZipFile, BSTR lpFolder)
|
||||
{
|
||||
IShellDispatch *pISD;
|
||||
Folder *pZippedFile = 0L;
|
||||
Folder *pDestination = 0L;
|
||||
long FilesCount = 0;
|
||||
IDispatch* pItem = 0L;
|
||||
FolderItems *pFilesInside = 0L;
|
||||
VARIANT Options, OutFolder, InZipFile, Item;
|
||||
CoInitialize(nullptr);
|
||||
|
||||
__try
|
||||
{
|
||||
if (CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD) != S_OK)
|
||||
return false;
|
||||
|
||||
InZipFile.vt = VT_BSTR;
|
||||
InZipFile.bstrVal = lpZipFile;
|
||||
pISD->NameSpace(InZipFile, &pZippedFile);
|
||||
if (!pZippedFile)
|
||||
{
|
||||
pISD->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
OutFolder.vt = VT_BSTR;
|
||||
OutFolder.bstrVal = lpFolder;
|
||||
pISD->NameSpace(OutFolder, &pDestination);
|
||||
if (!pDestination)
|
||||
{
|
||||
pZippedFile->Release();
|
||||
pISD->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
pZippedFile->Items(&pFilesInside);
|
||||
if (!pFilesInside)
|
||||
{
|
||||
pDestination->Release();
|
||||
pZippedFile->Release();
|
||||
pISD->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
pFilesInside->get_Count(&FilesCount);
|
||||
if (FilesCount < 1)
|
||||
{
|
||||
pFilesInside->Release();
|
||||
pDestination->Release();
|
||||
pZippedFile->Release();
|
||||
pISD->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
pFilesInside->QueryInterface(IID_IDispatch, (void**)&pItem);
|
||||
|
||||
Item.vt = VT_DISPATCH;
|
||||
Item.pdispVal = pItem;
|
||||
|
||||
Options.vt = VT_I4;
|
||||
Options.lVal = 1024 | 512 | 16 | 4;
|
||||
|
||||
bool retval = pDestination->CopyHere(Item, Options) == S_OK;
|
||||
|
||||
pItem->Release(); pItem = 0L;
|
||||
pFilesInside->Release(); pFilesInside = 0L;
|
||||
pDestination->Release(); pDestination = 0L;
|
||||
pZippedFile->Release(); pZippedFile = 0L;
|
||||
pISD->Release(); pISD = 0L;
|
||||
|
||||
return retval;
|
||||
}
|
||||
__finally
|
||||
{
|
||||
CoUninitialize();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче