PolycodeToolLauncher.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. GenericRunner::GenericRunner(String app, String file, String inFolder) : Threaded() {
  24. this->app = app;
  25. this->file = file;
  26. this->inFolder = inFolder;
  27. }
  28. void GenericRunner::runThread() {
  29. #if defined(__APPLE__) && defined(__MACH__)
  30. CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
  31. cocoaCore->openFileWithApplication(file, app);
  32. #else
  33. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(app, file, inFolder);
  34. #endif
  35. }
  36. PolycodeRunner::PolycodeRunner(String polyappPath) : Threaded() {
  37. this->polyappPath = polyappPath;
  38. }
  39. void PolycodeRunner::runThread() {
  40. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  41. #if defined(__APPLE__) && defined(__MACH__)
  42. String command = "../MacOS/PolycodePlayer";
  43. String inFolder = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app/Contents/Resources";
  44. String args = polyappPath;
  45. #elif defined _WINDOWS
  46. String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.exe";
  47. String args = polyappPath;
  48. String inFolder = polycodeBasePath+"/Standalone/Player";
  49. #else
  50. String command = "./PolycodePlayer";
  51. String inFolder = polycodeBasePath+"/Standalone/Player";
  52. String args = polyappPath;
  53. #endif
  54. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command, args, inFolder);
  55. CoreServices::getInstance()->getCore()->removeDiskItem(polyappPath);
  56. }
  57. PolycodeToolLauncher::PolycodeToolLauncher() {
  58. }
  59. PolycodeToolLauncher::~PolycodeToolLauncher() {
  60. }
  61. String PolycodeToolLauncher::generateTempPath(PolycodeProject *project) {
  62. #ifdef _WINDOWS
  63. wchar_t buf[2048];
  64. GetTempPath(2048, buf);
  65. String retString = String(buf)+project->getProjectName();
  66. printf("TEMP_PATH: %s\n", retString.c_str());
  67. return retString;
  68. #else
  69. return "/tmp/"+project->getProjectName();
  70. #endif
  71. }
  72. void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destinationPath, bool compileScripts) {
  73. PolycodeConsole::print("Building project: "+project->getProjectName() + "\n");
  74. project->saveFile();
  75. String projectBasePath = project->getRootFolder();
  76. String projectPath = project->getProjectFile();
  77. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  78. #ifdef _WINDOWS
  79. String targetFolder = projectBasePath;
  80. String command = "\""+polycodeBasePath+"/Standalone/Bin/polybuild.exe\"";
  81. String args = "--config=\""+projectPath+"\" --out=\""+destinationPath+"\" --compileScripts=\""+((compileScripts)?"true":"false")+"\"";
  82. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command, args, targetFolder);
  83. #else
  84. String command = polycodeBasePath+"/Standalone/Bin/polybuild";
  85. String inFolder = projectBasePath;
  86. String args = "--config=\""+projectPath+"\" --out=\""+destinationPath+"\" --compileScripts=\""+((compileScripts)?"true":"false")+"\"";
  87. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command, args, inFolder);
  88. // PolycodeConsole::print(ret);
  89. #endif
  90. }
  91. void PolycodeToolLauncher::openExternalEditor(String app, String file, String inFolder) {
  92. GenericRunner *runner = new GenericRunner(app, "\""+file+"\"", inFolder);
  93. CoreServices::getInstance()->getCore()->createThread(runner);
  94. }
  95. void PolycodeToolLauncher::runPolyapp(String polyappPath) {
  96. PolycodeConsole::clearBacktraces();
  97. #if defined(__APPLE__) && defined(__MACH__)
  98. CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
  99. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  100. String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app";
  101. cocoaCore->openFileWithApplication(polyappPath, command);
  102. #else
  103. PolycodeRunner *runner = new PolycodeRunner(polyappPath);
  104. CoreServices::getInstance()->getCore()->createThread(runner);
  105. #endif
  106. }