Skip to content

Commit

Permalink
Integrate Sponsor NanaZip dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed May 22, 2024
1 parent a441aae commit ad3f090
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
174 changes: 174 additions & 0 deletions NanaZip.UI.Modern/NanaZip.UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <Mile.Xaml.h>

#include "AboutPage.h"
#include "SponsorPage.h"

HWND NanaZip::UI::CreateXamlDialog(
_In_opt_ HWND ParentWindowHandle)
Expand Down Expand Up @@ -193,3 +194,176 @@ winrt::handle NanaZip::UI::ShowAboutDialog(
winrt::check_hresult(::MileXamlThreadUninitialize());
}));
}

namespace
{
static void SplitCommandLineEx(
std::wstring const& CommandLine,
std::vector<std::wstring> const& OptionPrefixes,
std::vector<std::wstring> const& OptionParameterSeparators,
std::wstring& ApplicationName,
std::map<std::wstring, std::wstring>& OptionsAndParameters,
std::wstring& UnresolvedCommandLine)
{
ApplicationName.clear();
OptionsAndParameters.clear();
UnresolvedCommandLine.clear();

size_t arg_size = 0;
for (auto& SplitArgument : Mile::SplitCommandLineWideString(CommandLine))
{
// We need to process the application name at the beginning.
if (ApplicationName.empty())
{
// For getting the unresolved command line, we need to cumulate
// length which including spaces.
arg_size += SplitArgument.size() + 1;

// Save
ApplicationName = SplitArgument;
}
else
{
bool IsOption = false;
size_t OptionPrefixLength = 0;

for (auto& OptionPrefix : OptionPrefixes)
{
if (0 == _wcsnicmp(
SplitArgument.c_str(),
OptionPrefix.c_str(),
OptionPrefix.size()))
{
IsOption = true;
OptionPrefixLength = OptionPrefix.size();
}
}

if (IsOption)
{
// For getting the unresolved command line, we need to cumulate
// length which including spaces.
arg_size += SplitArgument.size() + 1;

// Get the option name and parameter.

wchar_t* OptionStart = &SplitArgument[0] + OptionPrefixLength;
wchar_t* ParameterStart = nullptr;

for (auto& OptionParameterSeparator
: OptionParameterSeparators)
{
wchar_t* Result = wcsstr(
OptionStart,
OptionParameterSeparator.c_str());
if (nullptr == Result)
{
continue;
}

Result[0] = L'\0';
ParameterStart = Result + OptionParameterSeparator.size();

break;
}

// Save
OptionsAndParameters[(OptionStart ? OptionStart : L"")] =
(ParameterStart ? ParameterStart : L"");
}
else
{
// Get the approximate location of the unresolved command line.
// We use "(arg_size - 1)" to ensure that the program path
// without quotes can also correctly parse.
wchar_t* search_start =
const_cast<wchar_t*>(CommandLine.c_str()) + (arg_size - 1);

// Get the unresolved command line. Search for the beginning of
// the first parameter delimiter called space and exclude the
// first space by adding 1 to the result.
wchar_t* command = wcsstr(search_start, L" ") + 1;

// Omit the space. (Thanks to wzzw.)
while (command && *command == L' ')
{
++command;
}

// Save
if (command)
{
UnresolvedCommandLine = command;
}

break;
}
}
}
}
}

void NanaZip::UI::SpecialCommandHandler()
{
std::wstring ApplicationName;
std::map<std::wstring, std::wstring> OptionsAndParameters;
std::wstring UnresolvedCommandLine;

::SplitCommandLineEx(
std::wstring(::GetCommandLineW()),
std::vector<std::wstring>{ L"-", L"/", L"--" },
std::vector<std::wstring>{ L"=", L":" },
ApplicationName,
OptionsAndParameters,
UnresolvedCommandLine);

bool AcquireSponsorEdition = false;

for (auto& Current : OptionsAndParameters)
{
if (0 == _wcsicmp(Current.first.c_str(), L"AcquireSponsorEdition"))
{
AcquireSponsorEdition = true;
}
}

if (AcquireSponsorEdition)
{
HWND WindowHandle = ::CreateWindowExW(
WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
L"Mile.Xaml.ContentWindow",
nullptr,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
nullptr,
nullptr,
nullptr,
nullptr);
if (!WindowHandle)
{
::ExitProcess(static_cast<UINT>(-1));
}

if (FAILED(::MileAllowNonClientDefaultDrawingForWindow(
WindowHandle,
FALSE)))
{
::ExitProcess(static_cast<UINT>(-1));
}

winrt::NanaZip::Modern::SponsorPage Window =
winrt::make<winrt::NanaZip::Modern::implementation::SponsorPage>(
WindowHandle);
NanaZip::UI::ShowXamlWindow(
WindowHandle,
460,
320,
winrt::get_abi(Window),
nullptr);

::ExitProcess(0);
}
}
2 changes: 2 additions & 0 deletions NanaZip.UI.Modern/NanaZip.UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace NanaZip::UI

winrt::handle ShowAboutDialog(
_In_ HWND ParentWindowHandle);

void SpecialCommandHandler();
}

namespace winrt::NanaZip
Expand Down
3 changes: 3 additions & 0 deletions NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/FileManager/FM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "../../../../../pch.h"
#include "../../../../../App.h"
#include "../../../../../NanaZip.UI.h"

using namespace NWindows;
using namespace NFile;
Expand Down Expand Up @@ -517,6 +518,8 @@ static int WINAPI WinMain2(int nCmdShow)
winrt::com_ptr<winrt::NanaZip::Modern::implementation::App> app =
winrt::make_self<winrt::NanaZip::Modern::implementation::App>();

NanaZip::UI::SpecialCommandHandler();

UString commandsString;
// MessageBoxW(0, GetCommandLineW(), L"", 0);

Expand Down

0 comments on commit ad3f090

Please sign in to comment.