Skip to content

Commit

Permalink
Merge pull request #1 from KondeU/dev
Browse files Browse the repository at this point in the history
AutoDiskCopier v3.0 合入
KondeU authored Aug 20, 2021
2 parents f74243f + da5cd4e commit 21dcc9a
Showing 22 changed files with 1,892 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AutoDiskCopier_v3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
*.aps
12 changes: 12 additions & 0 deletions AutoDiskCopier_v3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.10)
project(AutoDiskCopier)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

file(GLOB_RECURSE INC src/*.h)
file(GLOB_RECURSE SRC src/*.cpp)
file(GLOB_RECURSE RES src/*.rc)

add_executable(AutoDiskCopier WIN32 ${SRC} ${INC} ${RES})
30 changes: 30 additions & 0 deletions AutoDiskCopier_v3/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cd %~dp0

set BUILD_BITS=%1
set BUILD_TYPE=%2
set BUILD_COMPILE=%3

rem script params: build.bat [BUILD_BITS] [BUILD_TYPE] [BUILD_COMPILE]
rem default value: BUILD_BITS=x86 BUILD_TYPE=Release BUILD_COMPILE=VS2015

if "%BUILD_TYPE%"=="" (set BUILD_TYPE=Release)
if "%BUILD_COMPILE%"=="" (set BUILD_COMPILE=VS2017)

if "%BUILD_COMPILE%"=="VS2015" (set BUILD_COMPILE=Visual Studio 14 2015)
if "%BUILD_COMPILE%"=="VS2017" (set BUILD_COMPILE=Visual Studio 15 2017)
if "%BUILD_COMPILE%"=="VS2019" (set BUILD_COMPILE=Visual Studio 16 2019)

rem only VS2019 uses "BUILD_ARCH_ARG"
set BUILD_ARCH_ARG=
if "%BUILD_COMPILE%"=="Visual Studio 16 2019" (
if "%BUILD_BITS%"=="x64" (set BUILD_ARCH_ARG=-A x64) ^
else (set BUILD_ARCH_ARG=-A Win32)
) else (
if "%BUILD_BITS%"=="x64" (set BUILD_COMPILE=%BUILD_COMPILE% Win64)
)

mkdir build
cd build
cmake -G "%BUILD_COMPILE%" %BUILD_ARCH_ARG% ..
cmake --build . --config %BUILD_TYPE% -j 8 -- /p:CharacterSet=Unicode
cd ..
1 change: 1 addition & 0 deletions AutoDiskCopier_v3/clean.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rd %~dp0build /S /Q
14 changes: 14 additions & 0 deletions AutoDiskCopier_v3/config.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:: Manually configure the local environment.

PATH=D:\CMake\cmake-3.16.0-win64-x64\bin;%PATH%
PATH=D:\CMake\cmake-3.19.8-win64-x64\bin;%PATH%
echo Env PATH: %PATH%

:: The version of CMake finally used:
cmake --version

:: The default build uses VS2015, if we have a higher version of VS,
:: use the higher version of MSBuild to build, then we need to add
:: the path of MSBuild.exe to the environment PATH.
:: And we need to install vc140 compatible compile and build tools.
PATH=D:\VS\2017\Enterprise\MSBuild\15.0\Bin;%PATH%
280 changes: 280 additions & 0 deletions AutoDiskCopier_v3/src/AutoDiskCopier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
#include"AutoDiskCopier.h"

#pragma comment(linker, \
"/manifestdependency:\"" \
"type='win32' " \
"name='Microsoft.Windows.Common-Controls' " \
"version='6.0.0.0' " \
"processorArchitecture='*' " \
"publicKeyToken='6595b64144ccf1df' " \
"language='*'\"")

static const TCHAR szAppNameEng[] = TEXT("AutoDiskCopier");
static const TCHAR szAppNameChn[] = TEXT("自动磁盘拷贝器");

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);


INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, INT iCmdShow)
{
//--- Create a no show window to get other msg. ---//

HWND hwnd;
MSG msg;
WNDCLASS wndclass;
memset(&hwnd, 0, sizeof(HWND));
memset(&msg, 0, sizeof(MSG));
memset(&wndclass, 0, sizeof(WNDCLASS));

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppNameEng;

if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("错误:主窗口类注册失败,该应用程序最低版本限制为WindowsNT!"), szAppNameChn, MB_ICONERROR | MB_OK);
return 0;
}

hwnd = CreateWindow(
szAppNameEng, szAppNameChn, WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME,
0, 0, 0, 0, GetDesktopWindow(), NULL, hInstance, NULL);

//--- Program init. ---//

//Accel.

HACCEL hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));

//--- Message loop. ---//

while (GetMessage(&msg, NULL, 0, 0))
{
if (TranslateAccelerator(hwnd, hAccel, &msg))
{
continue;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}

//--- Program end. ---//

return (int)msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static CAutoDiskCopier adc(hwnd);

static HWND hDlgMain = NULL;

switch (message)
{

case WM_CREATE:

hDlgMain = CreateDialogParam(
((CREATESTRUCT*)lParam)->hInstance, MAKEINTRESOURCE(IDD_DIALOG),
hwnd, DlgProc, (LPARAM)(&adc));

//热键启动(Control + Alt + Shift + U)
RegisterHotKey(hwnd, 0, MOD_CONTROL | MOD_ALT | MOD_SHIFT, 'U');

//托盘图标
adc.m_ni.SetTip(TEXT("AutoDiskCopier v3.0"));
adc.m_ni.SetIcon(((CREATESTRUCT*)lParam)->hInstance, MAKEINTRESOURCE(IDI_ICON));

if (adc.m_bEnableNotifyIcon)
{
adc.m_ni.AddNotificationIcon();
}

return 0;


case WM_COMMAND:

switch (LOWORD(wParam))
{
case IDR_ACCELERATOR_HIDE:
SendMessage(hDlgMain, WM_COMMAND, wParam, lParam);
}
break;

case WM_HOTKEY:

ShowWindow(hDlgMain, SW_NORMAL);
return 0;


case WM_NOTIFYICON:

if (wParam == IDI_ICON && lParam == WM_RBUTTONDBLCLK)
{
adc.m_ni.DeleteNotificationIcon();
ShowWindow(hDlgMain, SW_SHOWNORMAL);
}
break;


case WM_DEVICECHANGE:

if ((DBT_DEVICEARRIVAL != wParam) ||
(DBT_DEVTYP_VOLUME != ((PDEV_BROADCAST_HDR)lParam)->dbch_devicetype))
{
//忽略设备安装不成功或非逻辑磁盘的消息
return BROADCAST_QUERY_DENY;
}
else
{
DWORD dwDiskMask = ((PDEV_BROADCAST_VOLUME)lParam)->dbcv_unitmask;
UINT uiPos = 0;
TCHAR szCopyDiskPath[4];

for (uiPos = 0; !(dwDiskMask & 1); uiPos++)
{
dwDiskMask >>= 1;
}

if (uiPos >= 26)
{
//磁盘盘符超标
return BROADCAST_QUERY_DENY;
}
else
{
wsprintf(szCopyDiskPath, TEXT("%c%s"), 'A' + uiPos, TEXT(":\\"));
}

adc.Copying(szCopyDiskPath);

return TRUE;
}


case WM_DESTROY:

PostQuitMessage(0);
return 0;
}

return DefWindowProc(hwnd, message, wParam, lParam);
}


INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static CAutoDiskCopier * padc;

switch (message)
{
case WM_INITDIALOG:
padc = (CAutoDiskCopier *)lParam;
padc->SetDlgInfo(hDlg);
padc->m_bfdlg.SetOwnerWindow(hDlg);
padc->m_osdlg.SetOwnerWindow(hDlg);
padc->m_osdlg.SetFilter(2, TEXT("签名文件(*.key)"), TEXT("*.key"), TEXT("所有文件(*.*)"), TEXT("*.*"));
padc->m_osdlg.SetDefExt(TEXT("key"));
return TRUE;

case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
case IDC_BTN_HIDE:
case IDR_ACCELERATOR_HIDE:
ShowWindow(hDlg, SW_HIDE);
if (padc->m_bEnableNotifyIcon)
{
padc->m_ni.AddNotificationIcon();
}
return TRUE;

case IDC_BTN_QUIT:
SendMessage(GetParent(hDlg), WM_DESTROY, 0, 0);
return TRUE;

case IDC_BTN_SAVESETTING:
padc->GetDlgInfo(hDlg);
padc->RegisterAutorun(hDlg); // 注册失败时会自动更改标记
padc->SetDlgInfo(hDlg); // 因此重新获取一遍标记再SaveSetting
padc->SaveSetting(hDlg);
return TRUE;

case IDC_BTN_BROWSECOPYFILEPATH:
if (padc->m_bfdlg.CmmDlgBrowse())
{
TCHAR szPath[MAX_PATH];
wsprintf(szPath, TEXT("%s%s"), padc->m_bfdlg.GetDir(), TEXT("\\"));
SetDlgItemText(hDlg, IDC_EDIT_COPYFILEPATH, szPath);
}
return TRUE;

case IDC_BTN_CREATEKEYFILE:
if(padc->m_osdlg.CmnDlgSaveFile())
{
HANDLE hFile = CreateFile(padc->m_osdlg.GetFilePath(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
MessageBox(hDlg, TEXT("生成签名文件失败!"), TEXT("ADC - 签名"), MB_ICONERROR);
}
else
{
int iRand[2];
char szMD5[33];
for (UINT ui = 0; ui < 2; ui++)
{
srand(GetTickCount());
iRand[ui] = rand();

padc->m_md5.CalcMD5((void *)(&iRand[ui]), sizeof(int));
padc->m_md5.GetMD5(szMD5);
padc->m_md5.Reset();

DWORD dwWrited;
WriteFile(hFile, szMD5, 32 * sizeof(char), &dwWrited, NULL);
}

CloseHandle(hFile);
MessageBox(hDlg, TEXT("已生成签名文件。"), TEXT("ADC - 签名"), MB_OK);
}
}
return TRUE;

case IDC_BTN_BROWSEKEYFILEPATH:
if (padc->m_osdlg.CmnDlgOpenFile())
{
SetDlgItemText(hDlg, IDC_EDIT_KEYFILEPATH, padc->m_osdlg.GetFilePath());
}
return TRUE;
}
break;

case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code)
{
case NM_CLICK:
case NM_RETURN:
{
PNMLINK pnmLink = (PNMLINK)lParam;
if (((LPNMHDR)lParam)->hwndFrom == GetDlgItem(hDlg, IDC_SYSLINK))
{
ShellExecute(NULL, TEXT("open"), TEXT("https://github.com/KondeU/AutoDiskCopier"), NULL, NULL, SW_SHOW);
return TRUE;
}
}
}
break;
}
return FALSE;
}
Loading

0 comments on commit 21dcc9a

Please sign in to comment.