MakeMixFileDialog.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. // MakeMixFileDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "mixviewer.h"
  22. #include "MakeMixFileDialog.h"
  23. #include "wwstring.h"
  24. #include "MainFrm.h"
  25. #include "mixfile.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // MakeMixFileDialogClass dialog
  33. MakeMixFileDialogClass::MakeMixFileDialogClass(CWnd* pParent /*=NULL*/)
  34. : CDialog(MakeMixFileDialogClass::IDD, pParent)
  35. {
  36. //{{AFX_DATA_INIT(MakeMixFileDialogClass)
  37. // NOTE: the ClassWizard will add member initialization here
  38. //}}AFX_DATA_INIT
  39. }
  40. void MakeMixFileDialogClass::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(MakeMixFileDialogClass)
  44. // NOTE: the ClassWizard will add DDX and DDV calls here
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(MakeMixFileDialogClass, CDialog)
  48. //{{AFX_MSG_MAP(MakeMixFileDialogClass)
  49. ON_BN_CLICKED(IDC_BROWSE_FILE, OnBrowseFile)
  50. ON_BN_CLICKED(IDC_BROWSE_DIR, OnBrowseDir)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // MakeMixFileDialogClass message handlers
  55. BOOL MakeMixFileDialogClass::OnInitDialog()
  56. {
  57. CDialog::OnInitDialog();
  58. // TODO: Add extra initialization here
  59. return TRUE; // return TRUE unless you set the focus to a control
  60. // EXCEPTION: OCX Property Pages should return FALSE
  61. }
  62. /*
  63. **
  64. */
  65. unsigned MakeMixFileDialogClass::Add_Files (const StringClass &basepath, const StringClass &subpath, MixFileCreator &mixfile)
  66. {
  67. const char wildcardname [] = "*.*";
  68. unsigned filecount;
  69. StringClass findfilepathname;
  70. WIN32_FIND_DATA finddata;
  71. HANDLE handle;
  72. filecount = 0;
  73. if (basepath.Get_Length() > 0) {
  74. findfilepathname = basepath;
  75. findfilepathname += "\\";
  76. }
  77. if (subpath.Get_Length() > 0) {
  78. findfilepathname += subpath;
  79. findfilepathname += "\\";
  80. }
  81. findfilepathname += wildcardname;
  82. handle = FindFirstFile (findfilepathname, &finddata);
  83. if (handle != INVALID_HANDLE_VALUE) {
  84. bool done;
  85. done = false;
  86. while (!done) {
  87. // Filter out system files.
  88. if (finddata.cFileName [0] != '.') {
  89. StringClass subpathname;
  90. if (subpath.Get_Length() > 0) {
  91. subpathname += subpath;
  92. subpathname += "\\";
  93. }
  94. subpathname += finddata.cFileName;
  95. // Is it a subdirectory?
  96. if ((finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  97. // Recurse on subdirectory.
  98. filecount += Add_Files (basepath, subpathname, mixfile);
  99. } else {
  100. StringClass fullpathname;
  101. if (basepath.Get_Length() > 0) {
  102. fullpathname += basepath;
  103. fullpathname += "\\";
  104. }
  105. if (subpath.Get_Length() > 0) {
  106. fullpathname += subpath;
  107. fullpathname += "\\";
  108. }
  109. fullpathname += finddata.cFileName;
  110. if ( MixFilename != fullpathname ) {
  111. mixfile.Add_File (fullpathname, subpathname);
  112. filecount++;
  113. }
  114. }
  115. }
  116. done = !FindNextFile (handle, &finddata);
  117. }
  118. }
  119. return (filecount);
  120. }
  121. void MakeMixFileDialogClass::OnOK()
  122. {
  123. CString mix_name;
  124. GetDlgItemText( IDC_BROWSE_FILE_NAME, mix_name );
  125. CString dir_name;
  126. GetDlgItemText( IDC_BROWSE_DIR_NAME, dir_name );
  127. if ( mix_name.IsEmpty() ) {
  128. StringClass message;
  129. message.Format ("Invalid Mix File.");
  130. MessageBox (message, "Mix File Error", MB_ICONERROR | MB_OK);
  131. } else if ( dir_name.IsEmpty() ) {
  132. StringClass message;
  133. message.Format ("Invalid Source Directory.");
  134. MessageBox (message, "Mix File Error", MB_ICONERROR | MB_OK);
  135. } else {
  136. MixFilename = mix_name;
  137. MixFileCreator mixfile (mix_name);
  138. StringClass basepath (dir_name);
  139. StringClass subpath;
  140. StringClass message;
  141. int filecount = Add_Files (basepath, subpath, mixfile);
  142. if (filecount > 0) {
  143. message.Format ("%u files added\n", filecount);
  144. } else {
  145. message.Format ("No files found in source directory\n");
  146. }
  147. MessageBox (message, "Mix File Created", MB_OK);
  148. CDialog::OnOK();
  149. }
  150. }
  151. void MakeMixFileDialogClass::OnBrowseFile()
  152. {
  153. CString old_name;
  154. GetDlgItemText( IDC_BROWSE_FILE_NAME, old_name );
  155. CFileDialog dialog ( TRUE,
  156. ".mix",
  157. old_name,
  158. OFN_HIDEREADONLY | OFN_EXPLORER,
  159. "Mix File (*.mix)|*.mix||",
  160. this);
  161. dialog.m_ofn.lpstrTitle = "Pick Mix File to Create";
  162. if (dialog.DoModal () == IDOK) {
  163. SetDlgItemText( IDC_BROWSE_FILE_NAME, dialog.GetPathName () );
  164. }
  165. }
  166. void MakeMixFileDialogClass::OnBrowseDir()
  167. {
  168. CString old_name;
  169. GetDlgItemText( IDC_BROWSE_DIR_NAME, old_name );
  170. CFileDialog dialog ( TRUE,
  171. NULL, //".",
  172. old_name,
  173. OFN_HIDEREADONLY | OFN_EXPLORER,
  174. NULL, //"Mix File (*.mix)|*.mix||",
  175. this);
  176. dialog.m_ofn.lpstrTitle = "Pick A File In the Root Source Directory";
  177. if (dialog.DoModal () == IDOK) {
  178. StringClass filename = dialog.GetPathName ();
  179. StringClass directory = Strip_Filename_From_Path (filename);
  180. SetDlgItemText( IDC_BROWSE_DIR_NAME, directory );
  181. }
  182. }