|
|
|
@ -12,84 +12,53 @@ HRESULT __hr__; |
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // CHECK
|
|
|
|
#endif // CHECK
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// { WINSTRING
|
|
|
|
|
|
|
|
WinString::WinString(const std::string &string) { |
|
|
|
|
|
|
|
std::wstringstream ss; |
|
|
|
|
|
|
|
ss << s2ws(string); |
|
|
|
|
|
|
|
ss >> str; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string WinString::operator()() { |
|
|
|
|
|
|
|
std::string res; |
|
|
|
|
|
|
|
if (str != nullptr) { |
|
|
|
|
|
|
|
std::wstring ss(str); |
|
|
|
|
|
|
|
res = ws2s(ss); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring WinString::s2ws(const std::string& str) { |
|
|
|
|
|
|
|
return boost::locale::conv::utf_to_utf<wchar_t>(str); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string WinString::ws2s(const std::wstring& wstr) { |
|
|
|
|
|
|
|
return boost::locale::conv::utf_to_utf<char>(wstr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WINSTRING }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// { COMMON_DIALOG
|
|
|
|
// { COMMON_DIALOG
|
|
|
|
CommonDialog::CommonDialog(CLSID type) : dialog(nullptr) { |
|
|
|
CommonDialog::CommonDialog(CLSID type) : dialog(nullptr) { |
|
|
|
check(CoCreateInstance(type, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog)), "Failed to create instance"); |
|
|
|
check(CoCreateInstance(type, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog)), "Failed to create instance"); |
|
|
|
check(dialog->GetOptions(&options), "Failed to get options from instance"); |
|
|
|
check(dialog->GetOptions(&options), "Failed to get options from instance"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void CommonDialog::set_title(std::string &&title) { |
|
|
|
void CommonDialog::set_title(const std::string &title) { |
|
|
|
auto ptr = boost::locale::conv::utf_to_utf<wchar_t>(title).data(); |
|
|
|
check(dialog->SetTitle(), "Failed to set dialog title"); |
|
|
|
check(dialog->SetTitle(ptr), "Failed to set dialog title"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CommonDialog::add_option(unsigned option) { |
|
|
|
void CommonDialog::add_option(unsigned option) { |
|
|
|
check(dialog->SetOptions(options | option), "Failed to set options"); |
|
|
|
check(dialog->SetOptions(options | option), "Failed to set options"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void CommonDialog::set_default_file_extension(std::string &&file_extensions) { |
|
|
|
void CommonDialog::set_file_extensions(const std::vector<std::string> &file_extensions) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CommonDialog::set_default_folder(const std::string &directory_path) { |
|
|
|
void CommonDialog::set_default_folder(const std::string &directory_path) { |
|
|
|
std::cout << directory_path << std::endl; |
|
|
|
|
|
|
|
IShellItem * folder = nullptr; |
|
|
|
IShellItem * folder = nullptr; |
|
|
|
auto dir = WinString::s2ws(directory_path); |
|
|
|
auto ptr = boost::locale::conv::utf_to_utf<wchar_t>(directory_path).data(); |
|
|
|
std::wcout << dir << std::endl; |
|
|
|
check(SHCreateItemFromParsingName(ptr, nullptr, IID_PPV_ARGS(&folder)), "Failed to create string"); |
|
|
|
check(SHCreateItemFromParsingName(dir.data(), nullptr, IID_PPV_ARGS(&folder)), "Failed to create string"); |
|
|
|
|
|
|
|
check(dialog->SetDefaultFolder(folder), "Failed to set default folder"); |
|
|
|
check(dialog->SetDefaultFolder(folder), "Failed to set default folder"); |
|
|
|
folder->Release(); |
|
|
|
folder->Release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string CommonDialog::show() { |
|
|
|
std::string CommonDialog::show() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
check(dialog->Show(nullptr), "Failed to show dialog"); |
|
|
|
check(dialog->Show(nullptr), "Failed to show dialog"); |
|
|
|
IShellItem *result = nullptr; |
|
|
|
IShellItem *result = nullptr; |
|
|
|
check(dialog->GetResult(&result), "Failed to get result from dialog"); |
|
|
|
check(dialog->GetResult(&result), "Failed to get result from dialog"); |
|
|
|
WinString str; |
|
|
|
LPWSTR str = nullptr;
|
|
|
|
check(result->GetDisplayName(SIGDN_FILESYSPATH, &str), "Failed to get display name from dialog"); |
|
|
|
check(result->GetDisplayName(SIGDN_FILESYSPATH, &str), "Failed to get display name from dialog"); |
|
|
|
result->Release(); |
|
|
|
result->Release(); |
|
|
|
return str(); |
|
|
|
auto res = boost::locale::conv::utf_to_utf<char>(str); |
|
|
|
|
|
|
|
CoTaskMemFree(str); |
|
|
|
|
|
|
|
return res; |
|
|
|
} catch (std::exception e) { |
|
|
|
} catch (std::exception e) { |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
OpenDialog::OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog) { |
|
|
|
OpenDialog::OpenDialog(std::string &&title, unsigned option) : CommonDialog(CLSID_FileOpenDialog) { |
|
|
|
set_title(title); |
|
|
|
set_title(std::move(title)); |
|
|
|
add_option(option); |
|
|
|
add_option(option); |
|
|
|
auto dirs = Singleton::directories()->current_path; |
|
|
|
auto dirs = Singleton::directories()->current_path; |
|
|
|
set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string()); |
|
|
|
set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SaveDialog::SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog) { |
|
|
|
SaveDialog::SaveDialog(std::string &&title, unsigned option) : CommonDialog(CLSID_FileSaveDialog) { |
|
|
|
set_title(title); |
|
|
|
set_title(std::move(title)); |
|
|
|
add_option(option); |
|
|
|
add_option(option); |
|
|
|
auto dirs = Singleton::directories()->current_path; |
|
|
|
auto dirs = Singleton::directories()->current_path; |
|
|
|
set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string()); |
|
|
|
set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string()); |
|
|
|
|