AVAssetSuck.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. ** Command & Conquer Renegade(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. #include "stdafx.h"
  19. #include "avassetsuck.h"
  20. #include "ffactory.h"
  21. #include "mixfile.h"
  22. #include "rawfile.h"
  23. #include "bittype.h"
  24. #include "mixcombiningdialog.h"
  25. AVAssetSuckerClass::AVAssetSuckerClass(void) :
  26. Dialog(NULL)
  27. {
  28. }
  29. void AVAssetSuckerClass::Suck(char *input_file, char *output_file)
  30. {
  31. strcpy(InputFile, input_file);
  32. strcpy(OutputFile, output_file);
  33. //
  34. // Kick off the worker thread...
  35. //
  36. ::AfxBeginThread (Do_Stuff, (LPVOID)this);
  37. //
  38. // Show the UI
  39. //
  40. MixCombiningDialogClass dialog;
  41. Dialog = &dialog;
  42. dialog.DoModal();
  43. }
  44. unsigned int AVAssetSuckerClass::Do_Stuff(void *param)
  45. {
  46. ((AVAssetSuckerClass*)param)->Thread_Suck();
  47. return(1);
  48. }
  49. void AVAssetSuckerClass::Thread_Suck(void)
  50. {
  51. char name[_MAX_PATH];
  52. while (Dialog == NULL) {
  53. Sleep(0);
  54. }
  55. /*
  56. ** Get just the file name.
  57. */
  58. char justname[_MAX_PATH];
  59. _splitpath(InputFile, NULL, NULL, justname, NULL);
  60. char text[_MAX_PATH + 128];
  61. sprintf(text, "Copying files from %s...", justname);
  62. Dialog->Set_Title("Stripping AV assets...");
  63. Dialog->Set_Status_Text(text);
  64. Dialog->Set_Progress_Percent (0);
  65. MixFileFactoryClass mix_in(InputFile, _TheFileFactory);
  66. if (mix_in.Is_Valid() && mix_in.Build_Internal_Filename_List()) {
  67. /*
  68. ** Get the list of files in the source mix file.
  69. */
  70. DynamicVectorClass<StringClass> filename_list;
  71. mix_in.Get_Filename_List(filename_list);
  72. /*
  73. ** Create the output mix file.
  74. */
  75. MixFileCreator mix_out(OutputFile);
  76. /*
  77. ** Loop through all the files copying anything that isn't audio or texture.
  78. */
  79. for (int i=0 ; i<filename_list.Count() ; i++) {
  80. strcpy(name, filename_list[i].Peek_Buffer());
  81. strupr(name);
  82. if (strstr(name, ".WAV") == 0) {
  83. if (strstr(name, ".TGA") == 0) {
  84. if (strstr(name, ".DDS") == 0) {
  85. if (strstr(name, ".MP3") == 0) {
  86. Copy_File(&mix_in, &mix_out, filename_list[i].Peek_Buffer());
  87. }
  88. }
  89. }
  90. }
  91. Dialog->Set_Progress_Percent((float)i / float(filename_list.Count() + 1));
  92. }
  93. }
  94. Dialog->PostMessage(WM_COMMAND, MAKELPARAM(IDOK, BN_CLICKED));
  95. }
  96. void AVAssetSuckerClass::Copy_File(MixFileFactoryClass *src_mix, MixFileCreator *dest_mix, char *filename)
  97. {
  98. //
  99. // Get the file data from the source mix
  100. //
  101. FileClass *src_file = src_mix->Get_File (filename);
  102. src_file->Open ();
  103. int size = src_file->Size();
  104. //
  105. // Create a temporary destination file for the data
  106. //
  107. char temp_file_name[_MAX_PATH];
  108. char temp_path[_MAX_PATH];
  109. int chars = GetTempPath(_MAX_PATH, temp_path);
  110. if (chars) {
  111. int res = GetTempFileName(temp_path, "MIX", 0, temp_file_name);
  112. if (res == 0) {
  113. WWDEBUG_SAY(("GetTempFileName failed with error code %d\n", GetLastError()));
  114. } else {
  115. RawFileClass temp_file(temp_file_name);
  116. if (temp_file.Open(RawFileClass::WRITE)) {
  117. //
  118. // Save the data in the temp file.
  119. //
  120. void *bigbuf = new char [size + 1024];
  121. src_file->Read(bigbuf, size);
  122. temp_file.Write(bigbuf, size);
  123. temp_file.Close();
  124. //
  125. // Add the temp file to the mix file.
  126. //
  127. dest_mix->Add_File(temp_file_name, filename);
  128. //
  129. // Delete the temp file.
  130. //
  131. DeleteFile(temp_file_name);
  132. }
  133. }
  134. }
  135. src_mix->Return_File(src_file);
  136. }