2013-09-15 10:48:57 +00:00
|
|
|
#ifndef CSM_DOC_SAVINGSTATE_H
|
|
|
|
#define CSM_DOC_SAVINGSTATE_H
|
|
|
|
|
2015-01-22 12:41:09 +00:00
|
|
|
#include <deque>
|
2022-06-08 21:25:50 +00:00
|
|
|
#include <filesystem>
|
2013-09-15 13:00:41 +00:00
|
|
|
#include <fstream>
|
2014-05-27 10:39:26 +00:00
|
|
|
#include <map>
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <string>
|
2013-09-15 13:00:41 +00:00
|
|
|
|
2022-01-22 14:58:41 +00:00
|
|
|
#include <components/esm3/esmwriter.hpp>
|
2022-11-15 23:07:33 +00:00
|
|
|
#include <components/misc/algorithm.hpp>
|
2014-05-12 08:32:57 +00:00
|
|
|
#include <components/to_utf8/to_utf8.hpp>
|
2023-03-02 22:29:11 +00:00
|
|
|
|
2013-09-15 10:48:57 +00:00
|
|
|
namespace CSMDoc
|
|
|
|
{
|
|
|
|
class Operation;
|
2013-09-15 13:00:41 +00:00
|
|
|
class Document;
|
2013-09-15 10:48:57 +00:00
|
|
|
|
|
|
|
class SavingState
|
|
|
|
{
|
|
|
|
Operation& mOperation;
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path mPath;
|
|
|
|
std::filesystem::path mTmpPath;
|
2013-09-15 13:00:41 +00:00
|
|
|
ToUTF8::Utf8Encoder mEncoder;
|
2022-06-08 21:25:50 +00:00
|
|
|
std::ofstream mStream;
|
2013-09-15 13:00:41 +00:00
|
|
|
ESM::ESMWriter mWriter;
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path mProjectPath;
|
2013-09-27 09:36:06 +00:00
|
|
|
bool mProjectFile;
|
2023-03-02 22:29:11 +00:00
|
|
|
std::map<ESM::RefId, std::deque<int>> mSubRecords; // record ID, list of subrecords
|
2013-09-15 10:48:57 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
public:
|
2022-06-08 21:25:50 +00:00
|
|
|
SavingState(Operation& operation, std::filesystem::path projectPath, ToUTF8::FromType encoding);
|
2013-09-15 10:48:57 +00:00
|
|
|
|
|
|
|
bool hasError() const;
|
2013-09-15 13:00:41 +00:00
|
|
|
|
2013-09-27 09:36:06 +00:00
|
|
|
void start(Document& document, bool project);
|
|
|
|
///< \param project Save project file instead of content file.
|
2013-09-15 13:00:41 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
const std::filesystem::path& getPath() const;
|
2013-09-15 13:00:41 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
const std::filesystem::path& getTmpPath() const;
|
2013-09-15 13:00:41 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::ofstream& getStream();
|
2013-09-15 13:00:41 +00:00
|
|
|
|
|
|
|
ESM::ESMWriter& getWriter();
|
2013-09-27 09:36:06 +00:00
|
|
|
|
|
|
|
bool isProjectFile() const;
|
|
|
|
///< Currently saving project file? (instead of content file)
|
2014-05-27 10:39:26 +00:00
|
|
|
|
2023-03-02 22:29:11 +00:00
|
|
|
const std::deque<int>* findSubRecord(const ESM::RefId& refId) const;
|
|
|
|
|
|
|
|
std::deque<int>& getOrInsertSubRecord(const ESM::RefId& refId);
|
|
|
|
|
|
|
|
void clearSubRecords();
|
2013-09-15 10:48:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-19 11:52:19 +00:00
|
|
|
#endif
|