config_data.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import os
  8. import json
  9. import platform
  10. from keystore_settings import KeystoreSettings
  11. class ConfigData:
  12. """
  13. This class contains all the configuration parameters that are required
  14. to create a keystore for android applications and the configuration
  15. data that is required to create an android project for O3DE.
  16. """
  17. ASSET_MODE_LOOSE = "LOOSE"
  18. DEFAULT_NDK_VERSION = "25*"
  19. DEFAULT_API_LEVEL = "31" # The API level for Android 12.
  20. def __init__(self):
  21. self.engine_path = "" # Not serialized.
  22. self.project_path = "" # Not serialized.
  23. self.build_path = "" # Not serialized.
  24. self.third_party_path = "" # Not serialized.
  25. self.keystore_settings = KeystoreSettings()
  26. self.android_sdk_path = ""
  27. self.android_ndk_version = self.DEFAULT_NDK_VERSION
  28. self.android_sdk_api_level = self.DEFAULT_API_LEVEL
  29. self.asset_mode = self.ASSET_MODE_LOOSE
  30. self.is_meta_quest_project = False
  31. # When non-empty, looks like a series of space separated strings like
  32. # "-DENABLE_MY_LIB=ON -DENABLE_ANOTHER_GEM=OFF"
  33. self.extra_cmake_args = ""
  34. def as_dictionary(self) -> dict:
  35. d = { "keystore_settings" : self.keystore_settings.as_dictionary(),
  36. "android_sdk_path" : self.android_sdk_path,
  37. "android_ndk_version" : self.android_ndk_version,
  38. "android_sdk_api_level" : self.android_sdk_api_level,
  39. "asset_mode": self.asset_mode,
  40. "is_meta_quest_project": self.is_meta_quest_project,
  41. "extra_cmake_args": self.extra_cmake_args,
  42. }
  43. return d
  44. def update_from_dictionary(self, d: dict):
  45. """
  46. Partially updates this object from a dictionary
  47. """
  48. self.keystore_settings = KeystoreSettings.from_dictionary(d["keystore_settings"])
  49. self.android_sdk_path = d.get("android_sdk_path", "")
  50. self.android_ndk_version = d.get("android_ndk_version", self.DEFAULT_NDK_VERSION)
  51. self.android_sdk_api_level = d.get("android_sdk_api_level", self.DEFAULT_API_LEVEL)
  52. self.asset_mode = d.get("asset_mode", self.ASSET_MODE_LOOSE)
  53. self.is_meta_quest_project = d.get("is_meta_quest_project", False)
  54. self.extra_cmake_args = d.get("extra_cmake_args", "")
  55. def save_to_json_file(self, filePath: str) -> bool:
  56. """
  57. @returns True if successful
  58. """
  59. try:
  60. with open(filePath, "w") as f:
  61. json.dump(self.as_dictionary(), f, indent=4)
  62. except Exception as err:
  63. print(f"ConfigData.save_to_json_file failed for file {filePath}.\nException: {err}")
  64. return False
  65. return True
  66. def load_from_json_file(self, filePath: str) -> bool:
  67. """
  68. Partially updates this object from a json file
  69. """
  70. try:
  71. with open(filePath, "r") as f:
  72. loaded_dict = json.load(f)
  73. self.update_from_dictionary(loaded_dict)
  74. except Exception as err:
  75. print(f"ConfigData.load_from_json_file failed for file {filePath}.\nException: {err}")
  76. return False
  77. return True
  78. def get_o3de_cmd(self) -> str:
  79. if platform.system() == "Windows":
  80. return os.path.join(self.engine_path, "scripts", "o3de.bat")
  81. else:
  82. return os.path.join(self.engine_path, "scripts", "o3de.sh")
  83. def get_project_name(self) -> str:
  84. return os.path.basename(self.project_path)
  85. def get_android_build_dir(self) -> str:
  86. return os.path.join(self.build_path, "android")
  87. # class ConfigData END
  88. ######################################################