Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. /**
  3. * Utility class for providing some basic capabilities for enumerating and specifying MOD
  4. * directories.
  5. *
  6. * \version 1.0
  7. *
  8. * \date 07-18-2006
  9. *
  10. * \author mdurand
  11. *
  12. * \todo
  13. *
  14. * \bug
  15. *
  16. */
  17. #include "ModConfigsHelper.h"
  18. #include <windows.h>
  19. ModConfigsHelper::ModConfigsHelper()
  20. {
  21. setSourceModBaseDir();
  22. EnumerateModDirs();
  23. }
  24. /**
  25. * Default destructor.
  26. */
  27. ModConfigsHelper::~ModConfigsHelper()
  28. {
  29. // Empty the vector of directory names
  30. m_ModDirs.PurgeAndDeleteElements();
  31. }
  32. /**
  33. * Getter method that provides the parent directory for all MODs.
  34. * \return parent directory for all MODs
  35. */
  36. const char *ModConfigsHelper::getSourceModBaseDir()
  37. {
  38. return m_sourceModBaseDir;
  39. }
  40. /**
  41. * Getter method that provides a vector of the names of each MOD found.
  42. * \return vector of the names of each MOD found
  43. */
  44. const CUtlVector<char *> &ModConfigsHelper::getModDirsVector()
  45. {
  46. return m_ModDirs;
  47. }
  48. /**
  49. * Determines and sets the base directory for all MODs
  50. */
  51. void ModConfigsHelper::setSourceModBaseDir()
  52. {
  53. Q_strncpy( m_sourceModBaseDir, GetSDKLauncherBaseDirectory(), sizeof( m_sourceModBaseDir) ); // Start with the base directory
  54. Q_StripLastDir( m_sourceModBaseDir, sizeof( m_sourceModBaseDir ) ); // Get rid of the 'sourcesdk' directory.
  55. Q_StripLastDir( m_sourceModBaseDir, sizeof( m_sourceModBaseDir ) ); // Get rid of the '%USER%' directory.
  56. Q_strncat( m_sourceModBaseDir, "SourceMods", sizeof( m_sourceModBaseDir ), COPY_ALL_CHARACTERS ); // Add 'SourceMods'
  57. }
  58. /**
  59. * Searches the parent MOD directory for child MODs and puts their names in the member vector
  60. */
  61. void ModConfigsHelper::EnumerateModDirs()
  62. {
  63. char szWildCardPath[MAX_PATH];
  64. WIN32_FIND_DATA wfd;
  65. Q_strncpy( szWildCardPath, m_sourceModBaseDir, sizeof( szWildCardPath ) );
  66. Q_AppendSlash( szWildCardPath, sizeof( szWildCardPath ) );
  67. Q_strncat( szWildCardPath, "*.*", sizeof( szWildCardPath ), COPY_ALL_CHARACTERS );
  68. HANDLE ff = FindFirstFile( szWildCardPath, &wfd );
  69. do
  70. {
  71. if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  72. {
  73. if ( wfd.cFileName[ 0 ] == '.' )
  74. {
  75. continue;
  76. }
  77. else
  78. {
  79. // They are directories not named '.' or '..' so add them to the list of mod directories
  80. char *dirName = new char[ strlen( wfd.cFileName ) + 1 ];
  81. Q_strncpy( dirName, wfd.cFileName, strlen( wfd.cFileName ) + 1 );
  82. m_ModDirs.AddToTail( dirName );
  83. }
  84. }
  85. } while ( FindNextFile( ff, &wfd ) );
  86. }