-
Notifications
You must be signed in to change notification settings - Fork 21
/
SaveBackup.cs
198 lines (184 loc) · 5.11 KB
/
SaveBackup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.IO;
namespace RemnantSaveManager
{
public class SaveBackup : IEditableObject
{
struct SaveData
{
internal string name;
internal DateTime date;
internal bool keep;
internal bool active;
}
public event EventHandler<UpdatedEventArgs> Updated;
private SaveData saveData;
private SaveData backupData;
private bool inTxn = false;
//private int[] progression;
//private List<RemnantCharacter> charData;
private RemnantSave save;
public string Name
{
get
{
return this.saveData.name;
}
set
{
if (value.Equals(""))
{
this.saveData.name = this.saveData.date.Ticks.ToString();
} else
{
this.saveData.name = value;
}
//OnUpdated(new UpdatedEventArgs("Name"));
}
}
public DateTime SaveDate
{
get {
return this.saveData.date;
}
set
{
this.saveData.date = value;
//OnUpdated(new UpdatedEventArgs("SaveDate"));
}
}
public string Progression
{
get
{
return string.Join(",", this.save.Characters);
}
}
public bool Keep
{
get
{
return this.saveData.keep;
}
set
{
this.saveData.keep = value;
//OnUpdated(new UpdatedEventArgs("Keep"));
}
}
public bool Active
{
get
{
return this.saveData.active;
}
set
{
this.saveData.active = value;
//OnUpdated(new UpdatedEventArgs("Active"));
}
}
public RemnantSave Save
{
get
{
return save;
}
}
//public SaveBackup(DateTime saveDate)
public SaveBackup(string savePath)
{
this.save = new RemnantSave(savePath);
this.saveData = new SaveData();
this.saveData.name = this.SaveDateTime.Ticks.ToString();
this.saveData.date = this.SaveDateTime;
this.saveData.keep = false;
}
/*public void setProgression(List<List<string>> allItemList)
{
int[] prog = new int[allItemList.Count];
for (int i=0; i < allItemList.Count; i++)
{
prog[i] = allItemList[i].Count;
}
this.progression = prog;
}
public List<RemnantCharacter> GetCharacters()
{
return this.charData;
}
public void LoadCharacterData(string saveFolder)
{
this.charData = RemnantCharacter.GetCharactersFromSave(saveFolder, RemnantCharacter.CharacterProcessingMode.NoEvents);
}*/
// Implements IEditableObject
void IEditableObject.BeginEdit()
{
if (!inTxn)
{
this.backupData = saveData;
inTxn = true;
}
}
void IEditableObject.CancelEdit()
{
if (inTxn)
{
this.saveData = backupData;
inTxn = false;
}
}
void IEditableObject.EndEdit()
{
if (inTxn)
{
if (!backupData.name.Equals(saveData.name))
{
OnUpdated(new UpdatedEventArgs("Name"));
}
if (!backupData.date.Equals(saveData.date))
{
OnUpdated(new UpdatedEventArgs("SaveDate"));
}
if (!backupData.keep.Equals(saveData.keep))
{
OnUpdated(new UpdatedEventArgs("Keep"));
}
if (!backupData.active.Equals(saveData.active))
{
OnUpdated(new UpdatedEventArgs("Active"));
}
backupData = new SaveData();
inTxn = false;
}
}
public void OnUpdated(UpdatedEventArgs args)
{
EventHandler<UpdatedEventArgs> handler = Updated;
if (null != handler) handler(this, args);
}
private DateTime SaveDateTime
{
get
{
return File.GetLastWriteTime(save.SaveProfilePath);
}
}
}
public class UpdatedEventArgs : EventArgs
{
private readonly string _fieldName;
public UpdatedEventArgs(string fieldName) {
_fieldName = fieldName;
}
public string FieldName
{
get { return _fieldName; }
}
}
}