blob: 198d7075a6116cca2c658b1d3265e56eb6cf62a4 (
plain)
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
|
using System;
using System.Linq;
using System.Threading.Tasks;
namespace DSACore.DSA_Game.Save
{
using System.IO;
public class SaveCommand
{
public void LoadSession(string name = "")
{
if (name.Equals("?") || name.Equals(string.Empty))
{
Console.WriteLine($"Gespeicherte Sessions:");
Console.WriteLine(this.ListSessions());
return;
}
var path = Save.Session.DirectoryPath + @"\" + name;
var files = Directory.GetFiles(path);
var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First();
Dsa.Session = Session.Load(session);
Console.WriteLine($"{name} wurde geladen");
}
public void SessionSave(string name = "")
{
//var sendFile = this.Context.Channel.SendWebFile("https://cdn.discordapp.com/attachments/377123019673567232/465615882048110603/giphy.gif");
if (name.Equals("?") || name.Equals(string.Empty))
{
Console.WriteLine($"Gespeicherte Sessions:");
Console.WriteLine(this.ListSessions());
return;
}
var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name;
if (Directory.Exists(path))
{
var files = Directory.GetFiles(path);
int current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First()));
Dsa.Session.SessionName = name;
Dsa.Session.Save(path + "\\" + name + $"-{++current}.json");
}
else
{
Directory.CreateDirectory(path);
Dsa.Session.SessionName = name;
Dsa.Session.Save(path + "\\" + name + $"-0.json");
}
Console.WriteLine($"{name} wurde gespeichert");
//await sendFile;
}
private string[] ListSessions()
{
string[] dirs = Directory.GetDirectories(Session.DirectoryPath).OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray();
for (int i = 0; i < dirs.Length; i++)
{
dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime;
}
return dirs;
}
}
}
|