INIWebpageURL.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: INIWebpageURL.cpp /////////////////////////////////////////////////////////////////////////////
  24. // Author: Bryan Cleveland, November 2001
  25. // Desc: Parsing Webpage URL INI entries
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/INI.h"
  30. #include "Common/Registry.h"
  31. #include "GameNetwork/WOLBrowser/WebBrowser.h"
  32. #ifdef _INTERNAL
  33. // for occasional debugging...
  34. //#pragma optimize("", off)
  35. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  36. #endif
  37. ///////////////////////////////////////////////////////////////////////////////////////////////////
  38. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  39. ///////////////////////////////////////////////////////////////////////////////////////////////////
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////
  41. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  42. ///////////////////////////////////////////////////////////////////////////////////////////////////
  43. AsciiString encodeURL(AsciiString source)
  44. {
  45. if (source.isEmpty())
  46. {
  47. return AsciiString::TheEmptyString;
  48. }
  49. AsciiString target;
  50. AsciiString allowedChars = "$-_.+!*'(),\\";
  51. const char *ptr = source.str();
  52. while (*ptr)
  53. {
  54. if (isalnum(*ptr) || allowedChars.find(*ptr))
  55. {
  56. target.concat(*ptr);
  57. }
  58. else
  59. {
  60. AsciiString tmp;
  61. target.concat('%');
  62. tmp.format("%2.2x", ((int)*ptr));
  63. target.concat(tmp);
  64. }
  65. ++ptr;
  66. }
  67. return target;
  68. }
  69. //-------------------------------------------------------------------------------------------------
  70. /** Parse Music entry */
  71. //-------------------------------------------------------------------------------------------------
  72. void INI::parseWebpageURLDefinition( INI* ini )
  73. {
  74. AsciiString tag;
  75. WebBrowserURL *url;
  76. // read the name
  77. const char* c = ini->getNextToken();
  78. tag.set( c );
  79. if (TheWebBrowser != NULL)
  80. {
  81. url = TheWebBrowser->findURL(tag);
  82. if (url == NULL)
  83. {
  84. url = TheWebBrowser->makeNewURL(tag);
  85. }
  86. }
  87. // find existing item if present
  88. // track = TheAudio->Music->getTrack( name );
  89. // if( track == NULL )
  90. // {
  91. // allocate a new track
  92. // track = TheAudio->Music->newMusicTrack( name );
  93. // } // end if
  94. // DEBUG_ASSERTCRASH( track, ("parseMusicTrackDefinition: Unable to allocate track '%s'\n",
  95. // name.str()) );
  96. // parse the ini definition
  97. ini->initFromINI( url, url->getFieldParse() );
  98. if (url->m_url.startsWith("file://"))
  99. {
  100. char cwd[_MAX_PATH] = "\\";
  101. getcwd(cwd, _MAX_PATH);
  102. url->m_url.format("file://%s\\Data\\%s\\%s", encodeURL(cwd).str(), GetRegistryLanguage().str(), url->m_url.str()+7);
  103. DEBUG_LOG(("INI::parseWebpageURLDefinition() - converted URL to [%s]\n", url->m_url.str()));
  104. }
  105. } // end parseMusicTrackDefinition