Files
TTDownloader/client/src/main.cpp
T
tongtong eb3df9aa3d Add FTP and magnet backends, tracker and proxy settings, and organize client modules
Integrate pinned libcurl, libtorrent and static OpenSSL dependencies with license notices. Enable verified HTTPS trackers and authenticated HTTP/SOCKS5 proxies, add tracker TXT import without arbitrary list caps, and allow resizing the main window.

Organize client sources by responsibility and update Visual Studio projects, filters and tests. Debug and Release builds passed, along with UI, HTTP, tracker import and browser bridge regressions. Full protocol tests have an unresolved intermittent HTTPS tracker wait timeout; Windows 7 runtime validation remains outstanding.
2026-11-27 11:28:30 +08:00

61 lines
2.6 KiB
C++

#include "stdafx.h"
#include "ttui/application.h"
#include "ui/downloader_form.h"
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(nCmdShow);
const std::wstring command=GetCommandLineW();
StartupOptions startup;
if (!ParseStartupCommandLine(command,startup)) {
MessageBoxW(nullptr,L"启动参数无效。\n用法:ttdownloader.exe --add \"https://example.com/file.zip\"\n也可直接传入 HTTP/FTP/磁力下载地址,或使用 --add 打开空白添加窗口。",L"TTDownloader",MB_ICONERROR);
return 1;
}
HANDLE instance_mutex = ::CreateMutexW(nullptr, TRUE, L"Local\\TTDownloader.SingleInstance");
if (!instance_mutex) {
MessageBoxW(nullptr,L"无法访问客户端实例,请使用相同用户和权限启动。",L"TTDownloader",MB_ICONERROR); return 1;
}
if (::GetLastError() == ERROR_ALREADY_EXISTS)
{
HWND hwnd=nullptr;
const auto deadline=GetTickCount64()+5000;
do {
hwnd=FindWindowW(DownloaderForm::kClassName.c_str(),nullptr);
if (hwnd) break;
Sleep(50);
} while (GetTickCount64()<deadline);
bool delivered=false;
if (hwnd) {
DWORD pid=0; GetWindowThreadProcessId(hwnd,&pid); AllowSetForegroundWindow(pid);
if (!startup.show_add) delivered=PostMessageW(hwnd,DownloaderForm::kShowMainWindowMessage,0,0)!=FALSE;
else {
COPYDATASTRUCT data{kStartupCopyDataTag,static_cast<DWORD>((command.size()+1)*sizeof(wchar_t)),const_cast<wchar_t*>(command.c_str())};
DWORD_PTR result=0;
delivered=SendMessageTimeoutW(hwnd,WM_COPYDATA,0,reinterpret_cast<LPARAM>(&data),SMTO_ABORTIFHUNG|SMTO_BLOCK,3000,&result) && result;
}
}
::CloseHandle(instance_mutex);
if (!delivered) MessageBoxW(nullptr,L"正在运行的客户端未能接收启动参数,请完全退出旧版后重试。",L"TTDownloader",MB_ICONERROR);
return delivered?0:1;
}
DownloaderForm form;
int result=ttui::RunApplication([&] {
if (!form.Create(nullptr,DownloaderForm::kClassName.c_str(),L"TTDownloader",940,640,true,true)) {
MessageBoxW(nullptr,L"无法创建主窗口。",L"TTDownloader",MB_ICONERROR); return false;
}
form.CenterWindow(); form.ShowWindow(); form.OpenStartupRequest(startup); return true;
});
::CloseHandle(instance_mutex);
return result;
}