FilePicker.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // FilePickerClass.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "filepicker.h"
  23. #include "utils.h"
  24. #include "filemgr.h"
  25. ///////////////////////////////////////////////////////////
  26. //
  27. // FilePickerClass
  28. //
  29. ///////////////////////////////////////////////////////////
  30. FilePickerClass::FilePickerClass (void)
  31. : m_AssetTreeOnly (true),
  32. PickerClass ()
  33. {
  34. m_ExtensionString = "*.*";
  35. m_FilterString = "All Files (*.*)|*.*||";
  36. return ;
  37. }
  38. ///////////////////////////////////////////////////////////
  39. //
  40. // ~FilePickerClass
  41. //
  42. ///////////////////////////////////////////////////////////
  43. FilePickerClass::~FilePickerClass (void)
  44. {
  45. return ;
  46. }
  47. ///////////////////////////////////////////////////////////
  48. //
  49. // On_Pick
  50. //
  51. ///////////////////////////////////////////////////////////
  52. void
  53. FilePickerClass::On_Pick (void)
  54. {
  55. CString window_text;
  56. GetWindowText (window_text);
  57. CString full_path = ::Get_File_Mgr ()->Make_Full_Path (window_text);
  58. CString filename = ::Get_Filename_From_Path (full_path);
  59. CString path;
  60. DWORD attribs = ::GetFileAttributes (full_path);
  61. if ((attribs != 0xFFFFFFFF) && !(attribs & FILE_ATTRIBUTE_DIRECTORY)) {
  62. path = ::Strip_Filename_From_Path (full_path);
  63. } else if ((attribs == 0xFFFFFFFF) && (::strchr (filename, '*') != NULL)) {
  64. path = ::Strip_Filename_From_Path (full_path);
  65. } else if ((attribs == 0xFFFFFFFF) && m_AssetTreeOnly) {
  66. path = ::Get_File_Mgr ()->Get_Base_Path ();
  67. } else {
  68. path = full_path;
  69. }
  70. CFileDialog dialog (TRUE,
  71. m_ExtensionString,
  72. filename,
  73. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  74. m_FilterString,
  75. this);
  76. //
  77. // Set the path, so it opens in the correct directory
  78. //
  79. if (path.GetLength () > 0) {
  80. dialog.m_ofn.lpstrInitialDir = path;
  81. }
  82. //
  83. // Show the dialog to the user
  84. //
  85. if (dialog.DoModal () == IDOK) {
  86. path = dialog.GetPathName ();
  87. if (::Get_File_Mgr ()->Is_Empty_Path (path) == false)
  88. {
  89. if (m_AssetTreeOnly == false || ::Get_File_Mgr ()->Is_Path_Valid (path)) {
  90. CString rel_path = ::Get_File_Mgr ()->Make_Relative_Path (dialog.GetPathName ());
  91. SetWindowText (rel_path);
  92. }
  93. }
  94. }
  95. PickerClass::On_Pick ();
  96. return ;
  97. }