refactor: move COM type and guard into independent file

- move COM types and guard into independent file and namespace COMHelper because not only dialog, but also other parts also need to use COM related fucntion.
- remove ParserHelper.cpp because it is empty (ParserHelper is header only namespace).
- Add a function fetching LOCALAPPDATA in WinFctHelper.
This commit is contained in:
2024-06-17 12:46:32 +08:00
parent 8465d80a54
commit e20c03a5f1
9 changed files with 153 additions and 85 deletions

View File

@ -2,10 +2,10 @@
#include "YYCCInternal.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include "COMHelper.hpp"
#include <string>
#include <vector>
#include <initializer_list>
#include <memory>
#include "WinImportPrefix.hpp"
#include <Windows.h>
@ -14,44 +14,6 @@
namespace YYCC::DialogHelper {
#pragma region COM Pointer Management
/**
* @brief C++ standard deleter for every COM interfaces inheriting IUnknown.
*/
class ComPtrDeleter {
public:
ComPtrDeleter() {}
void operator() (IUnknown* com_ptr) {
if (com_ptr != nullptr) {
com_ptr->Release();
}
}
};
using SmartIFileDialog = std::unique_ptr<IFileDialog, ComPtrDeleter>;
using SmartIFileOpenDialog = std::unique_ptr<IFileOpenDialog, ComPtrDeleter>;
using SmartIShellItem = std::unique_ptr<IShellItem, ComPtrDeleter>;
using SmartIShellItemArray = std::unique_ptr<IShellItemArray, ComPtrDeleter>;
using SmartIShellFolder = std::unique_ptr<IShellFolder, ComPtrDeleter>;
/**
* @brief C++ standard deleter for almost raw pointer used in COM which need to be free by CoTaskMemFree()
*/
class CoTaskMemDeleter {
public:
CoTaskMemDeleter() {}
void operator() (void* com_ptr) {
if (com_ptr != nullptr) {
CoTaskMemFree(com_ptr);
}
}
};
using SmartLPWSTR = std::unique_ptr<std::remove_pointer_t<LPWSTR>, CoTaskMemDeleter>;
#pragma endregion
/**
* @brief The class represent the file types region in file dialog
* @details THis class is specific for Windows use, not user oriented.
@ -169,7 +131,7 @@ namespace YYCC::DialogHelper {
UINT m_WinDefaultFileTypeIndex;
bool m_HasTitle, m_HasInitFileName;
std::wstring m_WinTitle, m_WinInitFileName;
SmartIShellItem m_WinInitDirectory;
COMHelper::SmartIShellItem m_WinInitDirectory;
void Clear() {
m_WinOwner = nullptr;