Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
+ 1.支持自动登录。
+ 2.UI调整,添加窗口阴影。
  • Loading branch information
JelinYao committed May 21, 2022
1 parent 51f542c commit 89dc624
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*.lo
*.o
*.obj
*.exp
*.user

# Precompiled Headers
*.gch
Expand All @@ -29,6 +31,8 @@
*.exe
*.out
*.app
*.flv
*.mp3

*.dy
*.pdb
Expand Down
6 changes: 3 additions & 3 deletions Bin/Debug/skin/wnd_info.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Window size="400,232" caption="0,0,0,40">
<Window size="400,230" caption="0,0,0,40" showshadow="true" shadowdarkness="17" shadowsize="6" shadowposition="0,3">
<Font name="微软雅黑" size="12" bold="false" id="0"/>
<Font name="微软雅黑" size="14" bold="false" id="1"/>
<Font name="微软雅黑" size="16" bold="false" id="2"/>

<VerticalLayout bkcolor="#FFFFFFFF" bordersize="1" bordercolor="#FFE1E1E1" inset="1,1,1,1">
<VerticalLayout bkcolor="#FFFFFFFF">
<HorizontalLayout height="40" bkimage="bk_title.png">
<Label text="视频信息" float="true" pos="20,10,0,0" width="100" textcolor="#FFFFFFFF" height="16" font="1" align="left" valign="center"/>
<Label text="新建下载" float="true" pos="20,10,0,0" width="100" textcolor="#FFFFFFFF" height="16" font="1" align="left" valign="center"/>
<Button name="btn_close" float="true" pos="369,0,0,0" width="31" height="29" normalimage="file='close.png' source='0,0,31,29' " hotimage="file='close.png' source='0,29,31,58'" pushedimage="close.png' source='0,58,31,87'" cursor="hand"/>
</HorizontalLayout>
<HorizontalLayout>
Expand Down
4 changes: 2 additions & 2 deletions Bin/Debug/skin/wnd_login.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Window size="302,242" caption="0,0,0,40">
<Window size="300,240" caption="0,0,0,40" showshadow="true" shadowdarkness="17" shadowsize="6" shadowposition="0,3">
<Font name="微软雅黑" size="12" bold="false" id="0"/>
<Font name="微软雅黑" size="14" bold="false" id="1"/>
<Font name="微软雅黑" size="16" bold="false" id="2"/>

<VerticalLayout bkcolor="#FFFFFFFF" bordersize="1" bordercolor="#FFE1E1E1" inset="1,1,1,1">
<VerticalLayout bkcolor="#FFFFFFFF">
<HorizontalLayout height="40" bkimage="bk_title.png">
<Label text="登录bilibili" float="true" pos="20,10,0,0" width="100" textcolor="#FFFFFFFF" height="16" font="1" align="left" valign="center"/>
<Button name="btn_close" float="true" pos="269,0,0,0" width="31" height="29" normalimage="file='close.png' source='0,0,31,29' " hotimage="file='close.png' source='0,29,31,58'" pushedimage="close.png' source='0,58,31,87'" cursor="hand"/>
Expand Down
4 changes: 2 additions & 2 deletions Bin/Debug/skin/wnd_main.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Window size="702,502" caption="0,0,0,41">
<Window size="700,500" caption="0,0,0,41" showshadow="true" shadowdarkness="17" shadowsize="6" shadowposition="0,3">
<Font name="微软雅黑" size="12" bold="false" id="0"/>
<Font name="微软雅黑" size="12" bold="true" id="1"/>
<Font name="微软雅黑" size="14" bold="false" id="2"/>
<Font name="微软雅黑" size="14" bold="true" id="3"/>
<Default name="VScrollBar" value="showbutton1=&quot;false&quot; showbutton2=&quot;false&quot; thumbnormalimage=&quot;file=&apos;public/scroll.png&apos; source=&apos;0,0,6,7&apos; corner=&apos;2,2,2,2&apos;&quot; railnormalimage=&quot;file=&apos;public/scroll.png&apos; source=&apos;0,0,6,7&apos; corner=&apos;2,2,2,2&apos;&quot; bknormalimage=&quot;file=&apos;public/scroll.png&apos; source=&apos;0,7,6,14&apos; corner=&apos;2,2,2,2&apos;&quot; width=&quot;6&quot; "/>

