winExec_ScriptBinding.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. /*! @addtogroup WindowsPlatform Windows Platform
  23. @ingroup TorqueScriptFunctions
  24. @{
  25. */
  26. /*! Executes a process
  27. @param executable The program to execute
  28. @param args Arguments to pass to the executable
  29. @param directory The directory in which the program is located
  30. @return Returns true on success, false otherwise
  31. */
  32. ConsoleFunctionWithDocs(shellExecute, ConsoleBool, 2, 4, (executable, [args]?, [directory]?))
  33. {
  34. ExecuteThread *et = new ExecuteThread(argv[1], argc > 2 ? argv[2] : NULL, argc > 3 ? argv[3] : NULL);
  35. if(! et->isAlive())
  36. {
  37. delete et;
  38. return false;
  39. }
  40. return true;
  41. }
  42. /*!
  43. @param executable The program to execute
  44. @param args Arguments to pass to the executable
  45. @param directory The directory in which the program is located
  46. @return Returns true on success, false otherwise
  47. */
  48. ConsoleFunctionWithDocs(shellExecuteBlocking, int, 2, 6, (executable, [args]?, [directory]?))
  49. {
  50. const char* executable = argv[1];
  51. const char* args = argc > 2 ? argv[2] : NULL;
  52. const char* directory = argc > 3 ? argv[3] : NULL;
  53. SHELLEXECUTEINFOA shl;
  54. dMemset(&shl, 0, sizeof(shl));
  55. shl.cbSize = sizeof(shl);
  56. shl.fMask = SEE_MASK_NOCLOSEPROCESS;
  57. char exeBuf[1024];
  58. Platform::makeFullPathName(executable, exeBuf, sizeof(exeBuf));
  59. shl.lpVerb = "open";
  60. shl.lpFile = exeBuf;
  61. shl.lpParameters = args;
  62. shl.lpDirectory = directory;
  63. shl.nShow = SW_HIDE;
  64. ShellExecuteExA(&shl);
  65. if ( shl.hProcess == NULL )
  66. return false;
  67. return ( WaitForSingleObject( shl.hProcess, INFINITE) == WAIT_OBJECT_0 );
  68. }
  69. //----------------------------------------------------------------
  70. /*! Opens a folder of the platform
  71. */
  72. ConsoleFunctionWithDocs(openFolder, void, 2, 2, (folder))
  73. {
  74. Platform::openFolder(argv[1]);
  75. }
  76. /*! @} */ // end group WindowsPlatform