From 25b37f912cde628377b55e262fcaa8458448da97 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Nov 2018 13:45:49 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jin/main.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/jin') diff --git a/src/jin/main.cpp b/src/jin/main.cpp index 31e837f..f76bda7 100644 --- a/src/jin/main.cpp +++ b/src/jin/main.cpp @@ -47,38 +47,36 @@ std::string wstrtostr(const std::wstring &wstr) } #endif -std::string BrowseFolder() +bool BrowseFolder(string& cwd) { #ifdef _WIN32 - string path = EXECUTABLE_DIR; IFileDialog* pfd = NULL; DWORD dwFlags; IShellItem* pItem = NULL; HRESULT hr = CoInitialize(NULL); - if (FAILED(hr)) goto End; + if (FAILED(hr)) return false; hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast(&pfd)); - if (FAILED(hr)) goto End; + if (FAILED(hr)) return false; pfd->SetTitle(DIALOG_TITLE); hr = pfd->GetOptions(&dwFlags); - if (FAILED(hr)) goto End; + if (FAILED(hr)) return false; hr = pfd->SetOptions(dwFlags | FOS_PICKFOLDERS); - if (FAILED(hr)) goto End; + if (FAILED(hr)) return false; hr = pfd->Show(NULL); if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) - goto End; + return false; hr = pfd->GetResult(&pItem); - if (FAILED(hr)) goto End; + if (FAILED(hr)) return false; LPWSTR filePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath); - if (FAILED(hr)) goto End; - path = wstrtostr(filePath); + if (FAILED(hr)) return false; + cwd = wstrtostr(filePath); CoTaskMemFree(filePath); pItem->Release(); pfd->Release(); CoUninitialize(); -End: - return path; + return true; #endif } @@ -90,9 +88,12 @@ int main(int argc, char* args[]) cwd = args[1]; #endif else - cwd = BrowseFolder(); + { + if (!BrowseFolder(cwd)) + return 0; + } if (!cwd.empty()) load(cwd.c_str()); return 0; -}// todo:吧main.lua的读取提出来 \ No newline at end of file +} \ No newline at end of file -- cgit v1.1-26-g67d0