<VerticalLayout bkcolor="#FFFFFFFF" bordersize="1" bordercolor="#FFE1E1E1" inset="1,1,1,1">
<VerticalLayout bkcolor="#FFFFFFFF">
<HorizontalLayout height="40" bkimage="bk_title.png">
<Control float="true" pos="8,6,0,0" width="28" height="28" bkimage="public/logo.png"/>
<Label text="B站视频下载工具" float="true" pos="40,10,0,0" width="200" textcolor="#FFFFFFFF" height="16" font="2" align="left" valign="center"/>
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ mp3lame: https://lame.sourceforge.io/
jsoncpp: https://github.com/open-source-parsers/jsoncpp
restclient: https://github.com/mrtazz/restclient-cpp
## 更新记录
### 2022年5月21日 -- 1.2.0
+ 1.支持自动登录。
+ 2.UI调整,添加窗口阴影。
### 2022年5月13日 -- 1.1.0
+ 1.增加二维码登录功能,支持下载高清视频。
+ 2.UI调整。
Expand Down
Binary file modified src/BVLoader/BVLoader.rc
Binary file not shown.
3 changes: 3 additions & 0 deletions src/BVLoader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
ServiceManager::Instance()->Exit();
::CloseHandle(mutex);
LOG(INFO) << "Application exit";
#ifdef _DEBUG
_CrtDumpMemoryLeaks();
#endif
return 0;
}

Expand Down
12 changes: 9 additions & 3 deletions src/BVLoader/service/async/async_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ void AsyncService::AddDownloadImageTask(ImageType image_type, std_cstr_ref url)
task_event_.notify_one();
}

void AsyncService::SetCookie(std_cstr_ref cookie)
{
user_cookie_ = cookie;
}

