From 1d1210d7932b287d66e27157701b92df764528cb Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 5 Nov 2018 07:33:41 +0800 Subject: =?UTF-8?q?+=E7=8A=B6=E6=80=81=E6=9C=BA=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jin/main.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/jin/main.cpp') diff --git a/src/jin/main.cpp b/src/jin/main.cpp index 2f0f9b3..da5b5e7 100644 --- a/src/jin/main.cpp +++ b/src/jin/main.cpp @@ -4,13 +4,13 @@ #ifdef _WIN32 #include - #include #include #include #include #endif #define EXECUTABLE_DIR "./" +#define DIALOG_TITLE L"Open existing game" using namespace std; using namespace JinEngine::Filesystem; @@ -58,16 +58,17 @@ std::string wstrtostr(const std::wstring &wstr) std::string BrowseFolder() { - string path = EXECUTABLE_DIR; #ifdef _WIN32 - IFileDialog *pfd = NULL; + string path = EXECUTABLE_DIR; + IFileDialog* pfd = NULL; DWORD dwFlags; - IShellItem *pShellItem = NULL; + IShellItem* pItem = NULL; HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) goto End; hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast(&pfd)); if (FAILED(hr)) goto End; + pfd->SetTitle(DIALOG_TITLE); hr = pfd->GetOptions(&dwFlags); if (FAILED(hr)) goto End; hr = pfd->SetOptions(dwFlags | FOS_PICKFOLDERS); @@ -75,19 +76,19 @@ std::string BrowseFolder() hr = pfd->Show(NULL); if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) goto End; - hr = pfd->GetResult(&pShellItem); + hr = pfd->GetResult(&pItem); if (FAILED(hr)) goto End; LPWSTR filePath; - hr = pShellItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath); - if (FAILED(hr)) - { - goto End; - } + hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath); + if (FAILED(hr)) goto End; path = wstrtostr(filePath); CoTaskMemFree(filePath); -#endif + pItem->Release(); + pfd->Release(); + CoUninitialize(); End: return path; +#endif } int main(int argc, char* args[]) @@ -95,9 +96,7 @@ int main(int argc, char* args[]) string cwd = EXECUTABLE_DIR; #ifdef _WIN32 if (argc > 1) - { cwd = args[1]; - } #endif else cwd = BrowseFolder(); -- cgit v1.1-26-g67d0