Pushok

Easy config building

Jul 17th, 2011
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #define ROOT_SECTOR L"\"Sounds\""
  4. #define JOIN_SECTOR L"\"Connect\""
  5. #define T_SECTOR L"\"T Win\""
  6. #define CT_SECTOR L"\"CT Win\""
  7.  
  8. std::vector< std::wstring > g_vTSounds, g_vCTSounds, g_vJoinSounds;
  9.  
  10. void ReadFiles( TCHAR* szDataPath, std::vector< std::wstring > *vBuff )
  11. {
  12.     WIN32_FIND_DATA fData;
  13.     HANDLE l_hFile = FindFirstFile(szDataPath, &fData);
  14.  
  15.     do
  16.     {
  17.  
  18.         if( _tcscmp(fData.cFileName, L".mp3") )
  19.         {
  20.             vBuff->push_back(fData.cFileName);
  21.         }
  22.  
  23.     } while ( FindNextFile(l_hFile, &fData) );
  24.  
  25.     FindClose(l_hFile);
  26. }
  27.  
  28. void AddSector(TCHAR* szMainSector, TCHAR* szSectorName, std::vector< std::wstring > vBuff)
  29. {
  30.     DWORD l_dwPageCounter = 0;
  31.     WCHAR l_szCounterBuff[36];
  32.  
  33.     _itow_s(++l_dwPageCounter, l_szCounterBuff, 10);
  34.  
  35.     _tcscat(szMainSector, L"\t");
  36.     _tcscat(szMainSector, JOIN_SECTOR);
  37.     _tcscat(szMainSector, L"\n{\n");
  38.  
  39.     for(std::vector< std::wstring >::iterator i = vBuff.begin(); i != vBuff.end(); i++)
  40.     {
  41.  
  42.         _tcscat(szMainSector, L"\t\"");
  43.         _tcscat(szMainSector, l_szCounterBuff);
  44.         _tcscat(szMainSector, L"\"\n{\n\t\t");
  45.         _tcscat(szMainSector, L"\"sound\"\t\"");
  46.         _tcscat(szMainSector, i->c_str());
  47.         _tcscat(szMainSector, L"\"\n\t\t}\n");
  48.     }
  49. }
  50.  
  51. int _tmain(int argc, _TCHAR* argv[])
  52. {
  53.     TCHAR l_szDataPath[1024], l_szCTDataPath[1024], l_szTDataPath[1024];
  54.     GetCurrentDirectory(sizeof(l_szDataPath), l_szDataPath);
  55.  
  56.     _tcscpy(l_szCTDataPath, l_szDataPath);
  57.     _tcscpy(l_szTDataPath, l_szDataPath);
  58.  
  59.     _tcscat(l_szCTDataPath, L"\\ct\\*");
  60.     _tcscat(l_szTDataPath, L"\\t\\*");
  61.     _tcscat(l_szDataPath, L"\\*");
  62.  
  63.     ReadFiles(l_szDataPath, &g_vJoinSounds);
  64.     ReadFiles(l_szTDataPath, &g_vTSounds);
  65.     ReadFiles(l_szCTDataPath, &g_vCTSounds);
  66.  
  67.     TCHAR l_szBlock[4096];
  68.  
  69.     WCHAR l_szCounterBuff[36];
  70.     DWORD l_dwPageCounter = 0;
  71.    
  72.     HANDLE l_hConfig = CreateFile( L"qsounds.cfg", GENERIC_ALL, 0, 0, CREATE_ALWAYS, 0, 0);
  73.  
  74.     _tcscpy(l_szBlock, ROOT_SECTOR);
  75.     _tcscat(l_szBlock, L"\n{\n");
  76.    
  77.     AddSector(l_szBlock, JOIN_SECTOR, g_vJoinSounds);
  78.     AddSector(l_szBlock, T_SECTOR, g_vTSounds);
  79.     AddSector(l_szBlock, CT_SECTOR, g_vCTSounds);
  80.  
  81.     _tcscat(l_szBlock, L"}");
  82.  
  83.     DWORD l_dwCount;
  84.  
  85.     WriteFile(l_hConfig, l_szBlock, sizeof(l_szBlock), &l_dwCount, NULL);
  86.     CloseHandle(l_hConfig);
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment