From 281f8feabffd69928a0a0f08aa31f70b36f5e6bd Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 3 Nov 2018 21:11:41 +0800 Subject: =?UTF-8?q?*=E5=A2=9E=E5=8A=A0=E6=B8=B8=E6=88=8F=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jin/main.cpp | 78 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 22 deletions(-) (limited to 'src/jin/main.cpp') diff --git a/src/jin/main.cpp b/src/jin/main.cpp index d4f08a0..e129b78 100644 --- a/src/jin/main.cpp +++ b/src/jin/main.cpp @@ -1,36 +1,27 @@ #ifdef _WIN32 - #include - #include +#include +#include #endif #include "lua/luax.h" #include "lua/jin.h" #include "libjin/jin.h" + +#ifdef _WIN32 +#include #include +#endif + +#define EXECUTABLE_DIR "./" +using namespace std; using namespace JinEngine::Filesystem; using namespace JinEngine::Lua; -static void setParamters(lua_State* L, int argc, char* args[]) +// Load game under cwd. +static void load(const char* cwd) { - // Add args to field. - luax_newtable(L); - for (int i = 0; i < argc; ++i) - luax_setrawstring(L, -2, i + 1, args[i]); - luax_setfield(L, -2, "args"); - // Push current working directory. - // Absolute directory. - Buffer cwd = Buffer(1024); -#ifdef _WIN32 - _getcwd((char*)&cwd, cwd.size()); -#elif defined __unix__ -#elif defined __APPLE__ -#endif - luax_setfieldstring(L, "cwd", (char*)&cwd); -} -int main(int argc, char* args[]) -{ // Global lua runtime. lua_State* L = luax_newstate(); @@ -38,8 +29,10 @@ int main(int argc, char* args[]) luax_openlibs(L); // Open jin module. luaopen_jin(L); - // Set parameters. - setParamters(L, argc, args); + // Set current working directory. + luax_newtable(L); + luax_setfieldstring(L, "cwd", cwd); + luax_setfield(L, -2, "args"); // Clear lua stack. luax_clearstack(L); @@ -49,5 +42,46 @@ int main(int argc, char* args[]) // Close lua lib. luax_close(L); +} + +std::string BrowseFolder() +{ + 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); + + if (pidl != 0) + { + SHGetPathFromIDList(pidl, path); + + IMalloc * imalloc = 0; + if (SUCCEEDED(SHGetMalloc(&imalloc))) + { + imalloc->Free(pidl); + imalloc->Release(); + } + + return path; + } + + return ""; +} + +int main(int argc, char* args[]) +{ + string cwd = EXECUTABLE_DIR; +#ifdef _WIN32 + if (argc > 1) + cwd = args[1]; + else + cwd = BrowseFolder(); +#endif + if (!cwd.empty()) + load(cwd.c_str()); + return 0; } \ No newline at end of file -- cgit v1.1-26-g67d0