Counter Strike : Global Offensive Source Code
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.

95 lines
2.4 KiB

  1. //====== Copyright Valve Corporation, All rights reserved. =================
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "cs_custom_texture_saver.h"
  8. #include "tier2/p4helpers.h"
  9. #include "p4lib/ip4.h"
  10. bool CCSCustomTextureSaver::Init()
  11. {
  12. m_materials.RemoveAll();
  13. m_bHasJob = false;
  14. return true;
  15. }
  16. void CCSCustomTextureSaver::AddMaterialToWatch( CustomMaterialGenerationData_t embroiderMaterial )
  17. {
  18. m_materials.AddToTail( embroiderMaterial );
  19. m_bHasJob = true;
  20. }
  21. void CCSCustomTextureSaver::Update( float frameTime )
  22. {
  23. if ( m_bHasJob == false )
  24. return;
  25. int count = m_materials.Count();
  26. if ( count == 0 )
  27. {
  28. m_bHasJob = false;
  29. return;
  30. }
  31. CUtlVector<CustomMaterialGenerationData_t> completedMaterials;
  32. for ( int i = 0; i < count; ++i )
  33. {
  34. int completionCount = 0;
  35. for ( int j = 0; j < m_materials[i].nTex; j++ )
  36. {
  37. completionCount += ( m_materials[i].pCustomMaterial->GetTexture( j )->GenerationComplete() );
  38. }
  39. if ( completionCount == 3 )
  40. {
  41. count--;
  42. completedMaterials.AddToTail( m_materials[i] );
  43. m_materials.Remove( i );
  44. i--;
  45. }
  46. }
  47. for ( int i = 0; i < completedMaterials.Count(); i++ )
  48. {
  49. for ( int j = 0; j < completedMaterials[i].nTex; j++ )
  50. {
  51. if ( g_pFullFileSystem->FileExists( completedMaterials[i].fileNames[j], "MOD" ) && !g_pFullFileSystem->IsFileWritable( completedMaterials[i].fileNames[j], "MOD" ) )
  52. {
  53. // Skip read only files
  54. continue;
  55. }
  56. IVTFTexture *pVTFTexture = completedMaterials[i].pCustomMaterial->GetTexture( j )->GetResultVTF();
  57. CUtlBuffer buf;
  58. pVTFTexture->Serialize(buf);
  59. FileHandle_t f = g_pFullFileSystem->Open( completedMaterials[i].fileNames[j], "wb", NULL );
  60. if ( f != FILESYSTEM_INVALID_HANDLE )
  61. {
  62. g_pFullFileSystem->Write( buf.Base(), buf.TellMaxPut(), f );
  63. g_pFullFileSystem->Close(f);
  64. }
  65. DevMsg( "Saved VTF %s\n", completedMaterials[i].fileNames[j] );
  66. char szFullVTFPath[ MAX_PATH ];
  67. g_pFullFileSystem->RelativePathToFullPath( completedMaterials[i].fileNames[j], "MOD", szFullVTFPath, sizeof( szFullVTFPath ) );
  68. g_p4factory->SetDummyMode( p4 == NULL );
  69. g_p4factory->SetOpenFileChangeList( completedMaterials[i].pchChangeListName );
  70. if ( !( p4->IsFileInPerforce( szFullVTFPath ) ) )
  71. CP4AutoAddFile autop4_add( szFullVTFPath );
  72. else
  73. CP4AutoEditFile autop4_edit( szFullVTFPath );
  74. }
  75. // TODO: add saved files to perforce
  76. }
  77. }