forked from Razzmatazzz/RemnantSaveManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemnantSave.cs
137 lines (125 loc) · 3.54 KB
/
RemnantSave.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace RemnantSaveManager
{
public class RemnantSave
{
private string savePath;
private string profileFile;
private List<RemnantCharacter> saveCharacters;
private RemnantSaveType saveType;
private WindowsSave winSave;
public RemnantSave(string path)
{
if (!Directory.Exists(path))
{
throw new Exception(path + " does not exist.");
}
if (File.Exists(path + "\\profile.sav"))
{
this.saveType = RemnantSaveType.Normal;
this.profileFile = "profile.sav";
}
else
{
var winFiles = Directory.GetFiles(path, "container.*");
if (winFiles.Length > 0)
{
this.winSave = new WindowsSave(winFiles[0]);
this.saveType = RemnantSaveType.WindowsStore;
profileFile = winSave.Profile;
}
else
{
throw new Exception(path + " is not a valid save.");
}
}
this.savePath = path;
saveCharacters = RemnantCharacter.GetCharactersFromSave(this, RemnantCharacter.CharacterProcessingMode.NoEvents);
}
public string SaveFolderPath
{
get
{
return this.savePath;
}
}
public string SaveProfilePath
{
get
{
return this.savePath + $@"\{this.profileFile}";
}
}
public RemnantSaveType SaveType
{
get { return this.saveType; }
}
public List<RemnantCharacter> Characters
{
get
{
return saveCharacters;
}
}
public string[] WorldSaves
{
get
{
if (this.saveType == RemnantSaveType.Normal)
{
return Directory.GetFiles(SaveFolderPath, "save_*.sav");
}
else
{
System.Console.WriteLine(this.winSave.Worlds.ToArray());
return this.winSave.Worlds.ToArray();
}
}
}
public bool Valid
{
get
{
return this.saveType == RemnantSaveType.Normal || this.winSave.Valid;
}
}
public static Boolean ValidSaveFolder(String folder)
{
if (!Directory.Exists(folder))
{
return false;
}
if (File.Exists(folder + "\\profile.sav"))
{
return true;
}
else
{
var winFiles = Directory.GetFiles(folder, "container.*");
if (winFiles.Length > 0)
{
return true;
}
}
return false;
}
public void UpdateCharacters()
{
saveCharacters = RemnantCharacter.GetCharactersFromSave(this);
}
public void UpdateCharacters(RemnantCharacter.CharacterProcessingMode mode)
{
saveCharacters = RemnantCharacter.GetCharactersFromSave(this, mode);
}
}
public enum RemnantSaveType
{
Normal,
WindowsStore
}
}