From 4e70eb18d135ea29255da6aa8234c2c64b20a87b Mon Sep 17 00:00:00 2001 From: MouriNaruto Date: Tue, 21 May 2024 21:56:27 +0800 Subject: [PATCH] Implement the new toolbar and use it to replace the old menubar and old toolbar. --- NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp | 52 +- .../Assets/Toolbar/Add_24x24.bmp | Bin 2358 -> 0 bytes .../Assets/Toolbar/Add_32x32.bmp | Bin 4150 -> 0 bytes .../Assets/Toolbar/Copy_24x24.bmp | Bin 2358 -> 0 bytes .../Assets/Toolbar/Copy_32x32.bmp | Bin 4150 -> 0 bytes .../Assets/Toolbar/Delete_24x24.bmp | Bin 2358 -> 0 bytes .../Assets/Toolbar/Delete_32x32.bmp | Bin 4150 -> 0 bytes .../Assets/Toolbar/Extract_24x24.bmp | Bin 2358 -> 0 bytes .../Assets/Toolbar/Extract_32x32.bmp | Bin 4150 -> 0 bytes .../Assets/Toolbar/Info_24x24.bmp | Bin 2358 -> 0 bytes .../Assets/Toolbar/Info_32x32.bmp | Bin 4150 -> 0 bytes .../Assets/Toolbar/Move_24x24.bmp | Bin 2358 -> 0 bytes .../Assets/Toolbar/Move_32x32.bmp | Bin 4150 -> 0 bytes .../Assets/Toolbar/Test_24x24.bmp | Bin 2358 -> 0 bytes .../Assets/Toolbar/Test_32x32.bmp | Bin 4150 -> 0 bytes NanaZip.UI.Modern/MainWindowToolBarPage.cpp | 504 ++++++++++++++++++ NanaZip.UI.Modern/MainWindowToolBarPage.h | 62 ++- NanaZip.UI.Modern/MainWindowToolBarPage.xaml | 59 +- NanaZip.UI.Modern/NanaZip.Modern.vcxproj | 46 +- .../NanaZip.Modern.vcxproj.filters | 62 +-- NanaZip.UI.Modern/NanaZip.UI.h | 5 + .../SevenZip/CPP/7zip/UI/FileManager/App.cpp | 248 +++------ .../SevenZip/CPP/7zip/UI/FileManager/App.h | 53 +- .../SevenZip/CPP/7zip/UI/FileManager/FM.cpp | 61 ++- .../CPP/7zip/UI/FileManager/MyLoadMenu.cpp | 64 +-- .../CPP/7zip/UI/FileManager/resource.h | 5 - .../CPP/7zip/UI/FileManager/resource.rc | Bin 10412 -> 17848 bytes .../Strings/en/MainWindowToolBarPage.resw | 136 +++++ .../zh-Hans/MainWindowToolBarPage.resw | 136 +++++ NanaZipPackage/Strings/af/Legacy.resw | 6 +- NanaZipPackage/Strings/ar/Legacy.resw | 6 +- NanaZipPackage/Strings/az-arab/Legacy.resw | 2 +- NanaZipPackage/Strings/be/Legacy.resw | 2 +- NanaZipPackage/Strings/bg/Legacy.resw | 6 +- NanaZipPackage/Strings/bn/Legacy.resw | 6 +- .../Strings/ca-es-valencia/Legacy.resw | 4 +- NanaZipPackage/Strings/cs/Legacy.resw | 6 +- NanaZipPackage/Strings/cy/Legacy.resw | 6 +- NanaZipPackage/Strings/da/Legacy.resw | 6 +- NanaZipPackage/Strings/de/Legacy.resw | 6 +- NanaZipPackage/Strings/el/Legacy.resw | 6 +- NanaZipPackage/Strings/en/Legacy.resw | 6 +- NanaZipPackage/Strings/eo/Legacy.resw | 6 +- NanaZipPackage/Strings/es/Legacy.resw | 6 +- NanaZipPackage/Strings/et/Legacy.resw | 6 +- NanaZipPackage/Strings/eu/Legacy.resw | 6 +- NanaZipPackage/Strings/fi/Legacy.resw | 6 +- NanaZipPackage/Strings/fr/Legacy.resw | 6 +- NanaZipPackage/Strings/fy/Legacy.resw | 6 +- NanaZipPackage/Strings/ga/Legacy.resw | 2 +- NanaZipPackage/Strings/gl/Legacy.resw | 6 +- NanaZipPackage/Strings/gu/Legacy.resw | 6 +- NanaZipPackage/Strings/he/Legacy.resw | 6 +- NanaZipPackage/Strings/hi/Legacy.resw | 6 +- NanaZipPackage/Strings/hr/Legacy.resw | 6 +- NanaZipPackage/Strings/hu/Legacy.resw | 6 +- NanaZipPackage/Strings/hy/Legacy.resw | 2 +- NanaZipPackage/Strings/id/Legacy.resw | 6 +- NanaZipPackage/Strings/is/Legacy.resw | 6 +- NanaZipPackage/Strings/it/Legacy.resw | 6 +- NanaZipPackage/Strings/ja/Legacy.resw | 6 +- NanaZipPackage/Strings/ka/Legacy.resw | 4 +- NanaZipPackage/Strings/ko/Legacy.resw | 6 +- NanaZipPackage/Strings/ku-arab/Legacy.resw | 6 +- NanaZipPackage/Strings/ky-kg/Legacy.resw | 2 +- NanaZipPackage/Strings/lt/Legacy.resw | 6 +- NanaZipPackage/Strings/lv/Legacy.resw | 6 +- NanaZipPackage/Strings/mk/Legacy.resw | 6 +- NanaZipPackage/Strings/mn-cyrl/Legacy.resw | 6 +- NanaZipPackage/Strings/mn-mong/Legacy.resw | 6 +- NanaZipPackage/Strings/mr/Legacy.resw | 4 +- NanaZipPackage/Strings/ms/Legacy.resw | 6 +- NanaZipPackage/Strings/nb/Legacy.resw | 6 +- NanaZipPackage/Strings/ne/Legacy.resw | 6 +- NanaZipPackage/Strings/nl/Legacy.resw | 6 +- NanaZipPackage/Strings/nn/Legacy.resw | 6 +- NanaZipPackage/Strings/pa-in/Legacy.resw | 6 +- NanaZipPackage/Strings/pl/Legacy.resw | 6 +- NanaZipPackage/Strings/ps/Legacy.resw | 6 +- NanaZipPackage/Strings/pt-br/Legacy.resw | 6 +- NanaZipPackage/Strings/pt/Legacy.resw | 6 +- NanaZipPackage/Strings/ro/Legacy.resw | 6 +- NanaZipPackage/Strings/ru/Legacy.resw | 2 +- NanaZipPackage/Strings/si/Legacy.resw | 6 +- NanaZipPackage/Strings/sk/Legacy.resw | 6 +- NanaZipPackage/Strings/sl/Legacy.resw | 6 +- NanaZipPackage/Strings/sq/Legacy.resw | 6 +- NanaZipPackage/Strings/sv/Legacy.resw | 6 +- NanaZipPackage/Strings/sw/Legacy.resw | 6 +- NanaZipPackage/Strings/ta/Legacy.resw | 2 +- NanaZipPackage/Strings/th/Legacy.resw | 6 +- NanaZipPackage/Strings/tk-cyrl/Legacy.resw | 6 +- NanaZipPackage/Strings/tr/Legacy.resw | 6 +- NanaZipPackage/Strings/tt-arab/Legacy.resw | 2 +- NanaZipPackage/Strings/ug-arab/Legacy.resw | 6 +- NanaZipPackage/Strings/uk/Legacy.resw | 6 +- NanaZipPackage/Strings/uz-cyrl/Legacy.resw | 6 +- NanaZipPackage/Strings/uz-latn/Legacy.resw | 6 +- NanaZipPackage/Strings/yo-latn/Legacy.resw | 8 +- NanaZipPackage/Strings/zh-Hans/Legacy.resw | 6 +- NanaZipPackage/Strings/zh-Hant/Legacy.resw | 6 +- 101 files changed, 1257 insertions(+), 632 deletions(-) delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Add_24x24.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Add_32x32.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Copy_24x24.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Copy_32x32.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Delete_24x24.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Delete_32x32.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Extract_24x24.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Extract_32x32.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Info_24x24.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Info_32x32.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Move_24x24.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Move_32x32.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Test_24x24.bmp delete mode 100644 NanaZip.UI.Modern/Assets/Toolbar/Test_32x32.bmp create mode 100644 NanaZip.UI.Modern/Strings/en/MainWindowToolBarPage.resw create mode 100644 NanaZip.UI.Modern/Strings/zh-Hans/MainWindowToolBarPage.resw diff --git a/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp b/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp index 84f8bdac6..0de885c10 100644 --- a/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp +++ b/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp @@ -331,6 +331,21 @@ namespace } } + static bool IsFileManagerWindow( + _In_ HWND WindowHandle) + { + wchar_t ClassName[256] = { 0 }; + if (0 != ::GetClassNameW( + WindowHandle, + ClassName, + 256)) + { + return (0 == std::wcscmp(ClassName, L"FM")); + } + + return false; + } + LRESULT CALLBACK WindowSubclassCallback( _In_ HWND hWnd, _In_ UINT uMsg, @@ -397,7 +412,17 @@ namespace bool ShouldExtendFrame = (g_ShouldAppsUseDarkMode && ::IsStandardDynamicRangeMode()); - MARGINS Margins = { (ShouldExtendFrame ? -1 : 0) }; + MARGINS Margins = { 0 }; + if (ShouldExtendFrame) + { + Margins = { -1 }; + } + else if (::IsFileManagerWindow(hWnd)) + { + UINT DpiValue = ::GetDpiForWindow(hWnd); + Margins.cyTopHeight = + ::MulDiv(48, DpiValue, USER_DEFAULT_SCREEN_DPI); + } ::DwmExtendFrameIntoClientArea(hWnd, &Margins); ::EnumChildWindows( @@ -439,6 +464,15 @@ namespace MARGINS Margins = { -1 }; ::DwmExtendFrameIntoClientArea(hWnd, &Margins); } + else if (::IsFileManagerWindow(hWnd)) + { + UINT DpiValue = ::GetDpiForWindow(hWnd); + + MARGINS Margins = { 0 }; + Margins.cyTopHeight = + ::MulDiv(48, DpiValue, USER_DEFAULT_SCREEN_DPI); + ::DwmExtendFrameIntoClientArea(hWnd, &Margins); + } ::RefreshWindowTheme(hWnd); @@ -485,6 +519,22 @@ namespace break; } + case WM_DPICHANGED: + { + bool ShouldExtendFrame = + (g_ShouldAppsUseDarkMode && ::IsStandardDynamicRangeMode()); + if (!ShouldExtendFrame && ::IsFileManagerWindow(hWnd)) + { + UINT DpiValue = ::GetDpiForWindow(hWnd); + + MARGINS Margins = { 0 }; + Margins.cyTopHeight = + ::MulDiv(48, DpiValue, USER_DEFAULT_SCREEN_DPI); + ::DwmExtendFrameIntoClientArea(hWnd, &Margins); + } + + break; + } default: break; } diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Add_24x24.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Add_24x24.bmp deleted file mode 100644 index 90ed3a3cb5639976091dba79d5b7a187cd7833b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2358 zcmZ?rHREIe12Z700mKqe%*dbsWI@0YJ_ZI5hJgG!UvRhKxvyA7+W4ZcI?4%sycQpJ5HvB<(u(7d`th_@^{F18%00n61#sB~S diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Add_32x32.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Add_32x32.bmp deleted file mode 100644 index 70b4bfb6cd7a67a99f420af45b9ca172733b88cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4150 zcmZ?rH4|U}12Z700mKSW%m`)yIY4lP4}u{)28ItGKKviWqhUa58jzQl{|CaP>Z6u= zVEX+J!qhU4RC7k{9}WM}^f#LSNG&(0rJma552!4MnMo@eUwtvq_LCYfurMN3AGOqv k+CN(VfYJc9(i5rXjHbWQ^f!>{4^&^^t4~Nx&m&bm0H60Ms{jB1 diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Copy_24x24.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Copy_24x24.bmp deleted file mode 100644 index 67c5f4fc298c87924d54bf07610a5a5fac508c34..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2358 zcmeHJF$#k)6isoeL+6ei>n?(8#6hqQp1>1$7!TnE99?@EH%}1FOB?t^V$(u~f`M;- zlJ{SJ9^^;7>0s#?qprpIq~;>uejql{wgP1uI4;=kvGl@!`VM+q_uO=3YfaC)me+8 zP-jWg)JY@YuovRYy!9CCP1C4#?3L%a6{}-t4?N=N9Q7$b^(ki0M{bC-VJIi{ZFqD3 z;NRYLs?nj(p^vT)|9HPpn|$Vv+Uk=ZZ^|$Xs=oTrpWbz7RaKR>mQ$?uf#0kD8i(G; P`$hSGd4IDk+x!=-Q{3k5 diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Copy_32x32.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Copy_32x32.bmp deleted file mode 100644 index 13a9eff578d110accd3a06b0c6a5ddea75757ca7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4150 zcmchaF>b<85JZWPC?j70DP?F}SO|$WeOkB$_n`7ETvO7~q^6=nRK5Tw_{3|n78)_^ zU@0K|{LJp`8*Gg9`TCw^gZ4FR{(d&=<8QsS|23j{{k&h-RSgE`^ZCNo>2ykq#Uf={ zmKy&>S;OHl6-ANu`+Z_urCye0GM18g&odg0(r&lw^&Zyib(fpxdD?6?y*SEsqUUfp zbl1IFtzMSv?_;@Kw%0zN&%12(voa?ppG@uRxRK_BWUhxJts z`cN}|R989ZLmlO?zRE!#YQ~T1DhGY2qa4;(Ip{;p_)%TupbvGF!}=-*eW)2fs;eCI zp^kD`U*-6D!#V1l``NB?{H)|0bi7p dcn$tMyz2ao`Tjik{p-7{zdtbF^nd>T`UPa9f%O0Y diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Delete_24x24.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Delete_24x24.bmp deleted file mode 100644 index f88368cb10613cead682fa43be2514e8d54128ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2358 zcmb`Ip^gGE6h&u4Lb8YvBqSRWl2v3RL7)(1{2B}ffk0z$XbgtW;0G`$)JlTF@dY@( zpzNIPzDapAg@)`TrLV8|o|bmnNxypUk$rmEZ<3Xdzw#D+X3_8S9Y+yGp6m5`(`C6_ znp&-9GR-Zdpv9v(W$pEPZMp4s+oWk4RM0XHyk$%`*YEdDy_T_T1>o}cGAL?9>#CX^P7?RWVZnv|V)oOL8iR0MJ z=kq*AOwRS=fe*vYyRp1Go6Y7`OnUn=E(Ru z@7pI|9?s!#u=_uo%?kf7V4e5JidTqlg9x2@yfFB^449RXU0^oPdIc1JF=W(9qB$aSIv_kdhm40y<8x zWWULetjT`cY@#3;+cTc`XTkQ`Z|{Sbn)?ij@2n`VU**ZQicazQc)pi=uU5NWuQyfp z`+eSQHuGZatx7>G7>XaV&*$^Xx;9s^LR!{$KA-b?z3%iEi^W5+J`1tP1uQUqU#Pv^ zZe3iz-%pNFJTQ<0m}-o*FPBRfGaiqVV=RMxFrW`6ZLxYfow^v*v9U3K71n4pa{BA_ z`q%nk;Q7If^*4AJ^A5800{dT+UVvfh-kC;xUlcU&JWd{TLVA>ef z$9R-7zw#+N7$Kk4IGs)|-$tWRny+FhJNRJ154P2_{lno9{JoTpvV+h66Ktzz`8tswbd()@t|zdqp6$e84A57#>wx@GUm3IYWV|B_qt;)MHrb|E9Rp^~w<*Yz{tWIH9IV;6<=}$S+4TnQF zM^g4_a#L&WLC{b!d{2eusEUo*xwgvAA-!JDJvZ0rf7H-q&fIhVLzfyUdolB4%{5$h zmgoF>u!yC#f)>7jg@uUNSZJ+pA=ua(un{X; zD=RynU=shA%(Cw7UG@SV?Ct0Lc4l^V*8M2GTHaT>|DAhz`z3$(wGk$*|*JR zGtif?BOZ^7wU9CKPq*6@GO1MRAnDAGtm5^gQP=f&`&I&a% zF^9M_)gSWETV|t;_|dU3HyVv1@nze2AH+|m(|OPva~xM_oA`%gRX%6lL#=TKaTg&I zl@FQebV|rKDi{4?u_)MVZxsF64%Em=$XkQKfadc#A&>F=VzCfD`!Anax?1+*v-vpd zu-ptEnB+g%4q1QQIjLi~H;}>ompQsNbU{u=ZU*Ns{~&kOYBg=VsCsZ8`rvIb;X_BZ zw_GlV`VxMY{b};PAl{(|-WQ!e!p2PAN3i+6hp~d@!ru2*t3}J@(&$`+_|F{w2GK?b A@c;k- diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Extract_32x32.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Extract_32x32.bmp deleted file mode 100644 index e7e4a060227657ac840516c5b7d1937eb5e08a02..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4150 zcmd^CEsp{*5amLGAmMTb1A+@`ktBdZoj;91VEHNh033#76&6E+Bd1X~BnrnbD7SC9 z*Ua_0Z5POzBPla&XXd?r&whLk-b(3jko-qUdH*Rdsg_id-`DG{+-jxL<#M?`tHg1v zy4|j-)oLnqFM7xsKUw_;DyFwnn4j#1G*hW4N$veLM@4*o!th*@pSR+R#TzX&0hPU+6{S%egbTu#FNs84O6cao!{jdOaxFsg@5N%F o-xctXvF_2a26?_eILF8x?!mM9_vCaseHyln&wpzB22a-Mc>n+a diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Info_24x24.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Info_24x24.bmp deleted file mode 100644 index 82de9d94157c3f1d24c8d67ed7c6b018932f9927..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2358 zcmc&#vCFAp6n9hVDw2|$!kuK0D19X+Wl-*7pk%OGEMhPSF-TY$EhfsMl=YKM2Ak1j z^B0`&`ki~9x2N}eU*7vI_pRfc_c-Twe&;;z^E|0vZ{JP)yghz{5Bc#|zL|bLtUu4Y z-DHA@=YGF`{7*TZPBa>gsN3yQqtRf!Ua#qPyU|y9A-7(ylg(zMN1q>BVm6y8kx0;P zxBI6$^ZA?{4hQ4>8(C8WSLJh4x_WM2mACJd1|Ch1!?A2<;{4$x$ryjuB zYPCM?554#M{ZF}ay;7;fHI~bz5(gXKN2O9xd~%Mk#hk^vmd0$rGo4N=ScO7?@h_K) z;?v4Cf{(mhF2}PL>kteE38IB5`;6kxW;5msjePWjnlhG_Z4@7Kz`U!~Dr3S%t`?^3 zGm4KK8B?}pJhlB*e2>RN$z<{+|5~j^cDwy$+;+R=`Sf}{js>>U>3o@|?nm!koH3|_ zm{zOB^%jf8(;CHMkj;iwU#atOe&O6ljc0vm<%L2a z#uj@@9V6axH;LFlAV8bVMz=*9|sq1)}Ya`)luA9FpMfEs!W2Pf%{Z z`|;U%Erh>L@c$mPx1aVB_5vdKeO0dQN)-y{^ZD}M z{*J-vbTX^e%JlnvQ>|7_u~;-g{4TUosT7Ve2M@e?#q)SPn!#XTz!1E&FTBVgdygH{ z>GTG-R;!uOXk_;L{f%yL7-J3|u@5^Ii$!J|h+nVQi}W;`O|#qWob|wqjM#xL*EoRP zZnr~O)|eQ$%G!L$N}hDPT_-*8VRxlcG289dNyf(2G&<0Q&NLga7d~vx16%Asm&9Q< zo5lKcI2=s5Tn_Q?iMe3fU-6AtfMw6KU+}%vYWxL$D+85nmfTelKIq`k7 z+1$)&KD&=DnmwLGqZ@v(bd6$77;iKh&e&jN#YYAV%ImzN&#C+%zFJv;us`G=g& zqcp#nkIO&b{pW&b^Th2x-}*C|Ow4>fkMh{Yile3e=yS-Y{*K4va37IN^y9GXv84J7 zU)J--2S4fj0pI8R%@Th(f7xqEbxwF5dH+beTRijr#X3Cd{>hzIpZRufY8pPN3FLPk o_itBhZ3kkF@pHcyaw_zQ43R#4qXn$$sHY>ihou25e90<^TWy diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Move_24x24.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Move_24x24.bmp deleted file mode 100644 index 88041bacd2801dd32179ace70eabbd85211d1276..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2358 zcmb`Ip>6^}5QeWo6>*NFhR~pn7ifYb=MXh$1R-b)4voR!kr))gU`Vii1RMg5;|Z4D zH|=c5_E>h4UNY?P&p-dp4zox8`SF^_^HF?eg}wdSOY&ZLKhIa1B$z(e>-DC#-EK{@ z*)&D$hT$I$2cvO!CFb(caCv;6&*!3BtyWE*=VJKmL(I*I;h#Vi{%dn1JTfYcSRqL;<0>RJ^TGWs{S&5Y(Hc9 zoZB}K!{N~OMtcNC-$Lh&ys~+2wOTSO$K%oNfzSL9WB&2k3xBm*S)SJ7TUD#wZreP3 zH1GHHX*`RK$788)Hk%oYTEU*>#l*8LlRHSi@ndpBxH@c4Y?RL9T`);>0=kr;92QXhwXl%J$igv%>w|e-@5V265G9K^eTCFDL zzPIc3y7cTGFVpa0yICBqaC{n%V)UAPU!Q&ZKhg!~%pvE8$6UdU>689{ sF!R1Th?V{Rz8vl*ceK;#Jk?emxa81N#U8Db$wbZ^^KR7pN3N^;4H=mmzyJUM diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Move_32x32.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Move_32x32.bmp deleted file mode 100644 index 48a6924710665b6c39c3467a10a6b8ee7e6b35fc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4150 zcmdUxudX676vo-$5ClU=NC+#DsGE==$U4LtG!lcsVbB;14iY@!1u#6o@&-603da-7 z-TC$IN4lL31I$2jNy_P*f8XipIcYM zZ`l)fyoZVuofd)B_u zXc+s&ViEBzEM&qEPgJqpV^0ocC#pU2aB*m)qAS}#7T)v7sD<-gzWNAd?x z@p1lQBYb?}(-*gJ@1fi6*7(fl^8s_&Foy@8&6hk&+UxZUj(vux_K{_Y}h86a(0ssekBr*U1 diff --git a/NanaZip.UI.Modern/Assets/Toolbar/Test_32x32.bmp b/NanaZip.UI.Modern/Assets/Toolbar/Test_32x32.bmp deleted file mode 100644 index 39650107b09352e1f6f77cd612da7daaf3543463..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4150 zcmZ?rH4|U}12Z700mKSW%m`)yIY4lP4}u{)28ItGKKviWqhT +#include + +#include "../SevenZip/CPP/Common/Common.h" +#include "../SevenZip/CPP/7zip/UI/FileManager/resource.h" +#include "../SevenZip/CPP/7zip/UI/FileManager/LangUtils.h" + +#include "NanaZip.UI.h" + +#include + +namespace +{ + DWORD GetShellProcessId() + { + HWND ShellWindowHandle = ::GetShellWindow(); + if (!ShellWindowHandle) + { + return static_cast(-1); + } + + DWORD ShellProcessId = static_cast(-1); + if (!::GetWindowThreadProcessId(ShellWindowHandle, &ShellProcessId)) + { + return static_cast(-1); + } + return ShellProcessId; + } + + std::wstring GetCurrentProcessModulePath() + { + // 32767 is the maximum path length without the terminating null character. + std::wstring Path(32767, L'\0'); + Path.resize(::GetModuleFileNameW( + nullptr, &Path[0], static_cast(Path.size()))); + return Path; + } +} + +namespace winrt +{ + using Windows::Foundation::Point; + using Windows::Foundation::IAsyncAction; + using Windows::Services::Store::StoreProduct; + using Windows::Services::Store::StoreProductQueryResult; + using Windows::System::DispatcherQueuePriority; + using Windows::UI::Xaml::Automation::AutomationProperties; + using Windows::UI::Xaml::Controls::AppBarButton; + using Windows::UI::Xaml::Controls::ToolTipService; + using Windows::UI::Xaml::Media::GeneralTransform; +} + using namespace winrt; using namespace Windows::UI::Xaml; +namespace +{ + namespace ToolBarCommandID + { + enum + { + Add = 1070, + Extract = 1071, + Test = 1072, + }; + } + + namespace MenuIndex + { + enum + { + File = 0, + Edit, + View, + Bookmarks + }; + } +} + namespace winrt::NanaZip::Modern::implementation { MainWindowToolBarPage::MainWindowToolBarPage( @@ -19,5 +95,433 @@ namespace winrt::NanaZip::Modern::implementation void MainWindowToolBarPage::InitializeComponent() { MainWindowToolBarPageT::InitializeComponent(); + + DWORD ToolBarResources[10] = + { + IDS_ADD, + IDS_EXTRACT, + IDS_TEST, + IDS_BUTTON_COPY, + IDS_BUTTON_MOVE, + IDS_BUTTON_DELETE, + IDS_BUTTON_INFO, + IDM_OPTIONS, + IDM_BENCHMARK, + IDM_ABOUT + }; + + winrt::AppBarButton ToolBarButtons[10] = + { + this->AddButton(), + this->ExtractButton(), + this->TestButton(), + this->CopyButton(), + this->MoveButton(), + this->DeleteButton(), + this->InfoButton(), + this->OptionsButton(), + this->BenchmarkButton(), + this->AboutButton() + }; + + const std::size_t ToolBarButtonCount = + sizeof(ToolBarButtons) / sizeof(*ToolBarButtons); + + for (size_t i = 0; i < ToolBarButtonCount; ++i) + { + std::wstring Resource = std::wstring( + ::LangString(ToolBarResources[i])); + winrt::AutomationProperties::SetName( + ToolBarButtons[i], + Resource); + winrt::ToolTipService::SetToolTip( + ToolBarButtons[i], + winrt::box_value(Resource)); + } + + this->m_DispatcherQueue = + winrt::DispatcherQueue::GetForCurrentThread(); + + this->m_StoreContext = winrt::StoreContext::GetDefault(); + if (this->m_StoreContext) + { + winrt::check_hresult( + this->m_StoreContext.as()->Initialize( + this->m_WindowHandle)); + } + } + + void MainWindowToolBarPage::PageLoaded( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + this->RefreshSponsorButtonContent(); + } + + void MainWindowToolBarPage::AddButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + ToolBarCommandID::Add, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::ExtractButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + ToolBarCommandID::Extract, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::TestButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + ToolBarCommandID::Test, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::CopyButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + IDM_COPY_TO, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::MoveButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + IDM_MOVE_TO, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::DeleteButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + IDM_DELETE, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::InfoButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + IDM_PROPERTIES, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::OptionsButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + IDM_OPTIONS, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::BenchmarkButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + ::PostMessageW( + this->m_WindowHandle, + WM_COMMAND, + MAKEWPARAM( + IDM_BENCHMARK, + BN_CLICKED), + 0); + } + + void MainWindowToolBarPage::AboutButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + NanaZip::UI::ShowAboutDialog(this->m_WindowHandle); + } + + void MainWindowToolBarPage::MoreButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + winrt::AppBarButton Button = sender.as(); + + winrt::GeneralTransform Transform = + Button.TransformToVisual(this->Content()); + winrt::Point LogicalPoint = Transform.TransformPoint( + winrt::Point(0.0f, 0.0f)); + + extern HMENU g_MoreMenu; + + UINT DpiValue = ::GetDpiForWindow(this->m_WindowHandle); + + POINT MenuPosition = { 0 }; + MenuPosition.x = ::MulDiv( + static_cast(LogicalPoint.X), + DpiValue, + USER_DEFAULT_SCREEN_DPI); + MenuPosition.y = ::MulDiv( + 48, + DpiValue, + USER_DEFAULT_SCREEN_DPI); + ::MapWindowPoints( + this->m_WindowHandle, + HWND_DESKTOP, + &MenuPosition, + 1); + + ::SendMessageW( + this->m_WindowHandle, + WM_INITMENUPOPUP, + reinterpret_cast(::GetSubMenu( + g_MoreMenu, + MenuIndex::File)), + MenuIndex::File); + ::SendMessageW( + this->m_WindowHandle, + WM_INITMENUPOPUP, + reinterpret_cast(::GetSubMenu( + g_MoreMenu, + MenuIndex::Edit)), + MenuIndex::Edit); + ::SendMessageW( + this->m_WindowHandle, + WM_INITMENUPOPUP, + reinterpret_cast(::GetSubMenu( + g_MoreMenu, + MenuIndex::View)), + MenuIndex::View); + ::SendMessageW( + this->m_WindowHandle, + WM_INITMENUPOPUP, + reinterpret_cast(::GetSubMenu( + g_MoreMenu, + MenuIndex::Bookmarks)), + MenuIndex::Bookmarks); + + WPARAM Command = ::TrackPopupMenuEx( + g_MoreMenu, + TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RETURNCMD, + MenuPosition.x, + MenuPosition.y, + this->m_WindowHandle, + nullptr); + if (Command) + { + ::PostMessageW(this->m_WindowHandle, WM_COMMAND, Command, 0); + } + } + + void MainWindowToolBarPage::SponsorButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e) + { + UNREFERENCED_PARAMETER(sender); + UNREFERENCED_PARAMETER(e); + + winrt::handle(Mile::CreateThread([=]() + { + DWORD ShellProcessId = ::GetShellProcessId(); + if (static_cast(-1) == ShellProcessId) + { + return; + } + + HANDLE ShellProcessHandle = nullptr; + + auto Handler = Mile::ScopeExitTaskHandler([&]() + { + if (ShellProcessHandle) + { + ::CloseHandle(ShellProcessHandle); + } + }); + + ShellProcessHandle = ::OpenProcess( + PROCESS_CREATE_PROCESS, + FALSE, + ShellProcessId); + if (!ShellProcessHandle) + { + return; + } + + SIZE_T AttributeListSize = 0; + ::InitializeProcThreadAttributeList( + nullptr, + 1, + 0, + &AttributeListSize); + + std::vector AttributeListBuffer = + std::vector(AttributeListSize); + + PPROC_THREAD_ATTRIBUTE_LIST AttributeList = + reinterpret_cast( + &AttributeListBuffer[0]); + + if (!::InitializeProcThreadAttributeList( + AttributeList, + 1, + 0, + &AttributeListSize)) + { + return; + } + + if (!::UpdateProcThreadAttribute( + AttributeList, + 0, + PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, + &ShellProcessHandle, + sizeof(ShellProcessHandle), + nullptr, + nullptr)) + { + return; + } + + STARTUPINFOEXW StartupInfoEx = { 0 }; + PROCESS_INFORMATION ProcessInformation = { 0 }; + StartupInfoEx.StartupInfo.cb = sizeof(STARTUPINFOEXW); + StartupInfoEx.lpAttributeList = AttributeList; + + std::wstring ApplicationName = ::GetCurrentProcessModulePath(); + + if (!::CreateProcessW( + ApplicationName.c_str(), + const_cast(L"NanaZip --AcquireSponsorEdition"), + nullptr, + nullptr, + TRUE, + CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT, + nullptr, + nullptr, + &StartupInfoEx.StartupInfo, + &ProcessInformation)) + { + return; + } + + ::CloseHandle(ProcessInformation.hThread); + ::WaitForSingleObjectEx(ProcessInformation.hProcess, INFINITE, FALSE); + ::CloseHandle(ProcessInformation.hProcess); + + this->RefreshSponsorButtonContent(); + })); + } + + void MainWindowToolBarPage::RefreshSponsorButtonContent() + { + winrt::handle(Mile::CreateThread([=]() + { + if (this->m_StoreContext) + { + bool Sponsored = false; + + winrt::StoreProductQueryResult ProductQueryResult = + this->m_StoreContext.GetStoreProductsAsync( + { L"Durable" }, + { L"9N9DNPT6D6Z9" }).get(); + for (auto Item : ProductQueryResult.Products()) + { + winrt::StoreProduct Product = Item.Value(); + Sponsored = Product.IsInUserCollection(); + } + + if (!this->m_DispatcherQueue) + { + return; + } + this->m_DispatcherQueue.TryEnqueue( + winrt::DispatcherQueuePriority::Normal, + [=]() + { + this->SponsorButton().Content( + winrt::box_value(Mile::WinRT::GetLocalizedString( + Sponsored + ? L"MainWindowToolBarPage/SponsorButton/SponsoredText" + : L"MainWindowToolBarPage/SponsorButton/AcquireText"))); + }); + } + })); } } diff --git a/NanaZip.UI.Modern/MainWindowToolBarPage.h b/NanaZip.UI.Modern/MainWindowToolBarPage.h index 7e6446cff..f382b3b3c 100644 --- a/NanaZip.UI.Modern/MainWindowToolBarPage.h +++ b/NanaZip.UI.Modern/MainWindowToolBarPage.h @@ -4,12 +4,16 @@ #include +#include +#include + namespace winrt { using Windows::Foundation::IInspectable; + using Windows::Services::Store::StoreContext; + using Windows::System::DispatcherQueue; using Windows::UI::Xaml::RoutedEventArgs; } - namespace winrt::NanaZip::Modern::implementation { struct MainWindowToolBarPage : MainWindowToolBarPageT @@ -21,9 +25,65 @@ namespace winrt::NanaZip::Modern::implementation void InitializeComponent(); + void PageLoaded( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void AddButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void ExtractButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void TestButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void CopyButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void MoveButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void DeleteButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void InfoButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void OptionsButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void BenchmarkButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void AboutButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void MoreButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + + void SponsorButtonClick( + winrt::IInspectable const& sender, + winrt::RoutedEventArgs const& e); + private: HWND m_WindowHandle; + winrt::DispatcherQueue m_DispatcherQueue = nullptr; + winrt::StoreContext m_StoreContext = nullptr; + + void RefreshSponsorButtonContent(); }; } diff --git a/NanaZip.UI.Modern/MainWindowToolBarPage.xaml b/NanaZip.UI.Modern/MainWindowToolBarPage.xaml index 5f9005ff5..11353367b 100644 --- a/NanaZip.UI.Modern/MainWindowToolBarPage.xaml +++ b/NanaZip.UI.Modern/MainWindowToolBarPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:NanaZip.Modern" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + Loaded="PageLoaded" mc:Ignorable="d"> @@ -27,33 +28,38 @@ + ToolTipService.ToolTip="[Add]" /> + ToolTipService.ToolTip="[Extract]" /> + ToolTipService.ToolTip="[Test]" /> + ToolTipService.ToolTip="[Copy]" /> + AutomationProperties.Name="[Move]" + Click="MoveButtonClick" + ToolTipService.ToolTip="[Move]"> @@ -61,14 +67,16 @@ + ToolTipService.ToolTip="[Delete]" /> + AutomationProperties.Name="[Info]" + Click="InfoButtonClick" + ToolTipService.ToolTip="[Info]"> @@ -77,28 +85,32 @@ + ToolTipService.ToolTip="[Options]" /> + ToolTipService.ToolTip="[Benchmark]" /> + ToolTipService.ToolTip="[About]" /> + ToolTipService.ToolTip="[More]" />