ProjectBuildSettings.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <Atomic/IO/Log.h>
  2. #include <Atomic/IO/File.h>
  3. #include <Atomic/Resource/JSONFile.h>
  4. #include "ProjectBuildSettings.h"
  5. namespace ToolCore
  6. {
  7. void MacBuildSettings::Write(JSONValue& parent)
  8. {
  9. JSONValue json = parent.CreateChild("MacBuildSettings");
  10. json.SetString("appName", appName_);
  11. json.SetString("packageName", packageName_);
  12. json.SetString("companyName", companyName_);
  13. json.SetString("productName", productName_);
  14. }
  15. void MacBuildSettings::Read(JSONValue& parent)
  16. {
  17. JSONValue json = parent.GetChild("MacBuildSettings");
  18. if (json == JSONValue::EMPTY)
  19. return;
  20. appName_ = json.GetString("appName");
  21. packageName_ = json.GetString("packageName");
  22. companyName_ = json.GetString("companyName");
  23. productName_ = json.GetString("productName");
  24. }
  25. ProjectBuildSettings::ProjectBuildSettings(Context* context) : Object(context),
  26. macBuildSettings_(new MacBuildSettings())
  27. {
  28. }
  29. ProjectBuildSettings::~ProjectBuildSettings()
  30. {
  31. }
  32. bool ProjectBuildSettings::Load(const String& path)
  33. {
  34. SharedPtr<File> file(new File(context_, path));
  35. if (!file->IsOpen())
  36. return false;
  37. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  38. bool result = jsonFile->Load(*file);
  39. file->Close();
  40. JSONValue root = jsonFile->GetRoot();
  41. if (root == JSONValue::EMPTY)
  42. return false;
  43. macBuildSettings_->Read(root);
  44. return result;
  45. }
  46. void ProjectBuildSettings::Save(const String& path)
  47. {
  48. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  49. JSONValue root = jsonFile->CreateRoot();
  50. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  51. macBuildSettings_->Write(root);
  52. jsonFile->Save(*file, String(" "));
  53. file->Close();
  54. }
  55. }