void AsyncService::ThreadProc(void* param)
{
RestClient::init();
Expand Down Expand Up @@ -468,6 +473,7 @@ bool AsyncService::ParseLoginInfo(const std::shared_ptr<IAsyncTask>& task, std_c
auto& data = root[kHttpResponseData];
int code = 0;
std_str url;
std_str cookie;
if (data.isInt()) {
code = data.asInt();
}
Expand All @@ -482,15 +488,15 @@ bool AsyncService::ParseLoginInfo(const std::shared_ptr<IAsyncTask>& task, std_c
string_utils::SplitStringA(url, "&", param_list);
size_t count = param_list.size();
for (size_t i = 0; i < count; ++i) {
user_cookie_ += param_list[i];
cookie += param_list[i];
if (i != count - 1) {
user_cookie_.append("; ");
cookie.append("; ");
}
}
}
// 解析完毕,回调通知界面
if (!IsDelegateEmpty()) {
QrcodeLoginInfo* login_info = new QrcodeLoginInfo(code, std::move(url));
QrcodeLoginInfo* login_info = new QrcodeLoginInfo(code, std::move(url), std::move(cookie));
NotifyDelegate(task->task_type, AsyncErrorCode::ERROR_SUCCESS, login_info);
}
return true;
Expand Down
1 change: 1 addition & 0 deletions src/BVLoader/service/async/async_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AsyncService
void AddDecodeTask(UINT_PTR task_id, std_cwstr_ref video_path, std_cwstr_ref mp3_path) override;
void AddLoginTask(std_cstr_ref url, std_cstr_ref auth_key) override;
void AddDownloadImageTask(ImageType image_type, std_cstr_ref url) override;
void SetCookie(std_cstr_ref cookie) override;

protected:
bool Init() override;
Expand Down
6 changes: 4 additions & 2 deletions src/BVLoader/service/async/async_service_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ class QrcodeUrlInfo {
// 登录状态信息
class QrcodeLoginInfo {
public:
QrcodeLoginInfo(int _code, std_str_r_ref _url)
QrcodeLoginInfo(int _code, std_str_r_ref _url, std_str_r_ref _cookie)
: code(_code)
, url(std::move(_url)) {
, url(std::move(_url))
, cookie(std::move(_cookie)) {
}

int code = 0;
std_str url;
std_str cookie;
};

// 用户信息
Expand Down
1 change: 1 addition & 0 deletions src/BVLoader/service/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IAsyncService
virtual void AddDecodeTask(UINT_PTR task_id, std_cwstr_ref video_path, std_cwstr_ref mp3_path) = 0;
virtual void AddLoginTask(std_cstr_ref url, std_cstr_ref auth_key) = 0;
virtual void AddDownloadImageTask(ImageType image_type, std_cstr_ref url) = 0;
virtual void SetCookie(std_cstr_ref cookie) = 0;
};

// 下载服务对外能力接口
Expand Down
3 changes: 2 additions & 1 deletion src/BVLoader/wnd/wnd_login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ LRESULT WndLogin::OnMsgAsyncSuccess(WPARAM wParam, LPARAM lParam)
{
case 0: {
// 登陆成功
::PostMessage(main_wnd_, WM_MAINWND_LOGIN_SUCCESS, 0, 0);
std_str* cookie = new std_str(std::move(info->cookie));
::PostMessage(main_wnd_, WM_MAINWND_LOGIN_SUCCESS, 0, (LPARAM)cookie);
Close();
break;
}
Expand Down
51 changes: 51 additions & 0 deletions src/BVLoader/wnd/wnd_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void WndMain::InitWindow()
DOWNLOAD_SERVICE()->AddDelegate(this, nullptr);
AUDIO_SERVICE()->AddDelegate(this, nullptr);
ASYNC_SERVICE()->AddDelegate(this, nullptr);
cookie_mgr_ = std::make_unique<CookieMgr>(m_hWnd);
}

void WndMain::OnFinalMessage(HWND hWnd)
Expand Down Expand Up @@ -497,6 +498,12 @@ LRESULT WndMain::OnMsgShowWnd(WPARAM wParam, LPARAM lParam)

LRESULT WndMain::OnMsgLoginSuccess(WPARAM wParam, LPARAM lParam)
{
// user cookie
std_str* cookie = reinterpret_cast<std_str*>(lParam);
assert(cookie);
std::unique_ptr<std_str> auto_cookie(cookie);
ASYNC_SERVICE()->SetCookie(*cookie);
cookie_mgr_->SetCookie(std::move(*cookie));
// 获取用户信息
btn_user_->SetEnabled(false);
ASYNC_SERVICE()->AddHttpTask(AsyncTaskType::TASK_GET_USER_INFO, kRequestUserInfo);
Expand Down Expand Up @@ -526,5 +533,49 @@ LRESULT WndMain::OnMsgAsyncSuccess(WPARAM wParam, LPARAM lParam)

LRESULT WndMain::OnMsgAsyncError(WPARAM wParam, LPARAM lParam)
{
AsyncTaskType task_type = static_cast<AsyncTaskType>(wParam);
if (task_type == AsyncTaskType::TASK_GET_USER_INFO) {
btn_user_->SetEnabled(true);
// 获取用户信息失败,清空cookie
std_str cookie;
ASYNC_SERVICE()->SetCookie(cookie);
cookie_mgr_->SetCookie(cookie);
}
return 0;
}

////////////////////////////////////////////////////////////////////////////////////
static const constexpr char* kConfigFileName = "config.ini";
WndMain::CookieMgr::CookieMgr(HWND wnd)
: main_wnd_(wnd)
{
Read();
}

WndMain::CookieMgr::~CookieMgr()
{
}

void WndMain::CookieMgr::Read()
{
char buffer[256] = { 0 };
char file[MAX_PATH + 1] = { 0 };
system_utils::GetExePathA(file, MAX_PATH);
strcat_s(file, kConfigFileName);
if (::GetPrivateProfileStringA("user", "cookie", "", buffer, 256, file) > 0) {
cookie_.assign(buffer);
}
if (!cookie_.empty()) {
// 自动登录
std_str* cookie = new std_str(std::move(cookie_));
::PostMessage(main_wnd_, WM_MAINWND_LOGIN_SUCCESS, 0, (LPARAM)cookie);
}
}

void WndMain::CookieMgr::Save()
{
char file[MAX_PATH + 1] = { 0 };
system_utils::GetExePathA(file, MAX_PATH);
strcat_s(file, kConfigFileName);
::WritePrivateProfileStringA("user", "cookie", cookie_.c_str(), file);
}
25 changes: 25 additions & 0 deletions src/BVLoader/wnd/wnd_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ class WndMain
LRESULT OnMsgAsyncSuccess(WPARAM wParam, LPARAM lParam);
LRESULT OnMsgAsyncError(WPARAM wParam, LPARAM lParam);

class CookieMgr {
public:
CookieMgr(HWND wnd);
~CookieMgr();
void SetCookie(std_cstr_ref cookie) {
cookie_ = cookie;
Save();
}
void SetCookie(std_str_r_ref cookie) {
cookie_ = std::move(cookie);
Save();
}
std_cstr_ref GetCookie() const { return cookie_; }
void SetMainWnd(HWND wnd) { main_wnd_ = wnd; }

protected:
void Read();
void Save();

private:
HWND main_wnd_ = NULL;
std_str cookie_;
};

private:
bool user_login_ = false;
bool need_exit_ = false;
Expand All @@ -89,5 +113,6 @@ class WndMain
CListUI* list_finish_ = nullptr;
CControlUI* btn_user_ = nullptr;
std::unordered_map<UINT_PTR, CContainerUI*> map_loading_items_;
std::unique_ptr<CookieMgr> cookie_mgr_;
};

0 comments on commit 89dc624

Please sign in to comment.