NETToolSystem.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <Atomic/IO/Log.h>
  23. #include <Atomic/IO/FileSystem.h>
  24. #include <AtomicNET/NETCore/NETCore.h>
  25. #include "../Project/ProjectEvents.h"
  26. #include "../ToolEnvironment.h"
  27. #include "NETToolSystem.h"
  28. #include "NETProjectGen.h"
  29. namespace ToolCore
  30. {
  31. NETToolSystem::NETToolSystem(Context* context) : Object(context)
  32. {
  33. if (context->GetEditorContext())
  34. {
  35. NETCore* core = GetSubsystem<NETCore>();
  36. if (!core->CreateDelegate("AtomicNETTools", "AtomicTools.AtomicTools", "InspectAssembly", (void**) &inspectAssemblyFunction_))
  37. {
  38. LOGERROR("NETToolSystem::NETToolSystem - Unable to resolve delagate AtomicNETTools.InspectAssembly");
  39. }
  40. SubscribeToEvent(E_PROJECTLOADED, HANDLER(NETToolSystem, HandleProjectLoaded));
  41. }
  42. }
  43. NETToolSystem::~NETToolSystem()
  44. {
  45. }
  46. void NETToolSystem::HandleProjectLoaded(StringHash eventType, VariantMap& eventData)
  47. {
  48. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  49. String projectPath = eventData[ProjectLoaded::P_PROJECTPATH].GetString();
  50. String pathName, fileName, ext;
  51. SplitPath(projectPath, pathName, fileName, ext);
  52. String netJSONPath = AddTrailingSlash(pathName) + "AtomicNET.json";
  53. if (fileSystem->FileExists(netJSONPath))
  54. {
  55. SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
  56. #ifdef ATOMIC_PLATFORM_OSX
  57. gen->SetScriptPlatform("MACOSX");
  58. #else
  59. gen->SetScriptPlatform("WINDOWS");
  60. #endif
  61. gen->LoadProject(netJSONPath, true);
  62. gen->Generate();
  63. }
  64. }
  65. bool NETToolSystem::InspectAssembly(const String& pathToAssembly, JSONValue &json)
  66. {
  67. json.SetType(JSON_NULL);
  68. if (!inspectAssemblyFunction_)
  69. return false;
  70. String jsonString = inspectAssemblyFunction_(pathToAssembly.CString());
  71. if (!jsonString.Length())
  72. return false;
  73. return JSONFile::ParseJSON(jsonString, json);
  74. }
  75. }