PolycodeToolLauncher.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "PolycodeToolLauncher.h"
  20. #if defined(__APPLE__) && defined(__MACH__)
  21. #include "PolyCocoaCore.h"
  22. #endif
  23. PolycodeRunner::PolycodeRunner(String polyappPath) : Threaded() {
  24. this->polyappPath = polyappPath;
  25. }
  26. void PolycodeRunner::runThread() {
  27. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  28. #if defined(__APPLE__) && defined(__MACH__)
  29. String command = "../MacOS/PolycodePlayer";
  30. String inFolder = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app/Contents/Resources";
  31. String args = polyappPath;
  32. #elif defined _WINDOWS
  33. String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.exe";
  34. String args = polyappPath;
  35. String inFolder = polycodeBasePath+"/Standalone/Player";
  36. #else
  37. String command = "./PolycodePlayer";
  38. String inFolder = polycodeBasePath+"/Standalone/Player";
  39. String args = polyappPath;
  40. #endif
  41. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command, args, inFolder);
  42. CoreServices::getInstance()->getCore()->removeDiskItem(polyappPath);
  43. }
  44. PolycodeToolLauncher::PolycodeToolLauncher() {
  45. }
  46. PolycodeToolLauncher::~PolycodeToolLauncher() {
  47. }
  48. String PolycodeToolLauncher::generateTempPath(PolycodeProject *project) {
  49. #ifdef _WINDOWS
  50. wchar_t buf[2048];
  51. GetTempPath(2048, buf);
  52. String retString = String(buf)+project->getProjectName();
  53. printf("TEMP_PATH: %s\n", retString.c_str());
  54. return retString;
  55. #else
  56. return "/tmp/"+project->getProjectName();
  57. #endif
  58. }
  59. void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destinationPath) {
  60. PolycodeConsole::print("Building project: "+project->getProjectName() + "\n");
  61. project->saveFile();
  62. String projectBasePath = project->getRootFolder();
  63. String projectPath = project->getProjectFile();
  64. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  65. #ifdef _WINDOWS
  66. String targetFolder = projectBasePath;
  67. String command = "\""+polycodeBasePath+"/Standalone/Bin/polybuild.exe\"";
  68. String args = "--config=\""+projectPath+"\" --out=\""+destinationPath+"\"";
  69. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command, args, targetFolder);
  70. #else
  71. String command = polycodeBasePath+"/Standalone/Bin/polybuild";
  72. String inFolder = projectBasePath;
  73. String args = "--config=\""+projectPath+"\" --out="+destinationPath;
  74. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command, args, inFolder);
  75. PolycodeConsole::print(ret);
  76. #endif
  77. }
  78. void PolycodeToolLauncher::runPolyapp(String polyappPath) {
  79. PolycodeConsole::clearBacktraces();
  80. // PolycodeRunner *runner = new PolycodeRunner(polyappPath);
  81. // CoreServices::getInstance()->getCore()->createThread(runner);
  82. #if defined(__APPLE__) && defined(__MACH__)
  83. CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
  84. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  85. String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app";
  86. // cocoaCore->launchApplicationWithFile(command, polyappPath);
  87. cocoaCore->openFileWithApplication(polyappPath, command);
  88. #else
  89. PolycodeRunner *runner = new PolycodeRunner(polyappPath);
  90. CoreServices::getInstance()->getCore()->createThread(runner);
  91. #endif
  92. }