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