1 #include "savingstate.hpp"
2
3 #include <boost/filesystem/fstream.hpp>
4
5 #include "operation.hpp"
6 #include "document.hpp"
7
SavingState(Operation & operation,const boost::filesystem::path & projectPath,ToUTF8::FromType encoding)8 CSMDoc::SavingState::SavingState (Operation& operation, const boost::filesystem::path& projectPath,
9 ToUTF8::FromType encoding)
10 : mOperation (operation), mEncoder (encoding), mProjectPath (projectPath), mProjectFile (false)
11 {
12 mWriter.setEncoder (&mEncoder);
13 }
14
hasError() const15 bool CSMDoc::SavingState::hasError() const
16 {
17 return mOperation.hasError();
18 }
19
start(Document & document,bool project)20 void CSMDoc::SavingState::start (Document& document, bool project)
21 {
22 mProjectFile = project;
23
24 if (mStream.is_open())
25 mStream.close();
26
27 mStream.clear();
28
29 mSubRecords.clear();
30
31 if (project)
32 mPath = mProjectPath;
33 else
34 mPath = document.getSavePath();
35
36 boost::filesystem::path file (mPath.filename().string() + ".tmp");
37
38 mTmpPath = mPath.parent_path();
39
40 mTmpPath /= file;
41 }
42
getPath() const43 const boost::filesystem::path& CSMDoc::SavingState::getPath() const
44 {
45 return mPath;
46 }
47
getTmpPath() const48 const boost::filesystem::path& CSMDoc::SavingState::getTmpPath() const
49 {
50 return mTmpPath;
51 }
52
getStream()53 boost::filesystem::ofstream& CSMDoc::SavingState::getStream()
54 {
55 return mStream;
56 }
57
getWriter()58 ESM::ESMWriter& CSMDoc::SavingState::getWriter()
59 {
60 return mWriter;
61 }
62
isProjectFile() const63 bool CSMDoc::SavingState::isProjectFile() const
64 {
65 return mProjectFile;
66 }
67
getSubRecords()68 std::map<std::string, std::deque<int> >& CSMDoc::SavingState::getSubRecords()
69 {
70 return mSubRecords;
71 }
72