SafariWebPlugin.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. //-----------------------------------------------------------------------------
  3. // Copyright (c) 2012 GarageGames, LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. class SafariWebPlugin
  24. {
  25. var $FOLDER = "";
  26. var $GAMEFOLDER = "";
  27. var $PLUGINNAME = "";
  28. var $MIMETYPE = "";
  29. var $DESCRIPTION = "";
  30. var $IDENTIFIER = "";
  31. var $BUNDLE = "";
  32. var $VERSION = "";
  33. function SafariWebPlugin()
  34. {
  35. $rootPhpBuildDir = getcwd();
  36. $this->FOLDER = $rootPhpBuildDir."/web/source/npplugin/mac/";
  37. $this->GAMEFOLDER = $rootPhpBuildDir."/game/";
  38. $this->PLUGINNAME = WebDeploymentOSX::$safariPluginName;
  39. $this->MIMETYPE = WebDeploymentOSX::$mimeType;
  40. $this->VERSION = WebDeploymentOSX::$version;
  41. $this->DESCRIPTION = WebDeploymentOSX::$description." ".$this->VERSION ;
  42. $this->BUNDLE = WebDeploymentOSX::$safariPluginName;
  43. $this->IDENTIFIER = WebDeploymentOSX::$identifier;
  44. }
  45. function process($project)
  46. {
  47. $this->processTemplates();
  48. }
  49. function readTemplate($filename)
  50. {
  51. $filename = realpath( dirname( $_SERVER[ 'PHP_SELF' ] ) ). "/templates/web/".$filename;
  52. $fh = fopen($filename, 'r');
  53. $data = fread($fh, filesize($filename));
  54. fclose($fh);
  55. return $data;
  56. }
  57. function writeFile($filename, $data)
  58. {
  59. $filename = $this->FOLDER . $filename;
  60. echo($filename);
  61. $fh = fopen($filename, 'w');
  62. fwrite($fh, $data);
  63. fclose($fh);
  64. }
  65. function writeGameFile($filename, $data)
  66. {
  67. $filename = $this->GAMEFOLDER . $filename;
  68. $fh = fopen($filename, 'w');
  69. fwrite($fh, $data);
  70. fclose($fh);
  71. }
  72. function processTemplates()
  73. {
  74. $data = $this->readTemplate("safari_Info_plist.tpl");
  75. $data = str_replace("__CFBundleExecutable__", $this->BUNDLE, $data);
  76. $data = str_replace("__CFBundleIdentifier__", $this->IDENTIFIER, $data);
  77. $data = str_replace("__WebPluginDescription__", $this->DESCRIPTION, $data);
  78. $data = str_replace("__WebPluginMIMEType__", "application/".$this->MIMETYPE, $data);
  79. $data = str_replace("__WebPluginName__", $this->PLUGINNAME, $data);
  80. $data = str_replace("__GameName__", getGameProjectName(), $data);
  81. //TODO: handled by Toolbox
  82. $data = str_replace("__GameInstallPath__", $this->GAMEFOLDER, $data);
  83. $this->writeFile('Info.plist', $data);
  84. WebPlugin::processNPPlugin($this);
  85. }
  86. }
  87. ?>