config_data.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. def as_dictionary(self) -> dict:
  32. d = { "keystore_settings" : self.keystore_settings.as_dictionary(),
  33. "android_sdk_path" : self.android_sdk_path,
  34. "android_ndk_version" : self.android_ndk_version,
  35. "android_sdk_api_level" : self.android_sdk_api_level,
  36. "asset_mode": self.asset_mode,
  37. "is_meta_quest_project": self.is_meta_quest_project,
  38. }
  39. return d
  40. def update_from_dictionary(self, d: dict):
  41. """
  42. Partially updates this object from a dictionary
  43. """
  44. self.keystore_settings = KeystoreSettings.from_dictionary(d["keystore_settings"])
  45. self.android_sdk_path = d.get("android_sdk_path", "")
  46. self.android_ndk_version = d.get("android_ndk_version", self.DEFAULT_NDK_VERSION)
  47. self.android_sdk_api_level = d.get("android_sdk_api_level", self.DEFAULT_API_LEVEL)
  48. self.asset_mode = d.get("asset_mode", self.ASSET_MODE_LOOSE)
  49. self.is_meta_quest_project = d.get("is_meta_quest_project", False)
  50. def save_to_json_file(self, filePath: str) -> bool:
  51. """
  52. @returns True if successful
  53. """
  54. try:
  55. with open(filePath, "w") as f:
  56. json.dump(self.as_dictionary(), f, indent=4)
  57. except Exception as err:
  58. print(f"ConfigData.save_to_json_file failed for file {filePath}.\nException: {err}")
  59. return False
  60. return True
  61. def load_from_json_file(self, filePath: str) -> bool:
  62. """
  63. Partially updates this object from a json file
  64. """
  65. try:
  66. with open(filePath, "r") as f:
  67. loaded_dict = json.load(f)
  68. self.update_from_dictionary(loaded_dict)
  69. except Exception as err:
  70. print(f"ConfigData.load_from_json_file failed for file {filePath}.\nException: {err}")
  71. return False
  72. return True
  73. def get_o3de_cmd(self) -> str:
  74. if platform.system() == "Windows":
  75. return os.path.join(self.engine_path, "scripts", "o3de.bat")
  76. else:
  77. return os.path.join(self.engine_path, "scripts", "o3de.sh")
  78. def get_project_name(self) -> str:
  79. return os.path.basename(self.project_path)
  80. def get_android_build_dir(self) -> str:
  81. return os.path.join(self.build_path, "android")
  82. # class ConfigData END
  83. ######################################################