NewAssetPackageDialog.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. // NewAssetPackageDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "newassetpackagedialog.h"
  23. #include "assetpackagemgr.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. //
  31. // NewAssetPackageDialogClass
  32. //
  33. /////////////////////////////////////////////////////////////////////////////
  34. NewAssetPackageDialogClass::NewAssetPackageDialogClass(CWnd* pParent /*=NULL*/)
  35. : CDialog(NewAssetPackageDialogClass::IDD, pParent)
  36. {
  37. //{{AFX_DATA_INIT(NewAssetPackageDialogClass)
  38. // NOTE: the ClassWizard will add member initialization here
  39. //}}AFX_DATA_INIT
  40. return ;
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. //
  44. // DoDataExchange
  45. //
  46. /////////////////////////////////////////////////////////////////////////////
  47. void
  48. NewAssetPackageDialogClass::DoDataExchange (CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(NewAssetPackageDialogClass)
  52. // NOTE: the ClassWizard will add DDX and DDV calls here
  53. //}}AFX_DATA_MAP
  54. return ;
  55. }
  56. BEGIN_MESSAGE_MAP(NewAssetPackageDialogClass, CDialog)
  57. //{{AFX_MSG_MAP(NewAssetPackageDialogClass)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. //
  62. // OnInitDialog
  63. //
  64. /////////////////////////////////////////////////////////////////////////////
  65. BOOL
  66. NewAssetPackageDialogClass::OnInitDialog (void)
  67. {
  68. CDialog::OnInitDialog ();
  69. return TRUE;
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. //
  73. // OnOK
  74. //
  75. /////////////////////////////////////////////////////////////////////////////
  76. void
  77. NewAssetPackageDialogClass::OnOK (void)
  78. {
  79. CString text;
  80. GetDlgItemText (IDC_PACKAGE_NAME_EDIT, text);
  81. //
  82. // Check to ensure this name is valid
  83. //
  84. if (Is_Valid_Name (text) == false) {
  85. MessageBox ("Names must be at least one character long and cannot contain any of the following: \\ / \" * ? < > |", "Invalid Name", MB_ICONERROR | MB_OK);
  86. SendDlgItemMessage (IDC_PACKAGE_NAME_EDIT, EM_SETSEL, 0, -1);
  87. GetDlgItem (IDC_PACKAGE_NAME_EDIT)->SetFocus ();
  88. } else if (Is_Duplicate_Name (text)) {
  89. MessageBox ("Name is already in use, please choose another name.", "Invalid Name", MB_ICONERROR | MB_OK);
  90. SendDlgItemMessage (IDC_PACKAGE_NAME_EDIT, EM_SETSEL, 0, -1);
  91. GetDlgItem (IDC_PACKAGE_NAME_EDIT)->SetFocus ();
  92. } else {
  93. PackageName = text;
  94. CDialog::OnOK ();
  95. }
  96. return ;
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. //
  100. // Is_Valid_Name
  101. //
  102. /////////////////////////////////////////////////////////////////////////////
  103. bool
  104. NewAssetPackageDialogClass::Is_Valid_Name (const CString &name)
  105. {
  106. bool retval = false;
  107. //
  108. // Check to see if the string is long enough and that it doesn't contain
  109. // any illegal characters
  110. //
  111. if (name.GetLength () > 0) {
  112. retval = (name.FindOneOf ("\\/\"*?<>|") == -1);
  113. }
  114. return retval;
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. //
  118. // Is_Duplicate_Name
  119. //
  120. /////////////////////////////////////////////////////////////////////////////
  121. bool
  122. NewAssetPackageDialogClass::Is_Duplicate_Name (const CString &name)
  123. {
  124. bool retval = false;
  125. //
  126. // Build a list of all the packages that are currently available
  127. //
  128. STRING_LIST package_list;
  129. AssetPackageMgrClass::Build_Package_List (package_list);
  130. //
  131. // Check to see if the new name is already being used
  132. //
  133. for (int index = 0; index < package_list.Count (); index ++) {
  134. if (name.CompareNoCase (package_list[index]) == 0) {
  135. retval = true;
  136. break;
  137. }
  138. }
  139. return retval;
  140. }