PolycodeToolLauncher.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. String command = "cd "+polycodeBasePath+"/Standalone/Player/PolycodePlayer.app/Contents/Resources && ../MacOS/PolycodePlayer "+polyappPath;
  29. ;
  30. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command);
  31. core->removeDiskItem(polyappPath);
  32. }
  33. PolycodeToolLauncher::PolycodeToolLauncher() {
  34. }
  35. PolycodeToolLauncher::~PolycodeToolLauncher() {
  36. }
  37. String PolycodeToolLauncher::generateTempPath() {
  38. return "/tmp/"+String::IntToString(rand() % 10000000);
  39. }
  40. void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destinationPath) {
  41. String projectBasePath = project->getRootFolder();
  42. String projectPath = project->getProjectFile();
  43. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  44. String command = "cd "+projectBasePath+" && "+polycodeBasePath+"/Standalone/Bin/polybuild --config="+projectPath+" --out="+destinationPath;
  45. String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command);
  46. PolycodeConsole::print(ret);
  47. }
  48. void PolycodeToolLauncher::runPolyapp(String polyappPath) {
  49. // PolycodeRunner *runner = new PolycodeRunner(polyappPath);
  50. // CoreServices::getInstance()->getCore()->createThread(runner);
  51. #if defined(__APPLE__) && defined(__MACH__)
  52. CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
  53. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  54. String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app";
  55. cocoaCore->launchApplicationWithFile(command, polyappPath);
  56. #else
  57. #endif
  58. }