Skip to content

Commit

Permalink
Remove C++/WinRT dependency for NanaZip.Core and NanaZip.Shared proje…
Browse files Browse the repository at this point in the history
…cts.
  • Loading branch information
MouriNaruto committed Jan 14, 2024
1 parent 66c2bc4 commit b5a61e6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 67 deletions.
2 changes: 0 additions & 2 deletions NanaZip.Core/NanaZip.Core.Sfx.Console.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<MileProjectType>ConsoleApplication</MileProjectType>
<MileProjectManifestFile>NanaZip.Core.Sfx.Console.manifest</MileProjectManifestFile>
<MileProjectEnableVCLTLSupport>true</MileProjectEnableVCLTLSupport>
<MileProjectEnableCppWinRTSupport>true</MileProjectEnableCppWinRTSupport>
<MileProjectUseProjectProperties>true</MileProjectUseProjectProperties>
<MileProjectCompanyName>M2-Team</MileProjectCompanyName>
<MileProjectFileDescription>NanaZip Self Extracting Executable (Console)</MileProjectFileDescription>
Expand All @@ -28,7 +27,6 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">NoExtensions</EnableEnhancedInstructionSet>
<AdditionalOptions>%(AdditionalOptions) /Wv:18</AdditionalOptions>
</ClCompile>
Expand Down
3 changes: 1 addition & 2 deletions NanaZip.Core/NanaZip.Core.Sfx.Setup.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<MileProjectType>WindowsApplication</MileProjectType>
<MileProjectManifestFile>NanaZip.Core.Sfx.Setup.manifest</MileProjectManifestFile>
<MileProjectEnableVCLTLSupport>true</MileProjectEnableVCLTLSupport>
<MileProjectEnableCppWinRTSupport>true</MileProjectEnableCppWinRTSupport>
<MileProjectUseProjectProperties>true</MileProjectUseProjectProperties>
<MileProjectCompanyName>M2-Team</MileProjectCompanyName>
<MileProjectFileDescription>NanaZip Self Extracting Executable (Setup)</MileProjectFileDescription>
Expand All @@ -31,7 +30,7 @@
<ClCompile>
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">NoExtensions</EnableEnhancedInstructionSet>
<AdditionalOptions>%(AdditionalOptions) /Wv:18</AdditionalOptions>
<PreprocessorDefinitions>Z7_NO_REGISTRY;Z7_NO_CRYPTO;WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>Z7_NO_REGISTRY;Z7_NO_CRYPTO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<LargeAddressAware>true</LargeAddressAware>
Expand Down
3 changes: 1 addition & 2 deletions NanaZip.Core/NanaZip.Core.Sfx.Windows.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<MileProjectType>WindowsApplication</MileProjectType>
<MileProjectManifestFile>NanaZip.Core.Sfx.Windows.manifest</MileProjectManifestFile>
<MileProjectEnableVCLTLSupport>true</MileProjectEnableVCLTLSupport>
<MileProjectEnableCppWinRTSupport>true</MileProjectEnableCppWinRTSupport>
<MileProjectUseProjectProperties>true</MileProjectUseProjectProperties>
<MileProjectCompanyName>M2-Team</MileProjectCompanyName>
<MileProjectFileDescription>NanaZip Self Extracting Executable (Windows)</MileProjectFileDescription>
Expand All @@ -31,7 +30,7 @@
<ClCompile>
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">NoExtensions</EnableEnhancedInstructionSet>
<AdditionalOptions>%(AdditionalOptions) /Wv:18</AdditionalOptions>
<PreprocessorDefinitions>Z7_NO_REGISTRY;Z7_LANG;WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>Z7_NO_REGISTRY;Z7_LANG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<LargeAddressAware>true</LargeAddressAware>
Expand Down
2 changes: 1 addition & 1 deletion NanaZip.Core/NanaZip.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<ItemDefinitionGroup>
<ClCompile>
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">NoExtensions</EnableEnhancedInstructionSet>
<PreprocessorDefinitions>Z7_EXTERNAL_CODECS;Z7_LARGE_PAGES;NSIS_SCRIPT;ZSTD_LEGACY_SUPPORT;ZSTD_MULTITHREAD;NO_XXHASH;FL2_7ZIP_BUILD;WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>Z7_EXTERNAL_CODECS;Z7_LARGE_PAGES;NSIS_SCRIPT;ZSTD_LEGACY_SUPPORT;ZSTD_MULTITHREAD;NO_XXHASH;FL2_7ZIP_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'=='x64'">Z7_LZMA_DEC_OPT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4100;4113;4127;4146;4189;4200;4244;4267;4334;4702;</DisableSpecificWarnings>
</ClCompile>
Expand Down
117 changes: 59 additions & 58 deletions NanaZip.Shared/ModernWin32FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,79 @@
*
* LICENSE: The MIT License
*
* DEVELOPER: reflectronic (john-tur@outlook.com)
* MouriNaruto (KurikoMouri@outlook.jp)
* MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com)
* reflectronic (john-tur@outlook.com)
*/

