-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
204 lines (191 loc) · 7.76 KB
/
Copy pathMain.cs
File metadata and controls
204 lines (191 loc) · 7.76 KB
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
199
200
201
202
203
204
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace VSSaveManager
{
public class Main
{
internal static string SteamFolderDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\Steam\userdata";
internal static string EGSFolderDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Vampire_Survivors_EGS";
internal static string SaveFolderDirectory = SteamFolderDirectory;
internal static string DesktopDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\";
internal static string AppDataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Vampire_Survivors_Data\";
internal static string UserSaveFolder = "";
internal static string[] FoldersFound = new string[0];
internal static GameVersions GameVersion = GameVersions.Steam;
private static bool _SavesDirectoryExist = false;
internal static bool SavesDirectoryExist { get { return _SavesDirectoryExist; } }
internal static SaveFile MainSaveFile;
private static bool _MainSaveFileExists = false;
internal static bool MainSaveFileExists { get { return _MainSaveFileExists; } }
internal static string GetFullGameSaveDirectory
{
get
{
switch (GameVersion)
{
case GameVersions.Steam:
return SaveFolderDirectory + "\\" + UserSaveFolder + @"\1794680\remote\";
case GameVersions.EGS:
return SaveFolderDirectory + "\\" + UserSaveFolder + @"\";
}
return "Not Setup Game Version!!";
}
}
internal static string SaveFileName
{
get
{
switch (GameVersion)
{
case GameVersions.EGS:
return "SaveData.sav";
}
return "SaveData";
}
}
internal static string LastProfile = "";
static string SettingsFileName = Environment.CurrentDirectory + @"\settings.json";
static bool EndsWithCorrectPath(string Path)
{
switch (GameVersion)
{
case GameVersions.Steam:
return Path.EndsWith("userdata");
case GameVersions.EGS:
return Path.EndsWith("Vampire_Survivors_EGS");
}
return false;
}
internal static void SetDefaultGameVersions()
{
switch (GameVersion)
{
case GameVersions.Steam:
SaveFolderDirectory = SteamFolderDirectory;
break;
case GameVersions.EGS:
SaveFolderDirectory = EGSFolderDirectory;
break;
}
}
internal static void SaveSettingFile()
{
if(File.Exists(SettingsFileName))
{
File.Delete(SettingsFileName);
}
using (FileStream stream = new FileStream(SettingsFileName, FileMode.CreateNew))
{
using (StreamWriter writer = new StreamWriter(stream))
{
JObject save = new JObject();
save.Add("LastProfile", LastProfile);
save.Add("SaveDirectory", SaveFolderDirectory);
save.Add("GameVersion", (int)GameVersion);
writer.Write(save.ToString());
}
}
}
internal static void LoadSettingFile()
{
if (File.Exists(SettingsFileName))
{
using (FileStream stream = new FileStream(SettingsFileName, FileMode.Open))
{
using (StreamReader reader = new StreamReader(stream))
{
string Code = reader.ReadToEnd();
JObject save = JObject.Parse(Code);
LastProfile = save["LastProfile"].Value<string>();
if (save.ContainsKey("SaveDirectory"))
SaveFolderDirectory = save["SaveDirectory"].Value<string>();
if (save.ContainsKey("GameVersion"))
GameVersion = (GameVersions)save["GameVersion"].Value<int>();
}
}
}
}
internal static void InitializeDirectories()
{
_SavesDirectoryExist = false;
FoldersFound = new string[0];
if (Directory.Exists(SaveFolderDirectory))
{
if (EndsWithCorrectPath(SaveFolderDirectory))
{
_SavesDirectoryExist = true;
FoldersFound = Directory.GetDirectories(SaveFolderDirectory + "\\", "*", SearchOption.TopDirectoryOnly).Select(x => x.Substring(SaveFolderDirectory.Length + 1)).ToArray();
}
}
}
internal static void LoadSavesAndProfiles()
{
string SaveFilePath = GetFullGameSaveDirectory + SaveFileName;
if(_MainSaveFileExists = File.Exists(SaveFilePath))
{
MainSaveFile = new SaveFile(LoadJsonFile(SaveFilePath));
}
}
internal static void SaveSaveFileInformation(SaveFile save)
{
string SaveDataPath = DesktopDirectory + SaveFileName;
save.UpdateChecksum();
if (File.Exists(SaveDataPath)) File.Delete(SaveDataPath);
using (FileStream stream = new FileStream(SaveDataPath, FileMode.CreateNew))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(save.Minify());
}
}
}
internal static void TrySavingToDesktop(SaveFile save)
{
string SaveDataPath = DesktopDirectory + "SaveData";
if (File.Exists(SaveDataPath))
File.Delete(SaveDataPath);
using (FileStream stream = new FileStream(SaveDataPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(save.SaveObject.ToString());
}
}
}
internal static void OpenSavesFolder()
{
System.Diagnostics.Process.Start(GetFullGameSaveDirectory);
//System.Windows.Forms.MessageBox.Show("Use a online Vampire Survivors save editor on the \"SaveData\" in your desktop to update checksum, then download the edited save file.\nDepending on the site you use, it might be downloaded as \"SaveData.sav\", rename it to \"SaveData\".\nMove the SaveData in your desktop to the folder where your save file is at.\nRemember to disable Steam Cloud temporarily.");
}
private static string LoadJsonFile(string Path)
{
string Text = "";
using (StreamReader stream = new StreamReader(Path, Encoding.UTF8))
{
Text = stream.ReadToEnd();
}
return Text;
}
public static string ReturnGameVersionName(GameVersions ver)
{
switch (ver)
{
case GameVersions.Steam:
return "Steam";
case GameVersions.EGS:
return "Epic Games Store";
}
return ver.ToString();
}
public enum GameVersions : byte
{
Steam,
EGS
}
}
}