AutoSaver.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * AutoSaver.h
  3. * -----------
  4. * Purpose: Class for automatically saving open modules at a specified interval.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. OPENMPT_NAMESPACE_BEGIN
  12. class CModDoc;
  13. class CAutoSaver
  14. {
  15. public:
  16. CAutoSaver();
  17. bool DoSave(DWORD curTime);
  18. bool IsEnabled() const;
  19. bool GetUseOriginalPath() const;
  20. mpt::PathString GetPath() const;
  21. uint32 GetHistoryDepth() const;
  22. uint32 GetSaveInterval() const;
  23. uint32 GetSaveIntervalMilliseconds() const
  24. {
  25. return Clamp(GetSaveInterval(), 0u, (1u << 30) / 60u / 1000u) * 60 * 1000;
  26. }
  27. private:
  28. bool SaveSingleFile(CModDoc &modDoc);
  29. mpt::PathString GetBasePath(const CModDoc &modDoc, bool createPath) const;
  30. mpt::PathString GetBaseName(const CModDoc &modDoc) const;
  31. mpt::PathString BuildFileName(const CModDoc &modDoc) const;
  32. void CleanUpBackups(const CModDoc &modDoc) const;
  33. bool CheckTimer(DWORD curTime) const;
  34. DWORD m_lastSave = 0;
  35. //Flag to prevent autosave from starting new saving if previous is still in progress.
  36. bool m_saveInProgress = false;
  37. };
  38. OPENMPT_NAMESPACE_END