NPWebPlugin.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 NPWebPlugin
  24. {
  25. var $FOLDER = "";
  26. var $GAMEFOLDER = "";
  27. var $PLUGINNAME = "";
  28. var $COMPANY = "";
  29. var $COMPANYKEY = "";
  30. var $PLUGIN = "";
  31. var $PRODUCTNAME = "";
  32. var $VERSION = "";
  33. var $MIMETYPE = "";
  34. var $DESCRIPTION = "";
  35. function NPWebPlugin()
  36. {
  37. $rootPhpBuildDir = getcwd();
  38. $this->FOLDER = $rootPhpBuildDir."\\web\\source\\npplugin\\windows\\";
  39. $this->GAMEFOLDER = $rootPhpBuildDir."\\game\\";
  40. $this->PLUGINNAME = WebDeploymentWindows::$npPluginName;
  41. $this->COMPANY = WebDeploymentWindows::$company;
  42. $this->COMPANYKEY = WebDeploymentWindows::$companyKey;
  43. $this->PLUGIN = WebDeploymentWindows::$plugin;
  44. $this->PRODUCTNAME = WebDeploymentWindows::$productName;
  45. $this->VERSION = WebDeploymentWindows::$version;
  46. $this->MIMETYPE = WebDeploymentWindows::$mimeType;
  47. $this->DESCRIPTION = WebDeploymentWindows::$description." ".$this->VERSION;
  48. }
  49. function process($project)
  50. {
  51. $windowsRegistry = new WindowsRegistry();
  52. $MozillaVersion = $windowsRegistry->ReadValue('HKEY_LOCAL_MACHINE\\SOFTWARE\\Mozilla\\Mozilla Firefox', 'CurrentVersion', TRUE);
  53. $MozillaExe = $windowsRegistry->ReadValue('HKEY_LOCAL_MACHINE\\SOFTWARE\\Mozilla\\Mozilla Firefox\\'.$MozillaVersion.'\\Main', 'PathToExe', TRUE);
  54. // FireFox registry settings
  55. $MozillaKey = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\MozillaPlugins\\@';
  56. $html = 'file://'.getcwd().'/game/web/sample.html';
  57. $html = str_replace("\\", "/", $html);
  58. $html = str_replace(" ", "%20", $html);
  59. $project->commandRelease = $MozillaExe;
  60. $project->commandDebug = $MozillaExe;
  61. $project->commandOptimized = $MozillaExe;
  62. $project->argsRelease = $html;
  63. $project->argsDebug = $html;
  64. $project->argsOptimized = $html;
  65. //$windowsRegistry->WriteValue($MozillaKey.$this->COMPANYKEY.'/'.$this->PLUGIN, 'Path', $this->GAMEFOLDER.$this->PLUGINNAME.'.dll');
  66. //$windowsRegistry->WriteValue($MozillaKey.$this->COMPANYKEY.'/'.$this->PLUGIN, 'ProductName', $this->PRODUCTNAME);
  67. //$windowsRegistry->WriteValue($MozillaKey.$this->COMPANYKEY.'/'.$this->PLUGIN, 'Vendor', $this->COMPANY);
  68. //$windowsRegistry->WriteValue($MozillaKey.$this->COMPANYKEY.'/'.$this->PLUGIN, 'Version', $this->VERSION);
  69. //$windowsRegistry->WriteValue($MozillaKey.$this->COMPANYKEY.'/'.$this->PLUGIN.'\\MimeTypes\\application/'.$this->MIMETYPE, 'Description', $this->DESCRIPTION);
  70. unset($windowsRegistry);
  71. $this->processTemplates();
  72. setProjectModuleDefinitionFile('../../../web/source/npplugin/windows/npWebGamePlugin.def');
  73. /// Prefs
  74. addProjectDefine( 'TORQUE_SHADERGEN' );
  75. addProjectDefine( 'TORQUE_SHARED' );
  76. addProjectDefine( 'TORQUE_WEBDEPLOY' );
  77. // Firefox
  78. addProjectDefine( 'FIREFOXPLUGIN_EXPORTS' );
  79. addProjectDefine( 'MOZILLA_STRICT_API' );
  80. addProjectDefine( 'XP_WIN' );
  81. addProjectDefine( 'WIN32' );
  82. addProjectDefine( '_WINDOWS' );
  83. addProjectDefine( '_USRDLL' );
  84. addSrcDir( '../web/source/common' );
  85. addSrcDir( '../web/source/npplugin' );
  86. addSrcDir( '../web/source/npplugin/windows' );
  87. // Additional includes
  88. addIncludePath( "../../web/source/npplugin/windows" );
  89. addProjectLibDir( getAppLibSrcDir() . 'SDL/win32' );
  90. addProjectLibDir( getAppLibSrcDir() . 'unicode' );
  91. // addProjectLibDir( getAppLibSrcDir() . 'mozilla/lib' );
  92. addProjectLibInput('COMCTL32.LIB');
  93. addProjectLibInput('COMDLG32.LIB');
  94. addProjectLibInput('USER32.LIB');
  95. addProjectLibInput('ADVAPI32.LIB');
  96. addProjectLibInput('GDI32.LIB');
  97. addProjectLibInput('WINMM.LIB');
  98. addProjectLibInput('WS2_32.LIB');
  99. addProjectLibInput('vfw32.lib');
  100. addProjectLibInput('Imm32.lib');
  101. addProjectLibInput('UnicoWS.lib');
  102. addProjectLibInput('opengl32.lib');
  103. addProjectLibInput('glu32.lib');
  104. addProjectLibInput('ole32.lib');
  105. addProjectLibInput('shell32.lib');
  106. addProjectLibInput('oleaut32.lib');
  107. addProjectLibInput('version.lib');
  108. }
  109. function readTemplate($filename)
  110. {
  111. $filename = realpath( dirname( $_SERVER[ 'PHP_SELF' ] ) ). "/templates/web/".$filename;
  112. $fh = fopen($filename, 'r');
  113. $data = fread($fh, filesize($filename));
  114. fclose($fh);
  115. return $data;
  116. }
  117. function writeFile($filename, $data)
  118. {
  119. $filename = $this->FOLDER . $filename;
  120. $fh = fopen($filename, 'w');
  121. fwrite($fh, $data);
  122. fclose($fh);
  123. }
  124. function writeGameFile($filename, $data)
  125. {
  126. $filename = $this->GAMEFOLDER . $filename;
  127. $fh = fopen($filename, 'w');
  128. fwrite($fh, $data);
  129. fclose($fh);
  130. }
  131. function processTemplates()
  132. {
  133. $data = $this->readTemplate("firefox_rc.tpl");
  134. $cd = str_replace(".", "," , $this->VERSION);
  135. $data = str_replace("__PRODUCTVERSION__", $cd, $data);
  136. $data = str_replace("__FILEDESCRIPTION__", $this->DESCRIPTION, $data);
  137. $data = str_replace("__INTERNALNAME__", $this->PRODUCTNAME, $data);
  138. $data = str_replace("__MIMETYPE__", "application/".$this->MIMETYPE, $data);
  139. $data = str_replace("__ORIGINALFILENAME__", $this->PLUGINNAME.'.dll', $data);
  140. $data = str_replace("__PRODUCTNAME__", $this->PRODUCTNAME, $data);
  141. $data = str_replace("__COMPANY__", $this->COMPANY, $data);
  142. $data = str_replace("__COMPANYKEY__", $this->COMPANYKEY, $data);
  143. $data = str_replace("__PLUGIN__", $this->PLUGIN, $data);
  144. $this->writeFile('NPWebGamePlugin.rc', $data);
  145. // handle the sample HTML (and whatever else) that is shared between plugins
  146. WebPlugin::processNPPlugin($this);
  147. }
  148. }
  149. ?>