aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-03 22:22:20 +0800
committerchai <chaifix@163.com>2018-11-03 22:22:20 +0800
commit91641bccdf744e0dc29f015fbffc64be46d2ad2c (patch)
tree5d1d5c8b8748c3de1bc24912ae4383bc5066047c /src
parent281f8feabffd69928a0a0f08aa31f70b36f5e6bd (diff)
*使用IFileDialog
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/buildvm/buildvm.exebin62976 -> 62976 bytes
-rw-r--r--src/3rdparty/minilua/minilua.exebin112640 -> 112640 bytes
-rw-r--r--src/jin/main.cpp81
3 files changed, 51 insertions, 30 deletions
diff --git a/src/3rdparty/buildvm/buildvm.exe b/src/3rdparty/buildvm/buildvm.exe
index 0d45b9a..17459f4 100644
--- a/src/3rdparty/buildvm/buildvm.exe
+++ b/src/3rdparty/buildvm/buildvm.exe
Binary files differ
diff --git a/src/3rdparty/minilua/minilua.exe b/src/3rdparty/minilua/minilua.exe
index f26a026..e6cd530 100644
--- a/src/3rdparty/minilua/minilua.exe
+++ b/src/3rdparty/minilua/minilua.exe
Binary files differ
diff --git a/src/jin/main.cpp b/src/jin/main.cpp
index e129b78..2f0f9b3 100644
--- a/src/jin/main.cpp
+++ b/src/jin/main.cpp
@@ -1,15 +1,13 @@
-#ifdef _WIN32
-#include <SDL2/SDL_Main.h>
-#include <direct.h>
-#endif
-
#include "lua/luax.h"
#include "lua/jin.h"
#include "libjin/jin.h"
#ifdef _WIN32
-#include <shlobj.h>
-#include <Windows.h>
+ #include <Windows.h>
+ #include <SDL2/SDL_Main.h>
+ #include <direct.h>
+ #include <shlobj.h>
+ #include <wchar.h>
#endif
#define EXECUTABLE_DIR "./"
@@ -44,42 +42,65 @@ static void load(const char* cwd)
}
-std::string BrowseFolder()
+#ifdef _WIN32
+// WChar to string.
+std::string wstrtostr(const std::wstring &wstr)
{
- TCHAR path[MAX_PATH];
-
- BROWSEINFO bi = { 0 };
- bi.lpszTitle = ("Browse game folder...");
- bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
- bi.lpfn = nullptr;
- LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
+ std::string strTo;
+ char *szTo = new char[wstr.length() + 1];
+ szTo[wstr.size()] = '\0';
+ WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, szTo, (int)wstr.length(), NULL, NULL);
+ strTo = szTo;
+ delete[] szTo;
+ return strTo;
+}
+#endif
- if (pidl != 0)
+std::string BrowseFolder()
+{
+ string path = EXECUTABLE_DIR;
+#ifdef _WIN32
+ IFileDialog *pfd = NULL;
+ DWORD dwFlags;
+ IShellItem *pShellItem = NULL;
+ HRESULT hr = CoInitialize(NULL);
+ if (FAILED(hr)) goto End;
+ hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
+ IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd));
+ if (FAILED(hr)) goto End;
+ hr = pfd->GetOptions(&dwFlags);
+ if (FAILED(hr)) goto End;
+ hr = pfd->SetOptions(dwFlags | FOS_PICKFOLDERS);
+ if (FAILED(hr)) goto End;
+ hr = pfd->Show(NULL);
+ if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
+ goto End;
+ hr = pfd->GetResult(&pShellItem);
+ if (FAILED(hr)) goto End;
+ LPWSTR filePath;
+ hr = pShellItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath);
+ if (FAILED(hr))
{
- SHGetPathFromIDList(pidl, path);
-
- IMalloc * imalloc = 0;
- if (SUCCEEDED(SHGetMalloc(&imalloc)))
- {
- imalloc->Free(pidl);
- imalloc->Release();
- }
-
- return path;
+ goto End;
}
-
- return "";
+ path = wstrtostr(filePath);
+ CoTaskMemFree(filePath);
+#endif
+End:
+ return path;
}
int main(int argc, char* args[])
{
string cwd = EXECUTABLE_DIR;
-#ifdef _WIN32
+#ifdef _WIN32
if (argc > 1)
+ {
cwd = args[1];
+ }
+#endif
else
cwd = BrowseFolder();
-#endif
if (!cwd.empty())
load(cwd.c_str());