#include <Windows.h>
#include <ShlObj_core.h>
#include <winrt/base.h>

EXTERN_C PIDLIST_ABSOLUTE WINAPI ModernSHBrowseForFolderW(LPBROWSEINFOW uType)
EXTERN_C PIDLIST_ABSOLUTE WINAPI ModernSHBrowseForFolderW(
_In_ LPBROWSEINFOW lpbi)
{
winrt::com_ptr<IFileDialog> fileDialog = winrt::try_create_instance<IFileDialog>(CLSID_FileOpenDialog);
LPITEMIDLIST IDList = nullptr;

if (!fileDialog)
IFileDialog* FileDialog = nullptr;
if (SUCCEEDED(::CoCreateInstance(
CLSID_FileOpenDialog,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&FileDialog))))
{
return nullptr;
}
DWORD Flags = 0;
if (SUCCEEDED(FileDialog->GetOptions(
&Flags)))
{
if (SUCCEEDED(FileDialog->SetOptions(
Flags | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM)))
{
if (SUCCEEDED(FileDialog->SetTitle(
lpbi->lpszTitle)))
{
// 7-Zip does not use the pidlRoot parameter to configure
// the default folder. Instead, it sets it by configuring
// the message loop for the shell dialog, passing the path
// of the default folder through the lParam, and navigating
// to that folder inside the message loop.
//
// Since we cannot augment the IFileDialog's message loop,
// we will reach into the lParam given to us to find the
// initial path and hope that 7-Zip does not change this
// behavior.

DWORD flags;
if (FAILED(fileDialog->GetOptions(&flags)))
{
return nullptr;
}
IShellItem* DefaultFolder = nullptr;
if (SUCCEEDED(::SHCreateItemFromParsingName(
reinterpret_cast<PCWSTR>(lpbi->lParam),
nullptr,
IID_PPV_ARGS(&DefaultFolder))))
{
if (SUCCEEDED(FileDialog->SetDefaultFolder(
DefaultFolder)))
{
if (SUCCEEDED(FileDialog->Show(
lpbi->hwndOwner)))
{
IShellItem* Result = nullptr;
if (SUCCEEDED(FileDialog->GetResult(
&Result)))
{
::SHGetIDListFromObject(Result, &IDList);

if (FAILED(fileDialog->SetOptions(flags | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM)))
{
return nullptr;
}
Result->Release();
}
}
}

if (FAILED(fileDialog->SetTitle(uType->lpszTitle)))
{
return nullptr;
}

// 7-Zip does not use the pidlRoot parameter to configure the default folder.
// Instead, it sets it by configuring the message loop for the shell dialog,
// passing the path of the default folder through the lParam, and navigating
// to that folder inside the message loop.
//
// Since we cannot augment the IFileDialog's message loop, we will reach into
// the lParam given to us to find the initial path and hope that 7-Zip does
// not change this behavior.

winrt::com_ptr<IShellItem> defaultFolder;
if (FAILED(SHCreateItemFromParsingName(reinterpret_cast<PCWSTR>(uType->lParam), nullptr, IID_IShellItem, defaultFolder.put_void())))
{
return nullptr;
}
DefaultFolder->Release();
}
}
}
}

if (FAILED(fileDialog->SetDefaultFolder(defaultFolder.get())))
{
return nullptr;
}

HRESULT hr = fileDialog->Show(uType->hwndOwner);
if (FAILED(hr))
{
return nullptr;
}

winrt::com_ptr<IShellItem> result;
if (FAILED(fileDialog->GetResult(result.put())))
{
return nullptr;
}

LPITEMIDLIST pidl;
if (FAILED(SHGetIDListFromObject(result.get(), &pidl)))
{
return nullptr;
FileDialog->Release();
}

return pidl;
return IDList;
}

#if defined(_M_IX86)
Expand Down
2 changes: 0 additions & 2 deletions NanaZip.Shared/NanaZip.Shared.ModernExperienceShims.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<RootNamespace>NanaZip.Shared.ModernExperienceShims</RootNamespace>
<MileProjectType>StaticLibrary</MileProjectType>
<MileProjectEnableVCLTLSupport>true</MileProjectEnableVCLTLSupport>
<MileProjectEnableCppWinRTSupport>true</MileProjectEnableCppWinRTSupport>
</PropertyGroup>
<Import Project="..\Mile.Project.Windows\Mile.Project.Platform.x86.props" />
<Import Project="..\Mile.Project.Windows\Mile.Project.Platform.x64.props" />
Expand All @@ -14,7 +13,6 @@
<Import Project="..\Mile.Project.Windows\Mile.Project.Cpp.props" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">NoExtensions</EnableEnhancedInstructionSet>
</ClCompile>
</ItemDefinitionGroup>
Expand Down

0 comments on commit b5a61e6

Please sign in to comment.