| 1683 | return 0; |
| 1684 | } |
| 1685 | static int Execute(lua_State* L)LNOEXCEPT |
| 1686 | { |
| 1687 | struct Detail_ |
| 1688 | { |
| 1689 | LNOINLINE static bool Execute(const char* path, const char* args, const char* directory, bool bWait, bool bShow)LNOEXCEPT |
| 1690 | { |
| 1691 | wstring tPath, tArgs, tDirectory; |
| 1692 | |
| 1693 | try |
| 1694 | { |
| 1695 | tPath = fcyStringHelper::MultiByteToWideChar(path, CP_UTF8); |
| 1696 | tArgs = fcyStringHelper::MultiByteToWideChar(args, CP_UTF8); |
| 1697 | if (directory) |
| 1698 | tDirectory = fcyStringHelper::MultiByteToWideChar(directory, CP_UTF8); |
| 1699 | |
| 1700 | SHELLEXECUTEINFO tShellExecuteInfo; |
| 1701 | memset(&tShellExecuteInfo, 0, sizeof(SHELLEXECUTEINFO)); |
| 1702 | |
| 1703 | tShellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFO); |
| 1704 | tShellExecuteInfo.fMask = bWait ? SEE_MASK_NOCLOSEPROCESS : 0; |
| 1705 | tShellExecuteInfo.lpVerb = L"open"; |
| 1706 | tShellExecuteInfo.lpFile = tPath.c_str(); |
| 1707 | tShellExecuteInfo.lpParameters = tArgs.c_str(); |
| 1708 | tShellExecuteInfo.lpDirectory = directory ? tDirectory.c_str() : nullptr; |
| 1709 | tShellExecuteInfo.nShow = bShow ? SW_SHOWDEFAULT : SW_HIDE; |
| 1710 | |
| 1711 | if (FALSE == ShellExecuteEx(&tShellExecuteInfo)) |
| 1712 | return false; |
| 1713 | |
| 1714 | if (bWait) |
| 1715 | { |
| 1716 | WaitForSingleObject(tShellExecuteInfo.hProcess, INFINITE); |
| 1717 | CloseHandle(tShellExecuteInfo.hProcess); |
| 1718 | } |
| 1719 | return true; |
| 1720 | } |
| 1721 | catch (const std::bad_alloc&) |
| 1722 | { |
| 1723 | return false; |
| 1724 | } |
| 1725 | } |
| 1726 | }; |
| 1727 | |
| 1728 | const char* path = luaL_checkstring(L, 1); |
| 1729 | const char* args = luaL_optstring(L, 2, ""); |
| 1730 | const char* directory = luaL_optstring(L, 3, NULL); |
| 1731 | bool bWait = true; |
| 1732 | bool bShow = true; |
| 1733 | if (lua_gettop(L) >= 4) |
| 1734 | bWait = lua_toboolean(L, 4) == 0 ? false : true; |
| 1735 | if (lua_gettop(L) >= 5) |
| 1736 | bShow = lua_toboolean(L, 5) == 0 ? false : true; |
| 1737 | |
| 1738 | lua_pushboolean(L, Detail_::Execute(path, args, directory, bWait, bShow)); |
| 1739 | return 1; |
| 1740 | } |
| 1741 | |
| 1742 | // 内置数学库 |
nothing calls this directly
no outgoing calls
no test coverage detected