FileSaver.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. */
  8. #pragma once
  9. #include <ScriptCanvas/Core/Core.h>
  10. namespace ScriptCanvasEditor
  11. {
  12. namespace VersionExplorer
  13. {
  14. struct FileSaveResult
  15. {
  16. AZStd::string fileSaveError;
  17. AZStd::string tempFileRemovalError;
  18. AZ::IO::Path absolutePath;
  19. bool IsSuccess() const;
  20. };
  21. // \todo consider removing the live graph from this class, and replacing it with the json data that it will actually
  22. // write to disk.
  23. class FileSaver
  24. {
  25. public:
  26. AZ_CLASS_ALLOCATOR(FileSaver, AZ::SystemAllocator);
  27. FileSaver
  28. ( AZStd::function<bool()> onReadOnlyFile
  29. , AZStd::function<void(const FileSaveResult& result)> onComplete);
  30. const SourceHandle& GetSource() const;
  31. void Save(const SourceHandle& source, const AZ::IO::Path& absolutePath);
  32. private:
  33. AZStd::mutex m_mutex;
  34. bool m_sourceFileReleased = false;
  35. AZ::IO::Path m_fullPath;
  36. SourceHandle m_source;
  37. AZStd::function<void(const FileSaveResult& result)> m_onComplete;
  38. AZStd::function<bool()> m_onReadOnlyFile;
  39. void OnSourceFileReleased(const SourceHandle& source);
  40. void PerformMove
  41. ( AZStd::string source
  42. , AZStd::string target
  43. , size_t remainingAttempts);
  44. AZStd::string RemoveTempFile(AZStd::string_view tempFile);
  45. };
  46. }
  47. }