MakeMix.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. // MakeMix.cpp : Defines the entry point for the console application.
  19. //
  20. // Includes.
  21. #include "stdafx.h"
  22. #include "MixFile.h"
  23. // Private functions.
  24. static unsigned Add_Files (const StringClass &basepath, const StringClass &subpath, MixFileCreator &mixfile);
  25. int main (int argc, char *argv[])
  26. {
  27. // Must have at least 3 command line arguments - the executable, a full source path, and a mixfile name.
  28. if (argc >= 3) {
  29. MixFileCreator mixfile (argv [argc - 1]);
  30. for (int c = 1; c < argc - 1; c++) {
  31. unsigned filecount;
  32. StringClass basepath (argv [c]);
  33. StringClass subpath;
  34. filecount = Add_Files (basepath, subpath, mixfile);
  35. if (filecount > 0) {
  36. printf ("%u files added\n", filecount);
  37. } else {
  38. printf ("No files found in source directory\n");
  39. }
  40. }
  41. } else {
  42. printf ("Usage - MakeMix <source directory0>..<source directory n> <mixfilename>\n");
  43. }
  44. return (0);
  45. }
  46. unsigned Add_Files (const StringClass &basepath, const StringClass &subpath, MixFileCreator &mixfile)
  47. {
  48. const char wildcardname [] = "*.*";
  49. unsigned filecount;
  50. StringClass findfilepathname;
  51. WIN32_FIND_DATA finddata;
  52. HANDLE handle;
  53. filecount = 0;
  54. if (basepath.Get_Length() > 0) {
  55. findfilepathname = basepath;
  56. findfilepathname += "\\";
  57. }
  58. if (subpath.Get_Length() > 0) {
  59. findfilepathname += subpath;
  60. findfilepathname += "\\";
  61. }
  62. findfilepathname += wildcardname;
  63. handle = FindFirstFile (findfilepathname, &finddata);
  64. if (handle != INVALID_HANDLE_VALUE) {
  65. bool done;
  66. done = false;
  67. while (!done) {
  68. // Filter out system files.
  69. if (finddata.cFileName [0] != '.') {
  70. StringClass subpathname;
  71. if (subpath.Get_Length() > 0) {
  72. subpathname += subpath;
  73. subpathname += "\\";
  74. }
  75. subpathname += finddata.cFileName;
  76. // Is it a subdirectory?
  77. if ((finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  78. // Recurse on subdirectory.
  79. filecount += Add_Files (basepath, subpathname, mixfile);
  80. } else {
  81. StringClass fullpathname;
  82. if (basepath.Get_Length() > 0) {
  83. fullpathname += basepath;
  84. fullpathname += "\\";
  85. }
  86. if (subpath.Get_Length() > 0) {
  87. fullpathname += subpath;
  88. fullpathname += "\\";
  89. }
  90. fullpathname += finddata.cFileName;
  91. mixfile.Add_File (fullpathname, subpathname);
  92. filecount++;
  93. }
  94. }
  95. done = !FindNextFile (handle, &finddata);
  96. }
  97. }
  98. return (filecount);
  99. }