ProjectSettingsSerialization.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <EditorDefs.h>
  9. #include "ProjectSettingsSerialization.h"
  10. #include "PlatformSettings_common.h"
  11. #include <AzToolsFramework/UI/PropertyEditor/InstanceDataHierarchy.h>
  12. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  13. // Needed to overwrite ios icons and launchscreens
  14. #include <Util/FileUtil.h>
  15. namespace ProjectSettingsTool
  16. {
  17. const char* stringStr = "string";
  18. const char* arrayStr = "array";
  19. const char* trueStr = "true";
  20. const char* noDocumentError = "No json or xml document to use for Project Settings Tool serialization.";
  21. Serializer::Serializer(AzToolsFramework::InstanceDataNode* root)
  22. : m_root(root)
  23. , m_jsonDoc(nullptr)
  24. , m_jsonRoot(nullptr)
  25. , m_idString(AZ::SerializeTypeInfo<AZStd::string>::GetUuid())
  26. , m_idInt(AZ::SerializeTypeInfo<int>::GetUuid())
  27. , m_idBool(AZ::SerializeTypeInfo<bool>::GetUuid())
  28. {}
  29. Serializer::Serializer(AzToolsFramework::InstanceDataNode* root, rapidjson::Document* doc, rapidjson::Value* jsonRoot)
  30. : Serializer(root)
  31. {
  32. SetDocumentRoot(doc);
  33. if (jsonRoot != nullptr)
  34. {
  35. SetJsonRoot(jsonRoot);
  36. }
  37. else
  38. {
  39. SetJsonRoot(doc);
  40. }
  41. }
  42. Serializer::Serializer(AzToolsFramework::InstanceDataNode* root, AZStd::unique_ptr<PlistDictionary> dict)
  43. : Serializer(root)
  44. {
  45. SetDocumentRoot(AZStd::move(dict));
  46. }
  47. void Serializer::SetDocumentRoot(rapidjson::Document* doc)
  48. {
  49. m_jsonDoc = doc;
  50. }
  51. void Serializer::SetJsonRoot(rapidjson::Value* jsonRoot)
  52. {
  53. m_jsonRoot = jsonRoot;
  54. }
  55. void Serializer::SetDocumentRoot(AZStd::unique_ptr<PlistDictionary> dict)
  56. {
  57. m_plistDict = AZStd::move(dict);
  58. }
  59. bool Serializer::UiEqualToSettings() const
  60. {
  61. if (m_jsonRoot != nullptr)
  62. {
  63. return UiEqualToJson(m_jsonRoot);
  64. }
  65. else if (m_plistDict)
  66. {
  67. return UiEqualToPlist(m_root);
  68. }
  69. else
  70. {
  71. AZ_Assert(false, noDocumentError);
  72. return false;
  73. }
  74. }
  75. void Serializer::LoadFromSettings()
  76. {
  77. if (m_jsonRoot != nullptr)
  78. {
  79. LoadFromSettings(m_jsonRoot);
  80. }
  81. else if (m_plistDict)
  82. {
  83. LoadFromSettings(m_root);
  84. }
  85. else
  86. {
  87. AZ_Assert(false, noDocumentError);
  88. }
  89. }
  90. void Serializer::SaveToSettings()
  91. {
  92. if (m_jsonRoot != nullptr)
  93. {
  94. SaveToSettings(m_jsonRoot);
  95. }
  96. else if (m_plistDict)
  97. {
  98. SaveToSettings(m_root);
  99. }
  100. else
  101. {
  102. AZ_Assert(false, noDocumentError);
  103. }
  104. }
  105. bool Serializer::UiEqualToJson(rapidjson::Value* root) const
  106. {
  107. return UiEqualToJson(root, m_root);
  108. }
  109. void Serializer::LoadFromSettings(rapidjson::Value* root)
  110. {
  111. LoadFromSettings(root, m_root);
  112. }
  113. void Serializer::SaveToSettings(rapidjson::Value* root)
  114. {
  115. // This value needs to be an object to add members
  116. if (!root->IsObject())
  117. {
  118. root->SetObject();
  119. }
  120. SaveToSettings(root, m_root);
  121. }
  122. bool Serializer::UiEqualToJson(rapidjson::Value* root, AzToolsFramework::InstanceDataNode* node) const
  123. {
  124. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  125. if (baseMeta)
  126. {
  127. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  128. {
  129. auto childMeta = childNode.GetElementMetadata();
  130. if (childMeta)
  131. {
  132. bool noDocElement = true;
  133. rapidjson::Value::MemberIterator jsonMember;
  134. const char* propertyName = childMeta->m_name;
  135. // If there is a json object try to find the member
  136. if (root != nullptr)
  137. {
  138. jsonMember = root->FindMember(propertyName);
  139. if (jsonMember != root->MemberEnd())
  140. {
  141. noDocElement = false;
  142. }
  143. }
  144. AZ::Uuid type = childMeta->m_typeId;
  145. if (m_idString == type)
  146. {
  147. AZStd::string uiValue;
  148. childNode.Read(uiValue);
  149. if (!uiValue.empty() && !noDocElement)
  150. {
  151. if (jsonMember->value.IsString())
  152. {
  153. if (uiValue != jsonMember->value.GetString())
  154. {
  155. return false;
  156. }
  157. }
  158. else
  159. {
  160. return false;
  161. }
  162. }
  163. else if (uiValue.empty() != noDocElement)
  164. {
  165. return false;
  166. }
  167. }
  168. else if (m_idInt == type)
  169. {
  170. int uiValue;
  171. childNode.Read(uiValue);
  172. if (!noDocElement)
  173. {
  174. if (jsonMember->value.IsInt())
  175. {
  176. if (uiValue != jsonMember->value.GetInt())
  177. {
  178. return false;
  179. }
  180. }
  181. else
  182. {
  183. return false;
  184. }
  185. }
  186. else
  187. {
  188. return false;
  189. }
  190. }
  191. else if (m_idBool == type)
  192. {
  193. bool uiValue;
  194. childNode.Read(uiValue);
  195. if (uiValue)
  196. {
  197. if (!noDocElement)
  198. {
  199. if (jsonMember->value.IsString())
  200. {
  201. AZStd::string expectedJsonValue = trueStr;
  202. if (expectedJsonValue != jsonMember->value.GetString())
  203. {
  204. return false;
  205. }
  206. }
  207. else
  208. {
  209. return false;
  210. }
  211. }
  212. else
  213. {
  214. return false;
  215. }
  216. }
  217. else if (!noDocElement)
  218. {
  219. return false;
  220. }
  221. }
  222. // Should be a class with members instead of base data type
  223. else
  224. {
  225. rapidjson::Value* jsonNode = nullptr;
  226. if (!noDocElement)
  227. {
  228. jsonNode = &jsonMember->value;
  229. }
  230. // Drill into class
  231. if (!UiEqualToJson(jsonNode, &childNode))
  232. {
  233. return false;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. return true;
  240. }
  241. bool Serializer::UiEqualToPlist(AzToolsFramework::InstanceDataNode* node) const
  242. {
  243. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  244. if (baseMeta)
  245. {
  246. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  247. {
  248. auto childMeta = childNode.GetElementMetadata();
  249. if (childMeta)
  250. {
  251. bool noDocElement = true;
  252. const char* propertyName = childMeta->m_name;
  253. XmlNode* plistNode = m_plistDict->GetPropertyValueNode(propertyName);
  254. if (plistNode != nullptr)
  255. {
  256. noDocElement = false;
  257. }
  258. AZ::Uuid type = childMeta->m_typeId;
  259. if (m_idString == type)
  260. {
  261. AZStd::string uiValue;
  262. childNode.Read(uiValue);
  263. if (!uiValue.empty() && !noDocElement)
  264. {
  265. if (AZStd::string(plistNode->name()) == stringStr)
  266. {
  267. if (uiValue != plistNode->value())
  268. {
  269. return false;
  270. }
  271. }
  272. else
  273. {
  274. return false;
  275. }
  276. }
  277. else if (uiValue.empty() != noDocElement)
  278. {
  279. return false;
  280. }
  281. }
  282. else if (m_idBool == type)
  283. {
  284. bool uiValue;
  285. childNode.Read(uiValue);
  286. if (uiValue)
  287. {
  288. if (!noDocElement)
  289. {
  290. if (AZStd::string(plistNode->name()) != trueStr)
  291. {
  292. return false;
  293. }
  294. }
  295. else
  296. {
  297. return false;
  298. }
  299. }
  300. else if (!noDocElement)
  301. {
  302. return false;
  303. }
  304. }
  305. else if (AZStd::string(childNode.GetClassMetadata()->m_name) == "IosOrientations")
  306. {
  307. // Enter even if nullptr to make sure all values should be false
  308. if (plistNode == nullptr || AZStd::string(plistNode->name()) == arrayStr)
  309. {
  310. if (!UiEqualToPlistArray(plistNode, &childNode))
  311. {
  312. return false;
  313. }
  314. }
  315. else
  316. {
  317. return false;
  318. }
  319. }
  320. else
  321. {
  322. if (!UiEqualToPlistImages(&childNode))
  323. {
  324. return false;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. return true;
  331. }
  332. bool Serializer::UiEqualToPlistArray(XmlNode* array, AzToolsFramework::InstanceDataNode* node) const
  333. {
  334. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  335. if (baseMeta)
  336. {
  337. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  338. {
  339. const AZ::SerializeContext::ClassElement* childMeta = childNode.GetElementMetadata();
  340. if (childMeta)
  341. {
  342. AZ::Uuid type = childMeta->m_typeId;
  343. if (m_idBool == type)
  344. {
  345. const char* propertyName = childMeta->m_name;
  346. bool uiValue;
  347. childNode.Read(uiValue);
  348. bool found = false;
  349. if (array != nullptr)
  350. {
  351. for (XmlNode* plistNode = array->first_node(); plistNode != nullptr; plistNode = plistNode->next_sibling())
  352. {
  353. if (AZStd::string(plistNode->value()) == propertyName)
  354. {
  355. if (!uiValue)
  356. {
  357. return false;
  358. }
  359. else
  360. {
  361. found = true;
  362. }
  363. break;
  364. }
  365. }
  366. }
  367. if (uiValue && !found)
  368. {
  369. return false;
  370. }
  371. }
  372. }
  373. }
  374. }
  375. return true;
  376. }
  377. bool Serializer::UiEqualToPlistImages(AzToolsFramework::InstanceDataNode* node) const
  378. {
  379. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  380. if (baseMeta)
  381. {
  382. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  383. {
  384. auto childMeta = childNode.GetElementMetadata();
  385. if (childMeta)
  386. {
  387. AZ::Uuid type = childMeta->m_typeId;
  388. if (m_idString == type)
  389. {
  390. AZStd::string uiValue;
  391. childNode.Read(uiValue);
  392. if (!uiValue.empty())
  393. {
  394. return false;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return true;
  401. }
  402. void Serializer::LoadFromSettings(rapidjson::Value* root, AzToolsFramework::InstanceDataNode* node)
  403. {
  404. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  405. if (baseMeta)
  406. {
  407. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  408. {
  409. auto childMeta = childNode.GetElementMetadata();
  410. if (childMeta)
  411. {
  412. const char* propertyName = childMeta->m_name;
  413. AZ::Uuid type = childMeta->m_typeId;
  414. if (root != nullptr)
  415. {
  416. rapidjson::Value::MemberIterator jsonMember = root->FindMember(propertyName);
  417. if (jsonMember != root->MemberEnd())
  418. {
  419. rapidjson::Value& jsonNode = jsonMember->value;
  420. if (m_idString == type)
  421. {
  422. if (jsonNode.IsString())
  423. {
  424. AZStd::string jsonValue = jsonNode.GetString();
  425. childNode.Write(jsonValue);
  426. }
  427. }
  428. else if (m_idInt == type)
  429. {
  430. if (jsonNode.IsInt())
  431. {
  432. int jsonValue = jsonNode.GetInt();
  433. childNode.Write(jsonValue);
  434. }
  435. }
  436. else if (m_idBool == type)
  437. {
  438. if (jsonNode.IsString())
  439. {
  440. bool value = false;
  441. AZStd::string jsonValue = jsonNode.GetString();
  442. if (jsonValue == trueStr)
  443. {
  444. value = true;
  445. }
  446. childNode.Write(value);
  447. }
  448. }
  449. // Should be a class with members instead of base data type
  450. else
  451. {
  452. if (jsonNode.IsObject())
  453. {
  454. // Drill into class
  455. LoadFromSettings(&jsonNode, &childNode);
  456. }
  457. }
  458. }
  459. else
  460. {
  461. SetDefaults(childNode, type);
  462. }
  463. }
  464. else
  465. {
  466. SetDefaults(childNode, type);
  467. }
  468. }
  469. }
  470. }
  471. }
  472. void Serializer::SaveToSettings(rapidjson::Value* root, AzToolsFramework::InstanceDataNode* node)
  473. {
  474. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  475. if (baseMeta)
  476. {
  477. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  478. {
  479. auto childMeta = childNode.GetElementMetadata();
  480. if (childMeta)
  481. {
  482. const char* propertyName = childMeta->m_name;
  483. rapidjson::Value::MemberIterator jsonMember = root->FindMember(propertyName);
  484. if (jsonMember == root->MemberEnd())
  485. {
  486. root->AddMember(rapidjson::Value(propertyName, m_jsonDoc->GetAllocator())
  487. , rapidjson::Value(rapidjson::Type::kNullType)
  488. , m_jsonDoc->GetAllocator());
  489. jsonMember = root->FindMember(propertyName);
  490. }
  491. rapidjson::Value& jsonNode = jsonMember->value;
  492. AZ::Uuid type = childMeta->m_typeId;
  493. if (m_idString == type)
  494. {
  495. AZStd::string uiValue;
  496. childNode.Read(uiValue);
  497. if (!uiValue.empty())
  498. {
  499. jsonNode.SetString(uiValue.data(), m_jsonDoc->GetAllocator());
  500. }
  501. else
  502. {
  503. root->RemoveMember(propertyName);
  504. }
  505. }
  506. else if (m_idInt == type)
  507. {
  508. int uiValue;
  509. childNode.Read(uiValue);
  510. jsonNode.SetInt(uiValue);
  511. }
  512. else if (m_idBool == type)
  513. {
  514. bool uiValue;
  515. childNode.Read(uiValue);
  516. if (uiValue)
  517. {
  518. jsonNode.SetString(trueStr, m_jsonDoc->GetAllocator());
  519. }
  520. else
  521. {
  522. root->RemoveMember(propertyName);
  523. }
  524. }
  525. // Should be a class with members instead of base data type
  526. else
  527. {
  528. // This value needs to be an object to add members
  529. if (!jsonNode.IsObject())
  530. {
  531. jsonNode.SetObject();
  532. }
  533. // Drill into class
  534. SaveToSettings(&jsonNode, &childNode);
  535. if (jsonNode.ObjectEmpty())
  536. {
  537. root->RemoveMember(propertyName);
  538. }
  539. }
  540. }
  541. }
  542. }
  543. }
  544. void Serializer::LoadFromSettings(AzToolsFramework::InstanceDataNode* node)
  545. {
  546. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  547. if (baseMeta)
  548. {
  549. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  550. {
  551. const AZ::SerializeContext::ClassElement* childMeta = childNode.GetElementMetadata();
  552. if (childMeta)
  553. {
  554. const char* propertyName = childMeta->m_name;
  555. XmlNode* plistNode = m_plistDict->GetPropertyValueNode(propertyName);
  556. AZ::Uuid type = childMeta->m_typeId;
  557. if (plistNode != nullptr)
  558. {
  559. if (m_idString == type)
  560. {
  561. if (AZStd::string(plistNode->name()) == stringStr)
  562. {
  563. AZStd::string plistValue = plistNode->value();
  564. childNode.Write(plistValue);
  565. }
  566. }
  567. else if (m_idBool == type)
  568. {
  569. if (AZStd::string(plistNode->name()) == trueStr)
  570. {
  571. childNode.Write(true);
  572. }
  573. }
  574. else if (AZStd::string(childNode.GetClassMetadata()->m_name) == "IosOrientations")
  575. {
  576. // Make sure it seems like an array in plist as well
  577. if (AZStd::string(plistNode->name()) == arrayStr)
  578. {
  579. LoadOrientations(plistNode, &childNode);
  580. }
  581. }
  582. else
  583. {
  584. SetClassToDefaults(&childNode);
  585. }
  586. }
  587. else
  588. {
  589. SetDefaults(childNode, type);
  590. }
  591. }
  592. }
  593. }
  594. }
  595. void Serializer::LoadOrientations(XmlNode* array, AzToolsFramework::InstanceDataNode* node)
  596. {
  597. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  598. if (baseMeta)
  599. {
  600. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  601. {
  602. const AZ::SerializeContext::ClassElement* childMeta = childNode.GetElementMetadata();
  603. if (childMeta)
  604. {
  605. const char* propertyName = childMeta->m_name;
  606. bool found = false;
  607. if (array != nullptr)
  608. {
  609. for (XmlNode* plistNode = array->first_node(); plistNode != nullptr; plistNode = plistNode->next_sibling())
  610. {
  611. if (AZStd::string(plistNode->value()) == propertyName)
  612. {
  613. AZ::Uuid type = childMeta->m_typeId;
  614. if (m_idBool == type)
  615. {
  616. if (AZStd::string(plistNode->name()) == stringStr)
  617. {
  618. childNode.Write(true);
  619. found = true;
  620. }
  621. }
  622. else
  623. {
  624. AZ_Assert(false, "Unsupported type \"%s\" found in array.", childMeta->m_editData->m_name)
  625. }
  626. break;
  627. }
  628. }
  629. }
  630. if (!found)
  631. {
  632. childNode.Write(false);
  633. }
  634. }
  635. }
  636. }
  637. }
  638. void Serializer::SetClassToDefaults(AzToolsFramework::InstanceDataNode* node)
  639. {
  640. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  641. if (baseMeta)
  642. {
  643. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  644. {
  645. auto childMeta = childNode.GetElementMetadata();
  646. if (childMeta)
  647. {
  648. AZ::Uuid type = childMeta->m_typeId;
  649. SetDefaults(childNode, type);
  650. }
  651. }
  652. }
  653. }
  654. void Serializer::SetDefaults(AzToolsFramework::InstanceDataNode& node, const AZ::Uuid& type)
  655. {
  656. if (m_idString == type)
  657. {
  658. node.Write(AZStd::string(""));
  659. return;
  660. }
  661. else if (m_idBool == type)
  662. {
  663. node.Write(false);
  664. return;
  665. }
  666. else if (m_idInt == type)
  667. {
  668. node.Write(0);
  669. return;
  670. }
  671. if (AZStd::string(node.GetClassMetadata()->m_name) == "IosOrientations")
  672. {
  673. LoadOrientations(nullptr, &node);
  674. }
  675. else
  676. {
  677. SetClassToDefaults(&node);
  678. }
  679. }
  680. void Serializer::SaveToSettings(AzToolsFramework::InstanceDataNode* node)
  681. {
  682. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  683. if (baseMeta)
  684. {
  685. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  686. {
  687. auto childMeta = childNode.GetElementMetadata();
  688. if (childMeta)
  689. {
  690. const char* propertyName = childMeta->m_name;
  691. AZ::Uuid type = childMeta->m_typeId;
  692. if (m_idString == type)
  693. {
  694. AZStd::string uiValue;
  695. childNode.Read(uiValue);
  696. if (!uiValue.empty())
  697. {
  698. m_plistDict->SetPropertyValue(propertyName, uiValue.data());
  699. }
  700. else
  701. {
  702. m_plistDict->RemoveProperty(propertyName);
  703. }
  704. }
  705. else if (m_idBool == type)
  706. {
  707. bool uiValue;
  708. childNode.Read(uiValue);
  709. if (uiValue)
  710. {
  711. m_plistDict->SetPropertyValueName(propertyName, trueStr);
  712. m_plistDict->SetPropertyValue(propertyName, "");
  713. }
  714. else
  715. {
  716. m_plistDict->RemoveProperty(propertyName);
  717. }
  718. }
  719. else if (AZStd::string(childNode.GetClassMetadata()->m_name) == "IosOrientations")
  720. {
  721. XmlNode* plistNode = m_plistDict->GetPropertyValueNode(propertyName);
  722. if (plistNode == nullptr)
  723. {
  724. plistNode = m_plistDict->SetPropertyValueName(propertyName, arrayStr);
  725. }
  726. // Make sure the plist says this is an array type
  727. if (AZStd::string(plistNode->name()) == arrayStr)
  728. {
  729. if (!SaveOrientations(plistNode, &childNode))
  730. {
  731. m_plistDict->RemoveProperty(propertyName);
  732. }
  733. }
  734. }
  735. //Assume this is a class with image overrides
  736. else
  737. {
  738. OverwriteImages(&childNode);
  739. }
  740. }
  741. }
  742. }
  743. }
  744. bool Serializer::SaveOrientations(XmlNode* array, AzToolsFramework::InstanceDataNode* node)
  745. {
  746. bool anyEnabled = false;
  747. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  748. if (baseMeta)
  749. {
  750. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  751. {
  752. const AZ::SerializeContext::ClassElement* childMeta = childNode.GetElementMetadata();
  753. if (childMeta)
  754. {
  755. AZ::Uuid type = childMeta->m_typeId;
  756. if (m_idBool == type)
  757. {
  758. const char* propertyName = childMeta->m_name;
  759. bool uiValue;
  760. childNode.Read(uiValue);
  761. if (uiValue)
  762. {
  763. anyEnabled = true;
  764. }
  765. bool found = false;
  766. for (XmlNode* plistNode = array->first_node(); plistNode != nullptr; plistNode = plistNode->next_sibling())
  767. {
  768. if (AZStd::string(plistNode->value()) == propertyName)
  769. {
  770. if (!uiValue)
  771. {
  772. array->remove_node(plistNode);
  773. }
  774. else
  775. {
  776. found = true;
  777. }
  778. break;
  779. }
  780. }
  781. if (uiValue && !found)
  782. {
  783. array->append_node(m_plistDict->MakeNode(stringStr, propertyName));
  784. }
  785. }
  786. }
  787. }
  788. }
  789. return anyEnabled;
  790. }
  791. void Serializer::OverwriteImages(AzToolsFramework::InstanceDataNode* node)
  792. {
  793. const AZ::SerializeContext::ClassData* baseMeta = node->GetClassMetadata();
  794. if (baseMeta)
  795. {
  796. for (AzToolsFramework::InstanceDataNode& childNode : node->GetChildren())
  797. {
  798. auto childMeta = childNode.GetElementMetadata();
  799. if (childMeta)
  800. {
  801. AZ::Uuid type = childMeta->m_typeId;
  802. if (m_idString == type)
  803. {
  804. AZStd::string uiValue;
  805. childNode.Read(uiValue);
  806. if (!uiValue.empty())
  807. {
  808. AZ::Edit::ElementData* childEditMeta = childMeta->m_editData;
  809. if (childEditMeta != nullptr)
  810. {
  811. AZ::AttributeId handlerType = childEditMeta->m_elementId;
  812. // Special handling for iOS image overrides, the source images must be overwritten.
  813. if (handlerType == Handlers::ImagePreview)
  814. {
  815. AZ::Edit::Attribute* defaultPathAttr = childEditMeta->FindAttribute(Attributes::DefaultPath);
  816. if (defaultPathAttr != nullptr)
  817. {
  818. AzToolsFramework::PropertyAttributeReader reader(defaultPathAttr->GetContextData(), defaultPathAttr);
  819. AZStd::string defaultPath;
  820. if (reader.Read<AZStd::string>(defaultPath))
  821. {
  822. QString defaultPathQString = defaultPath.data();
  823. CFileUtil::OverwriteFile(defaultPathQString);
  824. CFileUtil::CopyFile(QString(uiValue.data()), defaultPathQString);
  825. // Clear the property so this isn't overwritten again for no reason
  826. childNode.Write(AZStd::string(""));
  827. }
  828. }
  829. else
  830. {
  831. AZ_Assert(false, "Could not find default path for \"%s\". Cannot override image.", childMeta->m_name)
  832. }
  833. }
  834. }
  835. }
  836. }
  837. else
  838. {
  839. AZ_Assert(false, "Unsupported type \"%s\" found in what should be image overrides.", childMeta->m_editData->m_name);
  840. }
  841. }
  842. }
  843. }
  844. }
  845. } // ProjectSettingsTool