dlgserversaveload.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/dlgserversaveload.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/25/02 4:29p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgserversaveload.h"
  36. #include "resource.h"
  37. #include "listctrl.h"
  38. #include "dialogresource.h"
  39. #include "inputconfigmgr.h"
  40. #include "string_ids.h"
  41. #include "rawfile.h"
  42. #include "ini.h"
  43. #include "gamedata.h"
  44. #include "assets.h"
  45. #include "dlgmplanhostoptions.h"
  46. #include "renegadedialogmgr.h"
  47. #include "dlgmpslaveservers.h"
  48. DynamicVectorClass<ServerSettingsClass*> ServerSettingsManagerClass::ServerSettingsList;
  49. bool ServerSaveLoadMenuClass::FromSlaveConfig = false;
  50. const char *DEFAULT_SERVER_SETTINGS_FILE_NAME = "svrcfg_cnc_%04d.ini";
  51. ////////////////////////////////////////////////////////////////
  52. //
  53. // ServerSaveLoadMenuClass
  54. //
  55. ////////////////////////////////////////////////////////////////
  56. ServerSaveLoadMenuClass::ServerSaveLoadMenuClass (void) :
  57. MenuDialogClass (IDD_MENU_SERVER_SETTINGS_SAVELOAD)
  58. {
  59. }
  60. ////////////////////////////////////////////////////////////////
  61. //
  62. // On_Init_Dialog
  63. //
  64. ////////////////////////////////////////////////////////////////
  65. void
  66. ServerSaveLoadMenuClass::On_Init_Dialog (void)
  67. {
  68. if (FromSlaveConfig) {
  69. Get_Dlg_Item(IDC_DELETE_BUTTON)->Enable(false);
  70. Get_Dlg_Item(IDC_SAVE_BUTTON)->Enable(false);
  71. } else {
  72. Get_Dlg_Item(IDC_DELETE_BUTTON)->Enable(true);
  73. Get_Dlg_Item(IDC_SAVE_BUTTON)->Enable(true);
  74. }
  75. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  76. if (list_ctrl != NULL) {
  77. //
  78. // Configure the column
  79. //
  80. list_ctrl->Add_Column (L"", 1.0F, Vector3 (1, 1, 1));
  81. //
  82. // Loop over all the configurations
  83. //
  84. ServerSettingsManagerClass::Scan();
  85. int count = ServerSettingsManagerClass::Get_Num_Settings_Files();
  86. for (int index = 0; index < count; index ++) {
  87. //
  88. // Get information about this configuration
  89. //
  90. ServerSettingsClass *config = ServerSettingsManagerClass::Get_Settings(index);
  91. Insert_Configuration (config);
  92. }
  93. //
  94. // Add an entry so the user can add new configurations
  95. //
  96. int item_index = list_ctrl->Insert_Entry (index, TRANSLATE(IDS_MENU_EMPTY_SLOT));
  97. list_ctrl->Set_Curr_Sel (item_index);
  98. //
  99. // Sort the entries
  100. //
  101. list_ctrl->Sort (ListSortCallback, 0);
  102. }
  103. MenuDialogClass::On_Init_Dialog ();
  104. }
  105. ////////////////////////////////////////////////////////////////
  106. //
  107. // On_Command
  108. //
  109. ////////////////////////////////////////////////////////////////
  110. void
  111. ServerSaveLoadMenuClass::On_Command (int ctrl_id, int message_id, DWORD param)
  112. {
  113. switch (ctrl_id)
  114. {
  115. case IDC_DELETE_BUTTON:
  116. Delete_Config ();
  117. break;
  118. case IDC_SAVE_BUTTON:
  119. Save_Config (true);
  120. break;
  121. case IDC_LOAD_BUTTON:
  122. Load_Config ();
  123. break;
  124. case IDC_MENU_BACK_BUTTON:
  125. Next_Dialog();
  126. break;
  127. }
  128. MenuDialogClass::On_Command (ctrl_id, message_id, param);
  129. }
  130. void ServerSaveLoadMenuClass::Next_Dialog(void)
  131. {
  132. if (FromSlaveConfig) {
  133. } else {
  134. START_DIALOG(MPLanHostOptionsMenuClass);
  135. }
  136. }
  137. ////////////////////////////////////////////////////////////////
  138. //
  139. // Delete_Config
  140. //
  141. ////////////////////////////////////////////////////////////////
  142. void
  143. ServerSaveLoadMenuClass::Delete_Config (void)
  144. {
  145. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  146. if (list_ctrl == NULL) {
  147. return ;
  148. }
  149. //
  150. // Get the current selection
  151. //
  152. int curr_sel = list_ctrl->Get_Curr_Sel ();
  153. if (curr_sel != -1) {
  154. //
  155. // Get the configuration object associated with this entry
  156. //
  157. ServerSettingsClass *config = (ServerSettingsClass *)list_ctrl->Get_Entry_Data (curr_sel, 0);
  158. if (config != NULL) {
  159. //
  160. // Delete the configuration (if possible)
  161. //
  162. if (config->IsCustom && !config->Is_Default_Custom()) {
  163. ServerSettingsManagerClass::Delete_Configuration(config);
  164. list_ctrl->Delete_Entry(curr_sel);
  165. list_ctrl->Sort (ListSortCallback, 0);
  166. }
  167. }
  168. }
  169. }
  170. ////////////////////////////////////////////////////////////////
  171. //
  172. // Load_Config
  173. //
  174. ////////////////////////////////////////////////////////////////
  175. void
  176. ServerSaveLoadMenuClass::Load_Config (void)
  177. {
  178. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  179. if (list_ctrl == NULL) {
  180. return ;
  181. }
  182. //
  183. // Get the current selection
  184. //
  185. int curr_sel = list_ctrl->Get_Curr_Sel ();
  186. if (curr_sel != -1) {
  187. //
  188. // Get the configuration object associated with this entry
  189. //
  190. ServerSettingsClass *config = (ServerSettingsClass *)list_ctrl->Get_Entry_Data(curr_sel, 0);
  191. if (config != NULL) {
  192. if (FromSlaveConfig) {
  193. //
  194. // Inform the slave settings dialog of the choice.
  195. //
  196. SlaveServerDialogClass::Set_Slave_Settings(&config->RawFileName);
  197. } else {
  198. //
  199. // Load this configuration
  200. //
  201. ServerSettingsManagerClass::Load_Settings(config);
  202. }
  203. End_Dialog ();
  204. Next_Dialog();
  205. }
  206. }
  207. }
  208. ////////////////////////////////////////////////////////////////
  209. //
  210. // Save_Config
  211. //
  212. ////////////////////////////////////////////////////////////////
  213. void
  214. ServerSaveLoadMenuClass::Save_Config (bool prompt)
  215. {
  216. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  217. if (list_ctrl == NULL) {
  218. return ;
  219. }
  220. //
  221. // Get the current selection
  222. //
  223. int curr_sel = list_ctrl->Get_Curr_Sel();
  224. if (curr_sel != -1) {
  225. //
  226. // Get the configuration object associated with this entry
  227. //
  228. ServerSettingsClass *config = (ServerSettingsClass *)list_ctrl->Get_Entry_Data(curr_sel, 0);
  229. if (config != NULL) {
  230. //
  231. // We can only save custom configurations...
  232. //
  233. if (config->IsCustom) {
  234. WideStringClass outMsg;
  235. if (The_Game()->Is_Valid_Settings(outMsg, true)) {
  236. //
  237. // Get the new display name for this configuration
  238. //
  239. const WCHAR *display_name = Get_Dlg_Item_Text (IDC_NAME_EDIT);
  240. if (display_name[0] != 0) {
  241. //
  242. // Display a message to the user asking if they really want to do this...
  243. //
  244. if (prompt) {
  245. DlgMsgBox::DoDialog (IDS_MENU_CONTROLS_OVERWRITE_PROMPT_TITLE, IDS_MENU_CONTROLS_OVERWRITE_PROMPT_MSG, DlgMsgBox::YesNo, this);
  246. } else {
  247. //
  248. // Just save it.
  249. //
  250. Save_Now();
  251. }
  252. } else {
  253. //
  254. // Let the user know they can't save a configuration without a name
  255. //
  256. DlgMsgBox::DoDialog(IDS_MENU_CANT_SAVE_CONFIG, IDS_MENU_CONFIG_NEEDS_NAME, DlgMsgBox::Okay, NULL, 0);
  257. }
  258. } else {
  259. #if(0) // Denzil
  260. //
  261. // Let the user know the settings are not correct
  262. //
  263. RenegadeDialogMgrClass::Do_Simple_Dialog(IDD_MP_INVALID_SERVER_CONFIG);
  264. #else
  265. WideStringClass errorMsg(0, true);
  266. errorMsg.Format(L"%s\n\n%s", TRANSLATE(IDS_MENU_TEXT330), (const WCHAR*)outMsg);
  267. DlgMsgBox::DoDialog(TRANSLATE(IDS_MENU_TEXT329), errorMsg);
  268. #endif
  269. }
  270. }
  271. } else {
  272. //
  273. // Get the new display name for this configuration
  274. //
  275. const WCHAR *display_name = Get_Dlg_Item_Text (IDC_NAME_EDIT);
  276. if (display_name[0] != 0) {
  277. //
  278. // Add a new configuration
  279. //
  280. WideStringClass name(display_name, true);
  281. config = ServerSettingsManagerClass::Add_Configuration(&name);
  282. if (config != NULL) {
  283. Insert_Configuration(config);
  284. ServerSettingsManagerClass::Save_Configuration(config);
  285. list_ctrl->Sort (ListSortCallback, 0);
  286. }
  287. } else {
  288. //
  289. // Let the user know they can't save a configuration without a name
  290. //
  291. DlgMsgBox::DoDialog (IDS_MENU_CANT_SAVE_CONFIG, IDS_MENU_CONFIG_NEEDS_NAME, DlgMsgBox::Okay, NULL, 0);
  292. }
  293. }
  294. }
  295. }
  296. ////////////////////////////////////////////////////////////////
  297. //
  298. // On_ListCtrl_Delete_Entry
  299. //
  300. ////////////////////////////////////////////////////////////////
  301. void
  302. ServerSaveLoadMenuClass::On_ListCtrl_Delete_Entry
  303. (
  304. ListCtrlClass *list_ctrl,
  305. int ctrl_id,
  306. int item_index
  307. )
  308. {
  309. //
  310. // Remove the data we associated with this entry
  311. //
  312. ServerSettingsClass *config = (ServerSettingsClass *)list_ctrl->Get_Entry_Data (item_index, 0);
  313. list_ctrl->Set_Entry_Data (item_index, 0, NULL);
  314. //
  315. // Free the config object
  316. //
  317. if (config != NULL) {
  318. delete config;
  319. }
  320. return ;
  321. }
  322. ////////////////////////////////////////////////////////////////
  323. //
  324. // Insert_Configuration
  325. //
  326. ////////////////////////////////////////////////////////////////
  327. int
  328. ServerSaveLoadMenuClass::Insert_Configuration (ServerSettingsClass *config)
  329. {
  330. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  331. if (list_ctrl == NULL) {
  332. return -1;
  333. }
  334. //
  335. // Add an entry for this configuration to the list
  336. //
  337. int item_index = list_ctrl->Insert_Entry (0xFFFF, config->ConfigName);
  338. if (item_index != -1) {
  339. //
  340. // Make a copy of the config object and store it with the entry
  341. //
  342. ServerSettingsClass *local_copy = new ServerSettingsClass(config);
  343. list_ctrl->Set_Entry_Data (item_index, 0, (DWORD)local_copy);
  344. //
  345. // Change the color of this configuration if the user cannot edit it
  346. //
  347. if (!config->IsCustom) {
  348. list_ctrl->Set_Entry_Color (item_index, 0, Vector3 (1.0F, 1.0F, 1.0F));
  349. }
  350. }
  351. return item_index;
  352. }
  353. ////////////////////////////////////////////////////////////////
  354. //
  355. // On_ListCtrl_Sel_Change
  356. //
  357. ////////////////////////////////////////////////////////////////
  358. void
  359. ServerSaveLoadMenuClass::On_ListCtrl_Sel_Change
  360. (
  361. ListCtrlClass * list_ctrl,
  362. int ctrl_id,
  363. int old_index,
  364. int new_index
  365. )
  366. {
  367. bool enable_edit = true;
  368. //
  369. // Remove the data we associated with this entry
  370. //
  371. ServerSettingsClass *config = (ServerSettingsClass *)list_ctrl->Get_Entry_Data(new_index, 0);
  372. if (config != NULL) {
  373. //
  374. // We want to disable the edit control if the user can't edit this entry
  375. //
  376. if (!config->IsCustom || config->Is_Default_Custom()) {
  377. enable_edit = false;
  378. }
  379. //
  380. // Put the name of the currently selected configuration in the control
  381. //
  382. Set_Dlg_Item_Text (IDC_NAME_EDIT, config->ConfigName);
  383. } else {
  384. //
  385. // Clear the name of the current configuration
  386. //
  387. Set_Dlg_Item_Text (IDC_NAME_EDIT, L"");
  388. }
  389. //
  390. // Fix the enable state of the edit control
  391. //
  392. Enable_Dlg_Item (IDC_NAME_EDIT, enable_edit);
  393. return ;
  394. }
  395. ////////////////////////////////////////////////////////////////
  396. //
  397. // ListSortCallback
  398. //
  399. ////////////////////////////////////////////////////////////////
  400. int CALLBACK
  401. ServerSaveLoadMenuClass::ListSortCallback
  402. (
  403. ListCtrlClass * list_ctrl,
  404. int item_index1,
  405. int item_index2,
  406. uint32 user_param
  407. )
  408. {
  409. ServerSettingsClass *config1 = (ServerSettingsClass *)list_ctrl->Get_Entry_Data (item_index1, 0);
  410. ServerSettingsClass *config2 = (ServerSettingsClass *)list_ctrl->Get_Entry_Data (item_index2, 0);
  411. if (config1 == NULL) {
  412. return(1);
  413. } else if (config2 == NULL) {
  414. return(-1);
  415. } else {
  416. //
  417. // Sort based on the type of configuration
  418. //
  419. if (!config1->IsCustom && config2->IsCustom) {
  420. return(-1);
  421. }
  422. if (config1->IsCustom && !config2->IsCustom) {
  423. return(1);
  424. }
  425. if (config1->Is_Default_Custom() && !config2->Is_Default_Custom()) {
  426. return(-1);
  427. }
  428. if (!config1->Is_Default_Custom() && config2->Is_Default_Custom()) {
  429. return(1);
  430. }
  431. }
  432. return(wcsicmp(config1->ConfigName, config2->ConfigName));
  433. }
  434. ////////////////////////////////////////////////////////////////
  435. //
  436. // On_EditCtrl_Enter_Pressed
  437. //
  438. ////////////////////////////////////////////////////////////////
  439. void
  440. ServerSaveLoadMenuClass::On_EditCtrl_Enter_Pressed (EditCtrlClass *edit_ctrl, int ctrl_id)
  441. {
  442. if (ctrl_id == IDC_NAME_EDIT) {
  443. Save_Config (true);
  444. }
  445. return ;
  446. }
  447. ////////////////////////////////////////////////////////////////
  448. //
  449. // HandleNotification
  450. //
  451. ////////////////////////////////////////////////////////////////
  452. void
  453. ServerSaveLoadMenuClass::HandleNotification (DlgMsgBoxEvent &event)
  454. {
  455. //
  456. // The user has confirmed the overwrite, so save the configuration
  457. //
  458. if (event.Event () == DlgMsgBoxEvent::Yes) {
  459. Save_Now();
  460. }
  461. }
  462. ////////////////////////////////////////////////////////////////
  463. //
  464. // Save_Now
  465. //
  466. ////////////////////////////////////////////////////////////////
  467. void ServerSaveLoadMenuClass::Save_Now(void)
  468. {
  469. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  470. if (list_ctrl == NULL) {
  471. return ;
  472. }
  473. //
  474. // Get the current selection
  475. //
  476. int curr_sel = list_ctrl->Get_Curr_Sel();
  477. if (curr_sel != -1) {
  478. //
  479. // Get the configuration object associated with this entry
  480. //
  481. ServerSettingsClass *config = (ServerSettingsClass *)list_ctrl->Get_Entry_Data(curr_sel, 0);
  482. if (config != NULL) {
  483. //
  484. // We can only save custom configurations...
  485. //
  486. if (config->IsCustom) {
  487. WideStringClass outMsg;
  488. if (The_Game()->Is_Valid_Settings(outMsg, true)) {
  489. //
  490. // Get the new display name for this configuration
  491. //
  492. const WCHAR *display_name = Get_Dlg_Item_Text (IDC_NAME_EDIT);
  493. if (display_name[0] != 0) {
  494. //
  495. // Update the name of this configuration
  496. //
  497. config->ConfigName = display_name;
  498. list_ctrl->Set_Entry_Text (curr_sel, 0, display_name);
  499. //
  500. // Save the configuration
  501. //
  502. ServerSettingsManagerClass::Save_Configuration(config);
  503. End_Dialog ();
  504. Next_Dialog();
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. /***********************************************************************************************
  512. * ServerSettingsClass::ServerSettingsClass -- Class constructor *
  513. * *
  514. * *
  515. * *
  516. * INPUT: File name of config file *
  517. * Name of config file *
  518. * File number *
  519. * *
  520. * *
  521. * OUTPUT: Nothing *
  522. * *
  523. * WARNINGS: None *
  524. * *
  525. * HISTORY: *
  526. * 12/17/2001 5:11PM ST : Created *
  527. *=============================================================================================*/
  528. ServerSettingsClass::ServerSettingsClass(char *filename, unsigned short *configname, int file_number)
  529. {
  530. ConfigName = configname; //"Default C&C Server Settings";
  531. RawFileName = filename; //"svrcfg_cnc.ini"
  532. FileNumber = file_number;
  533. IsCustom = true;
  534. }
  535. /***********************************************************************************************
  536. * ServerSettingsClass::ServerSettingsClass -- Class copy constructor *
  537. * *
  538. * *
  539. * *
  540. * INPUT: Other class *
  541. * *
  542. * OUTPUT: Nothing *
  543. * *
  544. * WARNINGS: None *
  545. * *
  546. * HISTORY: *
  547. * 12/17/2001 5:11PM ST : Created *
  548. *=============================================================================================*/
  549. ServerSettingsClass::ServerSettingsClass(ServerSettingsClass *other)
  550. {
  551. ConfigName = other->ConfigName;
  552. RawFileName = other->RawFileName;
  553. FileNumber = other->FileNumber;
  554. IsCustom = other->IsCustom;
  555. }
  556. /***********************************************************************************************
  557. * ServerSettingsManagerClass::Get_Settings -- Get settings by index *
  558. * *
  559. * *
  560. * *
  561. * INPUT: Index *
  562. * *
  563. * OUTPUT: Settings *
  564. * *
  565. * WARNINGS: None *
  566. * *
  567. * HISTORY: *
  568. * 12/17/2001 5:12PM ST : Created *
  569. *=============================================================================================*/
  570. ServerSettingsClass *ServerSettingsManagerClass::Get_Settings(int index)
  571. {
  572. WWASSERT(index >= 0 && index < ServerSettingsList.Count());
  573. return(ServerSettingsList[index]);
  574. }
  575. /***********************************************************************************************
  576. * ServerSettingsManagerClass::Scan -- Scan for server settings files on the disk *
  577. * *
  578. * *
  579. * *
  580. * INPUT: Nothing *
  581. * *
  582. * OUTPUT: Nothing *
  583. * *
  584. * WARNINGS: None *
  585. * *
  586. * HISTORY: *
  587. * 12/17/2001 5:13PM ST : Created *
  588. *=============================================================================================*/
  589. void ServerSettingsManagerClass::Scan(void)
  590. {
  591. char file_name[MAX_PATH];
  592. char whole_file_name[MAX_PATH];
  593. //char description[256];
  594. WideStringClass description(128, true);
  595. StringClass char_description(128, true);
  596. /*
  597. ** Clear out old configs.
  598. */
  599. Clear_Settings_List();
  600. /*
  601. ** Add in the default as the first entry.
  602. */
  603. ServerSettingsList.Add(new ServerSettingsClass("def_svrcfg_cnc.ini", (unsigned short *)TRANSLATE(IDS_SERVER_SAVELOAD_DEFAULT), 0));
  604. ServerSettingsList[0]->IsCustom = false;
  605. /*
  606. ** Add in the custom default as the second entry.
  607. */
  608. ServerSettingsList.Add(new ServerSettingsClass("svrcfg_cnc.ini", (unsigned short *)TRANSLATE(IDS_SERVER_SAVELOAD_CUSTOM_DEFAULT), 1));
  609. ServerSettingsList[1]->IsCustom = true;
  610. for (int i=2 ; i<MAX_SETTINGS_FILES ; i++) {
  611. sprintf(file_name, DEFAULT_SERVER_SETTINGS_FILE_NAME, i);
  612. sprintf(whole_file_name, "data\\%s", file_name);
  613. RawFileClass file(whole_file_name);
  614. if (file.Is_Available()) {
  615. INIClass *ini = Get_INI(file_name);
  616. if (ini) {
  617. description = ini->Get_Wide_String(description, "Settings", "wConfigName", L""); //(unsigned short *)TRANSLATE(IDS_SERVER_SAVELOAD_DEFAULT));
  618. if (description.Get_Length()) {
  619. ServerSettingsList.Add(new ServerSettingsClass(file_name, description.Peek_Buffer(), i));
  620. } else {
  621. StringClass defaultstr((unsigned short *)TRANSLATE(IDS_SERVER_SAVELOAD_DEFAULT), true);
  622. ini->Get_String("Settings", "bConfigName", defaultstr.Peek_Buffer(), char_description.Peek_Buffer(), 128);
  623. ServerSettingsList.Add(new ServerSettingsClass(file_name, WideStringClass(char_description, true).Peek_Buffer(), i));
  624. }
  625. }
  626. }
  627. }
  628. }
  629. /***********************************************************************************************
  630. * ServerSettingsManagerClass::Clear_Settings_List -- Reset the settings list *
  631. * *
  632. * *
  633. * *
  634. * INPUT: Nothing *
  635. * *
  636. * OUTPUT: Nothing *
  637. * *
  638. * WARNINGS: None *
  639. * *
  640. * HISTORY: *
  641. * 12/17/2001 5:13PM ST : Created *
  642. *=============================================================================================*/
  643. void ServerSettingsManagerClass::Clear_Settings_List(void)
  644. {
  645. for (int i=0 ; i<ServerSettingsList.Count() ; i++) {
  646. delete ServerSettingsList[i];
  647. }
  648. ServerSettingsList.Reset_Active();
  649. }
  650. /***********************************************************************************************
  651. * ServerSettingsManagerClass::Load_Settings -- Load settings into the game *
  652. * *
  653. * *
  654. * *
  655. * INPUT: Settings *
  656. * *
  657. * OUTPUT: Nothing *
  658. * *
  659. * WARNINGS: None *
  660. * *
  661. * HISTORY: *
  662. * 12/17/2001 5:14PM ST : Created *
  663. *=============================================================================================*/
  664. void ServerSettingsManagerClass::Load_Settings(ServerSettingsClass *settings)
  665. {
  666. WWASSERT(settings != NULL);
  667. WWASSERT(The_Game() != NULL);
  668. if (settings && The_Game()) {
  669. char filename[MAX_PATH];
  670. sprintf(filename, "data\\%s", settings->RawFileName);
  671. RawFileClass file(filename);
  672. if (file.Is_Available()) {
  673. The_Game()->Set_Ini_Filename(settings->RawFileName);
  674. The_Game()->Load_From_Server_Config();
  675. settings->ConfigName = The_Game()->Get_Settings_Description();
  676. }
  677. }
  678. }
  679. /***********************************************************************************************
  680. * ServerSettingsManagerClass::Delete_Configuration -- Delete a settings file from disk *
  681. * *
  682. * *
  683. * *
  684. * INPUT: Settings *
  685. * *
  686. * OUTPUT: Nothing *
  687. * *
  688. * WARNINGS: None *
  689. * *
  690. * HISTORY: *
  691. * 12/17/2001 5:14PM ST : Created *
  692. *=============================================================================================*/
  693. void ServerSettingsManagerClass::Delete_Configuration(ServerSettingsClass *settings)
  694. {
  695. if (!settings->Is_Default()) {
  696. char filename[MAX_PATH];
  697. sprintf(filename, "data\\%s", settings->RawFileName);
  698. DeleteFile(filename);
  699. for (int i=0 ; i<ServerSettingsList.Count() ; i++) {
  700. if (strcmp(settings->RawFileName, ServerSettingsList[i]->RawFileName) == 0) {
  701. delete ServerSettingsList[i];
  702. ServerSettingsList.Delete(i);
  703. break;
  704. }
  705. }
  706. }
  707. }
  708. /***********************************************************************************************
  709. * ServerSettingsManagerClass::Save_Configuration -- Save settings from the game *
  710. * *
  711. * *
  712. * *
  713. * INPUT: Settings *
  714. * *
  715. * OUTPUT: Nothing *
  716. * *
  717. * WARNINGS: None *
  718. * *
  719. * HISTORY: *
  720. * 12/17/2001 5:14PM ST : Created *
  721. *=============================================================================================*/
  722. void ServerSettingsManagerClass::Save_Configuration(ServerSettingsClass *settings)
  723. {
  724. WWASSERT(settings != NULL);
  725. WWASSERT(The_Game() != NULL);
  726. if (settings && The_Game()) {
  727. char filename[MAX_PATH];
  728. sprintf(filename, "data\\%s", settings->RawFileName);
  729. RawFileClass file(filename);
  730. if (!file.Is_Available()) {
  731. file.Create();
  732. WWASSERT(file.Is_Available());
  733. }
  734. if (file.Is_Available()) {
  735. //StringClass string(128, true);
  736. //settings->ConfigName.Convert_To(string);
  737. The_Game()->Set_Settings_Description(settings->ConfigName);
  738. The_Game()->Set_Ini_Filename(settings->RawFileName);
  739. The_Game()->Save_To_Server_Config();
  740. }
  741. }
  742. }
  743. /***********************************************************************************************
  744. * ServerSettingsManagerClass::Add_Configuration -- Create a new settings file entry *
  745. * *
  746. * *
  747. * *
  748. * INPUT: Settings name *
  749. * *
  750. * OUTPUT: Nothing *
  751. * *
  752. * WARNINGS: None *
  753. * *
  754. * HISTORY: *
  755. * 12/17/2001 5:15PM ST : Created *
  756. *=============================================================================================*/
  757. ServerSettingsClass *ServerSettingsManagerClass::Add_Configuration(WideStringClass *display_name)
  758. {
  759. WWASSERT(display_name != NULL);
  760. WWASSERT(The_Game());
  761. if (display_name != NULL) {
  762. if (The_Game()) {
  763. /*
  764. ** Find an unused filename.
  765. */
  766. char population[MAX_SETTINGS_FILES];
  767. memset(population, 0, sizeof(population));
  768. char filename[MAX_PATH];
  769. int file_number = -1;
  770. for (int i=0 ; i<ServerSettingsList.Count() ; i++) {
  771. ServerSettingsClass *settings = ServerSettingsList[i];
  772. if (settings) {
  773. WWASSERT(settings->FileNumber >= 0);
  774. WWASSERT(settings->FileNumber < MAX_SETTINGS_FILES);
  775. population[settings->FileNumber] = 1;
  776. }
  777. }
  778. for (i=0 ; i<MAX_SETTINGS_FILES ; i++) {
  779. if (population[i] == 0) {
  780. sprintf(filename, DEFAULT_SERVER_SETTINGS_FILE_NAME, i);
  781. file_number = i;
  782. break;
  783. }
  784. }
  785. if (file_number != -1) {
  786. ServerSettingsClass *new_settings = new ServerSettingsClass(filename, display_name->Peek_Buffer(), file_number);
  787. ServerSettingsList.Add(new_settings);
  788. return(new_settings);
  789. }
  790. }
  791. }
  792. return(NULL);
  793. }