ActiveXWebPlugin.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 ActiveXWebPlugin
  24. {
  25. // GUID
  26. var $REGISTRY_APPID_RESOURCEID = "";
  27. var $WEBGAME_UUID = "";
  28. var $IWEBGAMECTRL_UUID = "";
  29. var $WEBGAMELIB_UUID = "";
  30. var $WEBGAME_PLUGINNAME = "";
  31. var $WEBGAME_CTRLNAME = "";
  32. var $PLUGIN_DLL = "";
  33. var $PLUGIN_VERSION = "";
  34. var $FOLDER = "";
  35. var $GAMEFOLDER = "";
  36. function ActiveXWebPlugin()
  37. {
  38. // Setup our GUID
  39. //$this->REGISTRY_APPID_RESOURCEID = ActiveXWebPlugin::generateUUID();
  40. //$this->WEBGAME_UUID = ActiveXWebPlugin::generateUUID();
  41. //$this->IWEBGAMECTRL_UUID = ActiveXWebPlugin::generateUUID();
  42. //$this->WEBGAMELIB_UUID = ActiveXWebPlugin::generateUUID();
  43. $rootPhpBuildDir = getcwd();
  44. $this->FOLDER = $rootPhpBuildDir."\\web\\source\\activex\\";
  45. $this->GAMEFOLDER = $rootPhpBuildDir."\\game\\";
  46. $this->PLUGIN_DLL = WebDeploymentWindows::$axPluginName.".dll";
  47. $this->PLUGIN_VERSION = WebDeploymentWindows::$version;
  48. $this->REGISTRY_APPID_RESOURCEID = WebDeploymentWindows::$axAppUUID;
  49. $this->WEBGAME_UUID = WebDeploymentWindows::$axWebGameUUID;
  50. $this->IWEBGAMECTRL_UUID = WebDeploymentWindows::$axWebGameCtrlUUID;
  51. $this->WEBGAMELIB_UUID = WebDeploymentWindows::$axWebGameLibUUID;
  52. $this->WEBGAME_PLUGINNAME = str_replace(" ", "", WebDeploymentWindows::$axPluginName);
  53. $this->WEBGAME_CTRLNAME = "IEWebGameCtrl";//str_replace(" ", "", WebDeploymentWindows::$axPluginName)."Ctrl";
  54. }
  55. function process($project)
  56. {
  57. $html = 'file://'.getcwd().'/game/web/sample.html';
  58. $html = str_replace("\\", "/", $html);
  59. // if the someone is clever enough to change the default location of IE, they are assumed to be
  60. // clever enough to edit the debug command :)
  61. $IEExe = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
  62. if (file_exists("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe"))
  63. $IEExe = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe";
  64. $project->commandRelease = $IEExe;
  65. $project->commandDebug = $IEExe;
  66. $project->commandOptimized = $IEExe;
  67. $project->argsRelease = $html;
  68. $project->argsDebug = $html;
  69. $project->argsOptimized = $html;
  70. $this->processTemplates();
  71. }
  72. function readTemplate($filename)
  73. {
  74. $filename = realpath( dirname( $_SERVER[ 'PHP_SELF' ] ) ). "/templates/web/".$filename;
  75. $fh = fopen($filename, 'r');
  76. $data = fread($fh, filesize($filename));
  77. fclose($fh);
  78. return $data;
  79. }
  80. function writeFile($filename, $data)
  81. {
  82. $filename = $this->FOLDER . $filename;
  83. $fh = fopen($filename, 'w');
  84. fwrite($fh, $data);
  85. fclose($fh);
  86. }
  87. function writeGameFile($filename, $data)
  88. {
  89. $filename = $this->GAMEFOLDER . $filename;
  90. $fh = fopen($filename, 'w');
  91. fwrite($fh, $data);
  92. fclose($fh);
  93. }
  94. function processTemplates()
  95. {
  96. // Make sure these come first so timestamp is oldest (for autogeneration)
  97. $gen = $this->readTemplate("activex_IEWebGamePlugin_i_h.tpl");
  98. $this->writeFile("IEWebGamePlugin_i.h", $gen);
  99. $gen = $this->readTemplate("activex_IEWebGamePlugin_i_c.tpl");
  100. $this->writeFile("IEWebGamePlugin_i.c", $gen);
  101. // WebGame.idl
  102. $idl = $this->readTemplate("activex_IEWebGamePlugin_idl.tpl");
  103. $idl = str_replace("__WEBGAME_UUID__", $this->WEBGAME_UUID, $idl);
  104. $idl = str_replace("__IWEBGAMECTRL_UUID__", $this->IWEBGAMECTRL_UUID, $idl);
  105. $idl = str_replace("__WEBGAMELIB_UUID__", $this->WEBGAMELIB_UUID, $idl);
  106. $idl = str_replace("__WEBGAME_PLUGINNAME__", $this->WEBGAME_PLUGINNAME, $idl);
  107. $this->writeFile("IEWebGamePlugin.idl", $idl);
  108. // dllmain.h
  109. $dllmain = $this->readTemplate("activex_dllmain_h.tpl");
  110. $dllmain = str_replace("__WEBGAME_PLUGINNAME__", $this->WEBGAME_PLUGINNAME, $dllmain);
  111. $dllmain = str_replace("__REGISTRY_APPID_RESOURCEID__", $this->REGISTRY_APPID_RESOURCEID, $dllmain);
  112. $this->writeFile("dllmain.h", $dllmain);
  113. //WebGameCtrl.rgs
  114. $regs = $this->readTemplate("activex_IEWebGameCtrl_rgs.tpl");
  115. $regs = str_replace("__WEBGAME_UUID__", $this->WEBGAME_UUID, $regs);
  116. $regs = str_replace("__WEBGAMELIB_UUID__", $this->WEBGAMELIB_UUID, $regs);
  117. $regs = str_replace("__WEBGAME_PLUGINNAME__", $this->WEBGAME_PLUGINNAME, $regs);
  118. $regs = str_replace("__WEBGAME_CTRLNAME__", $this->WEBGAME_CTRLNAME, $regs);
  119. $this->writeFile("IEWebGameCtrl.rgs", $regs);
  120. //WebGamePlugin.rgs
  121. $regs = $this->readTemplate("activex_IEWebGamePlugin_rgs.tpl");
  122. $regs = str_replace("__WEBGAME_PLUGINNAME__", $this->WEBGAME_PLUGINNAME, $regs);
  123. $regs = str_replace("__WEBGAME_CTRLNAME__", $this->WEBGAME_CTRLNAME, $regs);
  124. $this->writeFile("IEWebGamePlugin.rgs", $regs);
  125. //WebGameCtrl.rc
  126. $rc = $this->readTemplate("activex_IEWebGamePlugin_rc.tpl");
  127. $rc = str_replace("__PLUGIN_DLL__", $this->PLUGIN_DLL, $rc);
  128. $rc = str_replace("__WEBGAME_PLUGINNAME__", $this->WEBGAME_PLUGINNAME, $rc);
  129. //versioning
  130. $rc = str_replace("__PLUGIN_VERSION_STRING__", $this->PLUGIN_VERSION, $rc);
  131. $cd = str_replace(".", "," , $this->PLUGIN_VERSION);
  132. $rc = str_replace("__PLUGIN_VERSION_COMMA_DELIMITED__", $cd, $rc);
  133. $this->writeFile("IEWebGamePlugin.rc", $rc);
  134. // handle the sample HTML (and whatever else) that is shared between plugins
  135. WebPlugin::processActiveXPlugin($this);
  136. }
  137. static function generateUUID()
  138. {
  139. $command = realpath( dirname( $_SERVER[ 'PHP_SELF' ] ) )."\\..\\..\\Engine\\bin\\uuidgen\\uuidgen.exe -c";
  140. exec($command, $output);
  141. return $output[0];
  142. }
  143. }
  144. ?>