UIBuildSettingsIOS.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <PugiXml/src/pugixml.hpp>
  6. #include <TurboBadger/tb_layout.h>
  7. #include <TurboBadger/tb_editfield.h>
  8. #include <TurboBadger/tb_select.h>
  9. #include <Atomic/Core/Context.h>
  10. #include <Atomic/IO/Log.h>
  11. #include <Atomic/IO/FileSystem.h>
  12. #include <Atomic/IO/MemoryBuffer.h>
  13. #include <Atomic/UI/TBUI.h>
  14. #include "AEEditor.h"
  15. #include "AEEvents.h"
  16. #include "AEPreferences.h"
  17. #include "Project/ProjectUtils.h"
  18. #include "Subprocess/AESubprocessSystem.h"
  19. #include "Build/BuildSystem.h"
  20. #include "Build/BuildIOSUtils.h"
  21. #include "UIBuildSettingsIOS.h"
  22. namespace AtomicEditor
  23. {
  24. UIBuildSettingsIOS::UIBuildSettingsIOS(Context* context) :
  25. AEWidget(context)
  26. {
  27. TBUI* tbui = GetSubsystem<TBUI>();
  28. tbui->LoadResourceFile(delegate_, "AtomicEditor/editor/ui/buildsettings_ios.tb.txt");
  29. appNameEdit_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("app_name"));
  30. assert(appNameEdit_);
  31. appPackageEdit_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("app_package"));
  32. assert(appPackageEdit_);
  33. productNameEdit_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("product_name"));
  34. assert(productNameEdit_);
  35. companyNameEdit_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("company_name"));
  36. assert(companyNameEdit_);
  37. provisionPath_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("provision_path"));
  38. assert(provisionPath_);
  39. applicationIDPrefix_ = delegate_->GetWidgetByIDAndType<TBTextField>(TBIDC("appid_prefix"));
  40. assert(applicationIDPrefix_);
  41. Refresh();
  42. }
  43. UIBuildSettingsIOS::~UIBuildSettingsIOS()
  44. {
  45. }
  46. void UIBuildSettingsIOS::StoreSettings()
  47. {
  48. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  49. IOSBuildSettings settings;
  50. TBStr text;
  51. appNameEdit_->GetText(text);
  52. settings.appName = text.CStr();
  53. text.Clear();
  54. appPackageEdit_->GetText(text);
  55. settings.package = text.CStr();
  56. text.Clear();
  57. productNameEdit_->GetText(text);
  58. settings.productName = text.CStr();
  59. text.Clear();
  60. companyNameEdit_->GetText(text);
  61. settings.companyName = text.CStr();
  62. text.Clear();
  63. provisionPath_->GetText(text);
  64. settings.provisionFile = text.CStr();
  65. text.Clear();
  66. applicationIDPrefix_->GetText(text);
  67. settings.appidPrefix = text.CStr();
  68. text.Clear();
  69. buildSystem->GetBuildSettings()->SetIOSSettings(settings);
  70. }
  71. void UIBuildSettingsIOS::Refresh()
  72. {
  73. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  74. const IOSBuildSettings& settings = buildSystem->GetBuildSettings()->GetIOSSettings();
  75. provisionPath_->SetText(settings.provisionFile.CString());
  76. appNameEdit_->SetText(settings.appName.CString());
  77. appPackageEdit_->SetText(settings.package.CString());
  78. productNameEdit_->SetText(settings.productName.CString());
  79. companyNameEdit_->SetText(settings.companyName.CString());
  80. applicationIDPrefix_->SetText(settings.appidPrefix.CString());
  81. }
  82. bool UIBuildSettingsIOS::ParseProvisionData(const String& provisionFile)
  83. {
  84. #if defined(ATOMIC_PLATFORM_WINDOWS) || defined(ATOMIC_PLATFORM_LINUX)
  85. return false;
  86. #else
  87. String pdata = GetMobileProvisionData(provisionFile.CString());
  88. if (!pdata.Length())
  89. return false;
  90. pugi::xml_document doc;
  91. if (!doc.load(pdata.CString()))
  92. {
  93. return false;
  94. }
  95. String AppIDName;
  96. String ApplicationIdentifierPrefix;
  97. pugi::xml_node dict = doc.document_element().child("dict");
  98. for (pugi::xml_node key = dict.child("key"); key; key = key.next_sibling("key"))
  99. {
  100. String keyName = key.child_value();
  101. if (keyName == "AppIDName")
  102. {
  103. pugi::xml_node value = key.next_sibling();
  104. if (!strcmp(value.name(), "string"))
  105. AppIDName = value.child_value();
  106. }
  107. else if (keyName == "ApplicationIdentifierPrefix")
  108. {
  109. pugi::xml_node array = key.next_sibling();
  110. if (!strcmp(array.name(), "array"))
  111. {
  112. pugi::xml_node value = array.first_child();
  113. if (!strcmp(value.name(), "string"))
  114. ApplicationIdentifierPrefix = value.child_value();
  115. }
  116. }
  117. }
  118. if (!ApplicationIdentifierPrefix.Length())
  119. return false;
  120. applicationIDPrefix_->SetText(ApplicationIdentifierPrefix.CString());
  121. provisionPath_->SetText(provisionFile.CString());
  122. return true;
  123. #endif
  124. }
  125. bool UIBuildSettingsIOS::OnEvent(const TBWidgetEvent &ev)
  126. {
  127. Editor* editor = context_->GetSubsystem<Editor>();
  128. ProjectUtils* utils = context_->GetSubsystem<ProjectUtils>();
  129. if (ev.type == EVENT_TYPE_CLICK)
  130. {
  131. if (ev.target->GetID() == TBIDC("choose_provision_path"))
  132. {
  133. String path = utils->GetMobileProvisionPath();
  134. if (path.Length())
  135. {
  136. if (!ParseProvisionData(path))
  137. editor->PostModalError("Mobile Provision Error", "Could not parse mobile provision");
  138. else
  139. StoreSettings();
  140. }
  141. return true;
  142. }
  143. }
  144. return false;
  145. }
  146. }