diff --git a/NanaZip.UI.Classic/NanaZip.vcxproj b/NanaZip.UI.Classic/NanaZip.vcxproj index 4a2b8c7c3..8b52d4c3c 100644 --- a/NanaZip.UI.Classic/NanaZip.vcxproj +++ b/NanaZip.UI.Classic/NanaZip.vcxproj @@ -423,9 +423,6 @@ {5220420B-9A5C-44A7-BE69-97F25365BB26} - - {F17D4837-7943-4361-9527-2AF9CACE477D} - {D33E771E-6B30-4EFB-9DEC-A9148D50080D} diff --git a/NanaZip.UI.Classic/NanaZipShellExtension.cpp b/NanaZip.UI.Classic/NanaZipShellExtension.cpp deleted file mode 100644 index bd03ed7c3..000000000 --- a/NanaZip.UI.Classic/NanaZipShellExtension.cpp +++ /dev/null @@ -1,1154 +0,0 @@ -/* - * PROJECT: NanaZip - * FILE: NanaZipShellExtension.cpp - * PURPOSE: Implementation for NanaZip Shell Extension - * - * LICENSE: The MIT License - * - * DEVELOPER: MouriNaruto (KurikoMouri@outlook.jp) - */ - -#include - -#include -#pragma comment(lib, "Shlwapi.lib") - -#include - -#include - -#include "../SevenZip/CPP/Common/Common.h" -#include "../SevenZip/CPP/Windows/DLL.h" -#include "../SevenZip/CPP/Windows/FileDir.h" -#include "../SevenZip/CPP/Windows/FileFind.h" -#include "../SevenZip/CPP/Windows/FileName.h" -#include "../SevenZip/CPP/Windows/ProcessUtils.h" -#include "../SevenZip/CPP/7zip/UI/Common/ArchiveName.h" -#include "../SevenZip/CPP/7zip/UI/Common/CompressCall.h" -#include "../SevenZip/CPP/7zip/UI/Common/ExtractingFilePath.h" -#include "../SevenZip/CPP/7zip/UI/Common/ZipRegistry.h" -#include "../SevenZip/CPP/7zip/UI/FileManager/FormatUtils.h" -#include "../SevenZip/CPP/7zip/UI/FileManager/LangUtils.h" -#include "../SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h" -#include "../SevenZip/CPP/7zip/UI/Explorer/resource.h" - -namespace -{ - static const char* const kExtractExcludeExtensions = - " 3gp" - " aac ans ape asc asm asp aspx avi awk" - " bas bat bmp" - " c cs cls clw cmd cpp csproj css ctl cxx" - " def dep dlg dsp dsw" - " eps" - " f f77 f90 f95 fla flac frm" - " gif" - " h hpp hta htm html hxx" - " ico idl inc ini inl" - " java jpeg jpg js" - " la lnk log" - " mak manifest wmv mov mp3 mp4 mpe mpeg mpg m4a" - " ofr ogg" - " pac pas pdf php php3 php4 php5 phptml pl pm png ps py pyo" - " ra rb rc reg rka rm rtf" - " sed sh shn shtml sln sql srt swa" - " tcl tex tiff tta txt" - " vb vcproj vbs" - " wav webp wma wv" - " xml xsd xsl xslt" - " "; - - static bool FindExt(const char* p, const FString& name) - { - int dotPos = name.ReverseFind_Dot(); - if (dotPos < 0 || dotPos == (int)name.Len() - 1) - return false; - - AString s; - - for (unsigned pos = dotPos + 1;; pos++) - { - wchar_t c = name[pos]; - if (c == 0) - break; - if (c >= 0x80) - return false; - s += (char)MyCharLower_Ascii((char)c); - } - - for (unsigned i = 0; p[i] != 0;) - { - unsigned j; - for (j = i; p[j] != ' '; j++); - if (s.Len() == j - i && memcmp(p + i, (const char*)s, s.Len()) == 0) - return true; - i = j + 1; - } - - return false; - } - - static bool DoNeedExtract(const FString& name) - { - return !FindExt(kExtractExcludeExtensions, name); - } - - static const char* const kArcExts[] = - { - "7z" - , "bz2" - , "gz" - , "lz" - , "liz" - , "lz4" - , "lz5" - , "rar" - , "zip" - , "zst" - }; - - static bool IsItArcExt(const UString& ext) - { - for (unsigned i = 0; i < ARRAY_SIZE(kArcExts); i++) - if (ext.IsEqualTo_Ascii_NoCase(kArcExts[i])) - return true; - return false; - } - - UString GetSubFolderNameForExtract(const UString& arcName) - { - int dotPos = arcName.ReverseFind_Dot(); - if (dotPos < 0) - return Get_Correct_FsFile_Name(arcName) + L'~'; - - const UString ext = arcName.Ptr(dotPos + 1); - UString res = arcName.Left(dotPos); - res.TrimRight(); - dotPos = res.ReverseFind_Dot(); - if (dotPos > 0) - { - const UString ext2 = res.Ptr(dotPos + 1); - if ((ext.IsEqualTo_Ascii_NoCase("001") && IsItArcExt(ext2)) - || (ext.IsEqualTo_Ascii_NoCase("rar") && - (ext2.IsEqualTo_Ascii_NoCase("part001") - || ext2.IsEqualTo_Ascii_NoCase("part01") - || ext2.IsEqualTo_Ascii_NoCase("part1")))) - res.DeleteFrom(dotPos); - res.TrimRight(); - } - return Get_Correct_FsFile_Name(res); - } - - static void ReduceString(UString& s) - { - const unsigned kMaxSize = 64; - if (s.Len() <= kMaxSize) - return; - s.Delete(kMaxSize / 2, s.Len() - kMaxSize); - s.Insert(kMaxSize / 2, L" ... "); - } - - static UString GetQuotedReducedString(const UString& s) - { - UString s2 = s; - ReduceString(s2); - s2.Replace(L"&", L"&&"); - return GetQuotedString(s2); - } - - static void MyFormatNew_ReducedName(UString& s, const UString& name) - { - s = MyFormatNew(s, GetQuotedReducedString(name)); - } - - static UString GetNanaZipPath() - { - return fs2us(NWindows::NDLL::GetModuleDirPrefix()) + L"NanaZip.exe"; - } -} - -namespace NanaZip::ShellExtension -{ - namespace CommandID - { - enum - { - None, - - Open, - Test, - - Extract, - ExtractHere, - ExtractTo, - - Compress, - CompressTo7z, - CompressToZip, - - CompressEmail, - CompressTo7zEmail, - CompressToZipEmail, - - HashCRC32, - HashCRC64, - HashSHA1, - HashSHA256, - HashAll, - - Maximum - }; - } - - using SubCommandList = std::vector>; - using SubCommandListIterator = SubCommandList::const_iterator; - - struct ExplorerCommandBase : public winrt::implements< - ExplorerCommandBase, - IExplorerCommand> - { - private: - - std::wstring m_Title; - - DWORD m_CommandID; - bool m_IsSeparator; - CBoolPair m_ElimDup; - UInt32 m_WriteZone; - - public: - - ExplorerCommandBase( - std::wstring const& Title = std::wstring(), - DWORD CommandID = CommandID::None, - CBoolPair const& ElimDup = CBoolPair(), - UInt32 const& WriteZone = static_cast(-1)) : - m_Title(Title), - m_CommandID(CommandID), - m_ElimDup(ElimDup), - m_WriteZone(WriteZone) - { - this->m_IsSeparator = (this->m_CommandID == CommandID::None); - } - -#pragma region IExplorerCommand - - HRESULT STDMETHODCALLTYPE GetTitle( - _In_opt_ IShellItemArray* psiItemArray, - _Outptr_ LPWSTR* ppszName) - { - UNREFERENCED_PARAMETER(psiItemArray); - - if (this->m_IsSeparator) - { - *ppszName = nullptr; - return S_FALSE; - } - - return ::SHStrDupW(this->m_Title.c_str(), ppszName); - } - - HRESULT STDMETHODCALLTYPE GetIcon( - _In_opt_ IShellItemArray* psiItemArray, - _Outptr_ LPWSTR* ppszIcon) - { - UNREFERENCED_PARAMETER(psiItemArray); - - *ppszIcon = nullptr; - return E_NOTIMPL; - } - - HRESULT STDMETHODCALLTYPE GetToolTip( - _In_opt_ IShellItemArray* psiItemArray, - _Outptr_ LPWSTR* ppszInfotip) - { - UNREFERENCED_PARAMETER(psiItemArray); - *ppszInfotip = nullptr; - return E_NOTIMPL; - } - - HRESULT STDMETHODCALLTYPE GetCanonicalName( - _Out_ GUID* pguidCommandName) - { - *pguidCommandName = GUID_NULL; - return E_NOTIMPL; - } - - HRESULT STDMETHODCALLTYPE GetState( - _In_opt_ IShellItemArray* psiItemArray, - _In_ BOOL fOkToBeSlow, - _Out_ EXPCMDSTATE* pCmdState) - { - UNREFERENCED_PARAMETER(psiItemArray); - UNREFERENCED_PARAMETER(fOkToBeSlow); - *pCmdState = ECS_ENABLED; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE Invoke( - _In_opt_ IShellItemArray* psiItemArray, - _In_opt_ IBindCtx* pbc) - { - UNREFERENCED_PARAMETER(pbc); - - if (this->m_IsSeparator) - { - return E_NOTIMPL; - } - - std::vector FilePaths; - if (psiItemArray) - { - DWORD Count = 0; - if (SUCCEEDED(psiItemArray->GetCount(&Count))) - { - for (DWORD i = 0; i < Count; ++i) - { - winrt::com_ptr Item; - if (SUCCEEDED(psiItemArray->GetItemAt( - i, - Item.put()))) - { - LPWSTR DisplayName = nullptr; - if (SUCCEEDED(Item->GetDisplayName( - SIGDN_FILESYSPATH, - &DisplayName))) - { - FilePaths.push_back(std::wstring(DisplayName)); - ::CoTaskMemFree(DisplayName); - } - } - } - } - } - - bool NeedExtract = false; - if (FilePaths.size() > 0) - { - for (std::wstring const FilePath : FilePaths) - { - DWORD FileAttributes = ::GetFileAttributesW( - FilePath.c_str()); - if (FileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - continue; - } - - if (DoNeedExtract(::PathFindFileNameW(FilePath.c_str()))) - { - NeedExtract = true; - break; - } - } - } - - std::wstring SpecFolder = L"*"; - if (NeedExtract) - { - if (FilePaths.size() == 1) - { - SpecFolder = GetSubFolderNameForExtract( - ::PathFindFileNameW(FilePaths[0].c_str())); - } - SpecFolder += L'\\'; - } - - UStringVector FileNames; - for (std::wstring const FilePath : FilePaths) - { - FileNames.Add(FilePath.c_str()); - } - - FString FolderPrefix; - - std::wstring ArchiveName; - if (FilePaths.size() > 0) - { - NWindows::NFile::NFind::CFileInfo FileInfo0; - - const UString& FileName = FileNames.Front(); - - if (NWindows::NFile::NName::IsDevicePath(us2fs(FileName))) - { - // CFileInfo::Find can be slow for device files. So we - // don't call it. - // we need only name here. - // change it 4 - must be constant - FileInfo0.Name = us2fs(FileName.Ptr( - NWindows::NFile::NName::kDevicePathPrefixSize)); - FolderPrefix = "C:\\"; - } - else - { - if (!FileInfo0.Find(us2fs(FileName))) - { - return ::HRESULT_FROM_WIN32(::GetLastError()); - } - NWindows::NFile::NDir::GetOnlyDirPrefix( - us2fs(FileName), - FolderPrefix); - } - - const UString Name = CreateArchiveName( - FileNames, - FileNames.Size() == 1 ? &FileInfo0 : nullptr); - ArchiveName = std::wstring(Name.Ptr(), Name.Len()); - - } - - std::wstring BaseFolder = std::wstring( - FolderPrefix.Ptr(), - FolderPrefix.Len()); - - std::wstring ArchiveName7z = ArchiveName + L".7z"; - std::wstring ArchiveNameZip = ArchiveName + L".zip"; - - switch (this->m_CommandID) - { - case CommandID::Open: - { - if (FilePaths.size() != 1) - { - break; - } - - DWORD FileAttributes = ::GetFileAttributesW( - FilePaths[0].c_str()); - if (FileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - break; - } - - if (!DoNeedExtract(FilePaths[0].c_str())) - { - break; - } - - UString params; - params = GetQuotedString(FilePaths[0].c_str()); - NWindows::MyCreateProcess(::GetNanaZipPath(), params); - - break; - } - case CommandID::Test: - { - if (!NeedExtract) - { - break; - } - - TestArchives(FileNames); - break; - } - case CommandID::Extract: - case CommandID::ExtractHere: - case CommandID::ExtractTo: - { - if (!NeedExtract) - { - break; - } - - std::wstring Folder = BaseFolder; - if (this->m_CommandID != CommandID::ExtractHere) - { - Folder += SpecFolder; - } - - ExtractArchives( - FileNames, - Folder.c_str(), - (this->m_CommandID == CommandID::Extract), - ((this->m_CommandID == CommandID::ExtractTo) - && this->m_ElimDup.Val), - this->m_WriteZone); - - break; - } - case CommandID::Compress: - case CommandID::CompressTo7z: - case CommandID::CompressToZip: - case CommandID::CompressEmail: - case CommandID::CompressTo7zEmail: - case CommandID::CompressToZipEmail: - { - bool Email =( - (this->m_CommandID == CommandID::CompressEmail) || - (this->m_CommandID == CommandID::CompressTo7zEmail) || - (this->m_CommandID == CommandID::CompressToZipEmail)); - bool ShowDialog = ( - (this->m_CommandID == CommandID::Compress) || - (this->m_CommandID == CommandID::CompressEmail)); - bool AddExtension = ( - (this->m_CommandID == CommandID::Compress) || - (this->m_CommandID == CommandID::CompressEmail)); - bool Is7z = ( - (this->m_CommandID == CommandID::CompressTo7z) || - (this->m_CommandID == CommandID::CompressTo7zEmail)); - - std::wstring Name = ( - AddExtension - ? ArchiveName - : (Is7z ? ArchiveName7z : ArchiveNameZip)); - - CompressFiles( - BaseFolder.c_str(), - Name.c_str(), - Is7z ? L"7z" : L"zip", - AddExtension, - FileNames, - Email, - ShowDialog, - false); - - break; - } - case CommandID::HashCRC32: - case CommandID::HashCRC64: - case CommandID::HashSHA1: - case CommandID::HashSHA256: - case CommandID::HashAll: - { - std::wstring MethodName; - switch (this->m_CommandID) - { - case CommandID::HashCRC32: - MethodName = L"CRC32"; - break; - case CommandID::HashCRC64: - MethodName = L"CRC64"; - break; - case CommandID::HashSHA1: - MethodName = L"SHA1"; - break; - case CommandID::HashSHA256: - MethodName = L"SHA256"; - break; - case CommandID::HashAll: - MethodName = L"*"; - break; - default: - break; - } - - CalcChecksum(FileNames, MethodName.c_str(), L"", L""); - break; - } - default: - break; - } - - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetFlags( - _Out_ EXPCMDFLAGS* pFlags) - { - *pFlags = - this->m_IsSeparator - ? ECF_ISSEPARATOR - : ECF_DEFAULT; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE EnumSubCommands( - _Outptr_ IEnumExplorerCommand** ppEnum) - { - *ppEnum = nullptr; - return E_NOTIMPL; - } - -#pragma endregion - }; - - - struct ExplorerCommandRoot : public winrt::implements< - ExplorerCommandRoot, - IExplorerCommand, - IEnumExplorerCommand> - { - private: - - DWORD m_ContextMenuFlags; - CBoolPair m_ContextMenuElimDup; - - bool m_Initialized = false; - SubCommandList m_SubCommands; - SubCommandListIterator m_CurrentSubCommand; - - void Initialize( - _In_opt_ IShellItemArray* psiItemArray) - { - if (m_Initialized) - { - return; - } - - m_Initialized = true; - - std::vector FilePaths; - if (psiItemArray) - { - DWORD Count = 0; - if (SUCCEEDED(psiItemArray->GetCount(&Count))) - { - for (DWORD i = 0; i < Count; ++i) - { - winrt::com_ptr Item; - if (SUCCEEDED(psiItemArray->GetItemAt( - i, - Item.put()))) - { - LPWSTR DisplayName = nullptr; - if (SUCCEEDED(Item->GetDisplayName( - SIGDN_FILESYSPATH, - &DisplayName))) - { - FilePaths.push_back(std::wstring(DisplayName)); - ::CoTaskMemFree(DisplayName); - } - } - } - } - } - - if (FilePaths.empty()) - { - return; - } - - UStringVector FileNames; - for (std::wstring const FilePath : FilePaths) - { - FileNames.Add(FilePath.c_str()); - } - - bool NeedExtract = false; - for (std::wstring const FilePath : FilePaths) - { - DWORD FileAttributes = ::GetFileAttributesW( - FilePath.c_str()); - if (FileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - continue; - } - - if (DoNeedExtract(::PathFindFileNameW(FilePath.c_str()))) - { - NeedExtract = true; - break; - } - } - - std::wstring SpecFolder = L"*"; - if (NeedExtract) - { - if (FilePaths.size() == 1) - { - SpecFolder = GetSubFolderNameForExtract( - ::PathFindFileNameW(FilePaths[0].c_str())); - } - SpecFolder += L'\\'; - } - - FString FolderPrefix; - - std::wstring ArchiveName; - { - NWindows::NFile::NFind::CFileInfo FileInfo0; - - const UString& FileName = FileNames.Front(); - - if (NWindows::NFile::NName::IsDevicePath(us2fs(FileName))) - { - // CFileInfo::Find can be slow for device files. So we - // don't call it. - // we need only name here. - // change it 4 - must be constant - FileInfo0.Name = us2fs(FileName.Ptr( - NWindows::NFile::NName::kDevicePathPrefixSize)); - FolderPrefix = "C:\\"; - } - else - { - if (!FileInfo0.Find(us2fs(FileName))) - { - return; - } - NWindows::NFile::NDir::GetOnlyDirPrefix( - us2fs(FileName), - FolderPrefix); - } - - const UString Name = CreateArchiveName( - FileNames, - FileNames.Size() == 1 ? &FileInfo0 : nullptr); - ArchiveName = std::wstring(Name.Ptr(), Name.Len()); - - } - - std::wstring BaseFolder = std::wstring( - FolderPrefix.Ptr(), - FolderPrefix.Len()); - - std::wstring ArchiveName7z = ArchiveName + L".7z"; - std::wstring ArchiveNameZip = ArchiveName + L".zip"; - - using NanaZip::ShellExtension::ExplorerCommandBase; - - CContextMenuInfo ContextMenuInfo; - ContextMenuInfo.Load(); - DWORD ContextMenuFlags = ContextMenuInfo.Flags; - CBoolPair ContextMenuElimDup = ContextMenuInfo.ElimDup; - UInt32 ContextMenuWriteZone = ContextMenuInfo.WriteZone; - - LoadLangOneTime(); - - if (ContextMenuFlags & NContextMenuFlags::kOpen) - { - DWORD FileAttributes = ::GetFileAttributesW( - FilePaths[0].c_str()); - if ((FilePaths.size() == 1) && - !(FileAttributes & FILE_ATTRIBUTE_DIRECTORY) && - DoNeedExtract(FilePaths[0].c_str())) - { - UString TranslatedString; - LangString(IDS_CONTEXT_OPEN, TranslatedString); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::Open)); - } - } - - if (NeedExtract) - { - if (ContextMenuFlags & NContextMenuFlags::kTest) - { - UString TranslatedString; - LangString(IDS_CONTEXT_TEST, TranslatedString); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::Test)); - } - - if (ContextMenuFlags & NContextMenuFlags::kExtract) - { - UString TranslatedString; - LangString(IDS_CONTEXT_EXTRACT, TranslatedString); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::Extract, - ContextMenuElimDup, - ContextMenuWriteZone)); - } - - if (ContextMenuFlags & NContextMenuFlags::kExtractHere) - { - UString TranslatedString; - LangString(IDS_CONTEXT_EXTRACT_HERE, TranslatedString); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::ExtractHere, - ContextMenuElimDup, - ContextMenuWriteZone)); - } - - if (ContextMenuFlags & NContextMenuFlags::kExtractTo) - { - UString TranslatedString; - LangString(IDS_CONTEXT_EXTRACT_TO, TranslatedString); - MyFormatNew_ReducedName(TranslatedString, SpecFolder.c_str()); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::ExtractTo, - ContextMenuElimDup, - ContextMenuWriteZone)); - } - } - - if (ContextMenuFlags & NContextMenuFlags::kCompress) - { - UString TranslatedString; - LangString(IDS_CONTEXT_COMPRESS, TranslatedString); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::Compress)); - } - - if (ContextMenuFlags & NContextMenuFlags::kCompressTo7z) - { - UString TranslatedString; - LangString(IDS_CONTEXT_COMPRESS_TO, TranslatedString); - MyFormatNew_ReducedName(TranslatedString, ArchiveName7z.c_str()); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::CompressTo7z)); - } - - if (ContextMenuFlags & NContextMenuFlags::kCompressToZip) - { - UString TranslatedString; - LangString(IDS_CONTEXT_COMPRESS_TO, TranslatedString); - MyFormatNew_ReducedName(TranslatedString, ArchiveNameZip.c_str()); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::CompressToZip)); - } - - if (ContextMenuFlags & NContextMenuFlags::kCompressEmail) - { - UString TranslatedString; - LangString(IDS_CONTEXT_COMPRESS_EMAIL, TranslatedString); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::CompressEmail)); - } - - if (ContextMenuFlags & NContextMenuFlags::kCompressTo7zEmail) - { - UString TranslatedString; - LangString(IDS_CONTEXT_COMPRESS_TO_EMAIL, TranslatedString); - MyFormatNew_ReducedName(TranslatedString, ArchiveName7z.c_str()); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::CompressTo7zEmail)); - } - - if (ContextMenuFlags & NContextMenuFlags::kCompressToZipEmail) - { - UString TranslatedString; - LangString(IDS_CONTEXT_COMPRESS_TO_EMAIL, TranslatedString); - MyFormatNew_ReducedName(TranslatedString, ArchiveNameZip.c_str()); - this->m_SubCommands.push_back( - winrt::make( - std::wstring( - TranslatedString.Ptr(), - TranslatedString.Len()), - CommandID::CompressToZipEmail)); - } - - if (ContextMenuFlags & NContextMenuFlags::kCRC) - { - if (!this->m_SubCommands.empty()) - { - this->m_SubCommands.push_back( - winrt::make()); - } - - this->m_SubCommands.push_back( - winrt::make( - L"CRC-32", - CommandID::HashCRC32)); - - this->m_SubCommands.push_back( - winrt::make( - L"CRC-64", - CommandID::HashCRC64)); - - this->m_SubCommands.push_back( - winrt::make( - L"SHA-1", - CommandID::HashSHA1)); - - this->m_SubCommands.push_back( - winrt::make( - L"SHA-256", - CommandID::HashSHA256)); - - this->m_SubCommands.push_back( - winrt::make( - L"*", - CommandID::HashAll)); - } - } - - public: - - ExplorerCommandRoot() - { - CContextMenuInfo ContextMenuInfo; - ContextMenuInfo.Load(); - this->m_ContextMenuFlags = ContextMenuInfo.Flags; - this->m_ContextMenuElimDup = ContextMenuInfo.ElimDup; - } - -#pragma region IExplorerCommand - - HRESULT STDMETHODCALLTYPE GetTitle( - _In_opt_ IShellItemArray* psiItemArray, - _Outptr_ LPWSTR* ppszName) - { - this->Initialize(psiItemArray); - - if (this->m_SubCommands.empty()) - { - *ppszName = nullptr; - return E_NOTIMPL; - } - - return ::SHStrDupW(L"NanaZip Preview", ppszName); - } - - HRESULT STDMETHODCALLTYPE GetIcon( - _In_opt_ IShellItemArray* psiItemArray, - _Outptr_ LPWSTR* ppszIcon) - { - UNREFERENCED_PARAMETER(psiItemArray); - UString Path = ::GetNanaZipPath(); - std::wstring Icon = std::wstring(Path.Ptr(), Path.Len()); - Icon += L",-1"; - return ::SHStrDupW(Icon.c_str(), ppszIcon); - } - - HRESULT STDMETHODCALLTYPE GetToolTip( - _In_opt_ IShellItemArray* psiItemArray, - _Outptr_ LPWSTR* ppszInfotip) - { - UNREFERENCED_PARAMETER(psiItemArray); - *ppszInfotip = nullptr; - return E_NOTIMPL; - } - - HRESULT STDMETHODCALLTYPE GetCanonicalName( - _Out_ GUID* pguidCommandName) - { - *pguidCommandName = GUID_NULL; - return E_NOTIMPL; - } - - HRESULT STDMETHODCALLTYPE GetState( - _In_opt_ IShellItemArray* psiItemArray, - _In_ BOOL fOkToBeSlow, - _Out_ EXPCMDSTATE* pCmdState) - { - UNREFERENCED_PARAMETER(psiItemArray); - UNREFERENCED_PARAMETER(fOkToBeSlow); - *pCmdState = ECS_ENABLED; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE Invoke( - _In_opt_ IShellItemArray* psiItemArray, - _In_opt_ IBindCtx* pbc) - { - UNREFERENCED_PARAMETER(psiItemArray); - UNREFERENCED_PARAMETER(pbc); - return E_NOTIMPL; - } - - HRESULT STDMETHODCALLTYPE GetFlags( - _Out_ EXPCMDFLAGS* pFlags) - { - *pFlags = ECF_HASSUBCOMMANDS; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE EnumSubCommands( - _Outptr_ IEnumExplorerCommand** ppEnum) - { - if (this->m_SubCommands.empty()) - { - *ppEnum = nullptr; - return E_NOTIMPL; - } - else - { - this->m_CurrentSubCommand = this->m_SubCommands.cbegin(); - this->AddRef(); - return this->QueryInterface(IID_PPV_ARGS(ppEnum)); - } - } - -#pragma endregion - -#pragma region IEnumExplorerCommand - - HRESULT STDMETHODCALLTYPE Next( - _In_ ULONG celt, - _Out_ IExplorerCommand** pUICommand, - _Out_opt_ ULONG* pceltFetched) - { - ULONG Fetched = 0; - - for ( - ULONG i = 0; - (i < celt) && - (this->m_CurrentSubCommand != this->m_SubCommands.cend()); - ++i) - { - this->m_CurrentSubCommand->copy_to(&pUICommand[i]); - ++Fetched; - ++this->m_CurrentSubCommand; - } - - if (pceltFetched) - { - *pceltFetched = Fetched; - } - - return (Fetched == celt) ? S_OK : S_FALSE; - } - - HRESULT STDMETHODCALLTYPE Skip( - _In_ ULONG celt) - { - UNREFERENCED_PARAMETER(celt); - return E_NOTIMPL; - } - - HRESULT STDMETHODCALLTYPE Reset() - { - this->m_CurrentSubCommand = this->m_SubCommands.cbegin(); - return S_OK; - } - - HRESULT STDMETHODCALLTYPE Clone( - _Out_ IEnumExplorerCommand** ppenum) - { - *ppenum = nullptr; - return E_NOTIMPL; - } - -#pragma endregion - }; - - struct DECLSPEC_UUID("469D94E9-6AF4-4395-B396-99B1308F8CE5") - ClassFactory : public winrt::implements< - ClassFactory, IClassFactory> - { - public: - - HRESULT STDMETHODCALLTYPE CreateInstance( - _In_opt_ IUnknown* pUnkOuter, - _In_ REFIID riid, - _COM_Outptr_ void** ppvObject) noexcept override - { - UNREFERENCED_PARAMETER(pUnkOuter); - - try - { - return winrt::make()->QueryInterface( - riid, ppvObject); - } - catch (...) - { - return winrt::to_hresult(); - } - } - - HRESULT STDMETHODCALLTYPE LockServer( - _In_ BOOL fLock) noexcept override - { - if (fLock) - { - ++winrt::get_module_lock(); - } - else - { - --winrt::get_module_lock(); - } - - return S_OK; - } - }; -} - -EXTERN_C HRESULT STDAPICALLTYPE DllCanUnloadNow() -{ - if (winrt::get_module_lock()) - { - return S_FALSE; - } - - winrt::clear_factory_cache(); - return S_OK; -} - -EXTERN_C HRESULT STDAPICALLTYPE DllGetClassObject( - _In_ REFCLSID rclsid, - _In_ REFIID riid, - _Outptr_ LPVOID* ppv) -{ - if (!ppv) - { - return E_POINTER; - } - - if (riid != IID_IClassFactory && riid != IID_IUnknown) - { - return E_NOINTERFACE; - } - - if (rclsid != __uuidof(NanaZip::ShellExtension::ClassFactory)) - { - return E_INVALIDARG; - } - - try - { - return winrt::make( - )->QueryInterface(riid, ppv); - } - catch (...) - { - return winrt::to_hresult(); - } -} - -long g_DllRefCount = 0; -HWND g_HWND = nullptr; -HINSTANCE g_hInstance = nullptr; - -BOOL WINAPI DllMain( - _In_ HINSTANCE hinstDLL, - _In_ DWORD fdwReason, - _In_ LPVOID lpvReserved) -{ - UNREFERENCED_PARAMETER(lpvReserved); - - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - { - g_hInstance = hinstDLL; - break; - } - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} diff --git a/NanaZip.UI.Classic/NanaZipShellExtension.def b/NanaZip.UI.Classic/NanaZipShellExtension.def deleted file mode 100644 index 733b8692c..000000000 --- a/NanaZip.UI.Classic/NanaZipShellExtension.def +++ /dev/null @@ -1,6 +0,0 @@ -LIBRARY - -EXPORTS - -DllCanUnloadNow PRIVATE -DllGetClassObject PRIVATE diff --git a/NanaZip.UI.Classic/NanaZipShellExtension.manifest b/NanaZip.UI.Classic/NanaZipShellExtension.manifest deleted file mode 100644 index f0dc4ff8c..000000000 --- a/NanaZip.UI.Classic/NanaZipShellExtension.manifest +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - diff --git a/NanaZip.UI.Classic/NanaZipShellExtension.vcxproj b/NanaZip.UI.Classic/NanaZipShellExtension.vcxproj deleted file mode 100644 index c08bb9936..000000000 --- a/NanaZip.UI.Classic/NanaZipShellExtension.vcxproj +++ /dev/null @@ -1,144 +0,0 @@ - - - - {F17D4837-7943-4361-9527-2AF9CACE477D} - NanaZipShellExtension - DynamicLibrary - NanaZipShellExtension.manifest - true - true - true - M2-Team - NanaZip Shell Extension - NanaZipShellExtension - © M2-Team and Contributors. All rights reserved. - NanaZipShellExtension.dll - NanaZip - 3.0.$([System.DateTime]::Today.Subtract($([System.DateTime]::Parse('2021-08-31'))).TotalDays).0 - Preview 1 - - - - - - - - - - %(AdditionalOptions) /Wv:18 - LANG;WIN_LONG_PATH;WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions) - - - true - NanaZipShellExtension.def - runtimeobject.lib;comctl32.lib;htmlhelp.lib;comdlg32.lib;Mpr.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NanaZip.UI.Classic/NanaZipShellExtension.vcxproj.filters b/NanaZip.UI.Classic/NanaZipShellExtension.vcxproj.filters deleted file mode 100644 index 9934ba7be..000000000 --- a/NanaZip.UI.Classic/NanaZipShellExtension.vcxproj.filters +++ /dev/null @@ -1,320 +0,0 @@ - - - - - {a90f3018-4f2a-4067-be95-c9a7db13a553} - - - {6984cc0f-f55a-4eb2-99a6-62d34d359a37} - - - {b2fbff5c-1f65-4c12-b0c9-cf281a54184f} - - - {dede274a-64c5-4794-98da-d0cfb0a1c506} - - - {2aed1d94-8cb0-472f-8367-5f6212490c1d} - - - {52a80806-d0cb-437b-abaf-7701277b68b0} - - - {c492cd90-1a18-4ee2-a365-02784205fd23} - - - {7cb3af9f-7db7-40b2-a882-d6528d9e46dc} - - - {b2063768-b1ac-4fc2-b288-349b160b3bad} - - - - - SevenZip\Spec - - - SevenZip\UI Common - - - SevenZip\UI Common - - - SevenZip\UI Common - - - SevenZip\UI Common - - - SevenZip\Engine - - - SevenZip\FileManager - - - SevenZip\FileManager - - - SevenZip\FileManager - - - SevenZip\FileManager - - - SevenZip\C - - - SevenZip\C - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Windows\Control - - - SevenZip\Windows\Control - - - SevenZip\Windows\Control - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\FileManager - - - SevenZip\FileManager - - - - - SevenZip\Spec - - - SevenZip\Spec - - - SevenZip\UI Common - - - SevenZip\UI Common - - - SevenZip\UI Common - - - SevenZip\UI Common - - - SevenZip\Engine - - - SevenZip\FileManager - - - SevenZip\FileManager - - - SevenZip\FileManager - - - SevenZip\FileManager - - - SevenZip\FileManager - - - SevenZip\C - - - SevenZip\C - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Common - - - SevenZip\Windows\Control - - - SevenZip\Windows\Control - - - SevenZip\Windows\Control - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Windows - - - SevenZip\Engine - - - SevenZip\FileManager - - - SevenZip\Engine - - - SevenZip\FileManager - - - - - SevenZip\Spec - - - - - - - - - - - - \ No newline at end of file diff --git a/NanaZip.sln b/NanaZip.sln index 319b66d8e..8397a16c6 100644 --- a/NanaZip.sln +++ b/NanaZip.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NanaZipShellExtension", "NanaZip.UI.Classic\NanaZipShellExtension.vcxproj", "{F17D4837-7943-4361-9527-2AF9CACE477D}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NanaZip.Core.Sfx.Windows", "NanaZip.Core\NanaZip.Core.Sfx.Windows.vcxproj", "{C11F288B-9E3C-4DA9-8206-852BB91C7E4C}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NanaZip.Core.Sfx.Console", "NanaZip.Core\NanaZip.Core.Sfx.Console.vcxproj", "{96C0A1A0-D964-4725-AFDC-73EBF7FC1416}" @@ -61,18 +59,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F17D4837-7943-4361-9527-2AF9CACE477D}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Debug|ARM64.Build.0 = Debug|ARM64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Debug|x64.ActiveCfg = Debug|x64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Debug|x64.Build.0 = Debug|x64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Debug|x86.ActiveCfg = Debug|Win32 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Debug|x86.Build.0 = Debug|Win32 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Release|ARM64.ActiveCfg = Release|ARM64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Release|ARM64.Build.0 = Release|ARM64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Release|x64.ActiveCfg = Release|x64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Release|x64.Build.0 = Release|x64 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Release|x86.ActiveCfg = Release|Win32 - {F17D4837-7943-4361-9527-2AF9CACE477D}.Release|x86.Build.0 = Release|Win32 {C11F288B-9E3C-4DA9-8206-852BB91C7E4C}.Debug|ARM64.ActiveCfg = Debug|Win32 {C11F288B-9E3C-4DA9-8206-852BB91C7E4C}.Debug|x64.ActiveCfg = Debug|Win32 {C11F288B-9E3C-4DA9-8206-852BB91C7E4C}.Debug|x86.ActiveCfg = Debug|Win32 @@ -268,7 +254,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {F17D4837-7943-4361-9527-2AF9CACE477D} = {6666CFC3-1986-469A-9266-0FD8C2674DF6} {C11F288B-9E3C-4DA9-8206-852BB91C7E4C} = {94A1E11C-B722-4BAE-9B12-1495F5EF3CC9} {96C0A1A0-D964-4725-AFDC-73EBF7FC1416} = {94A1E11C-B722-4BAE-9B12-1495F5EF3CC9} {43308629-5328-46BF-8E1C-A258A937B981} = {94A1E11C-B722-4BAE-9B12-1495F5EF3CC9} diff --git a/ReadMe.md b/ReadMe.md index ffbc5ec4f..ab5b0638d 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -77,14 +77,14 @@ NanaZip Classic. Here are the differences between them. - NanaZip - Only 64-Bit support. - Only MSIX packaged version. - - Support new context menu introduced by Windows 11. + - Support the context menu in Windows 10/11 File Explorer. - Only support Windows 10 Version 2004 (Build 19041) or later. - Have XAML-based GUI and VT-based CLI. - NanaZip Classic - Have 32-Bit support. - - Only unpackaged version (installer or portable). - - Only support legacy context menu. + - Only unpackaged portable version. + - Don't have the context menu support. - Support Windows Vista RTM (Build 6000.16386) or later. - Keep Win32 GUI and Win32 CLI.