-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreferences.cs
85 lines (68 loc) · 2.44 KB
/
Preferences.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace TModel
{
public static class Preferences
{
public static Action Changed;
// Folder for storing user settings, Fortnite mappings and other data for the software.
public static string StorageFolder { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TModel");
public static string ExportsPath { get; } = Path.Combine(StorageFolder, "Exports");
public static string SettingsFile { get; } = Path.Combine(StorageFolder, "Settings.settings");
public static string MappingsFile { set; get; } = @"https://benbot.app/api/v1/mappings/++Fortnite+Release-19.01-CL-18489740-Windows_oo.usmap";
public static string? GameDirectory { get; set; }
public static bool? AutoLoad { set; get; }
public static void Save()
{
CBinaryWriter Writer = new CBinaryWriter(File.Open(SettingsFile, FileMode.OpenOrCreate, FileAccess.ReadWrite));
Writer.Write(GameDirectory);
Writer.Write(AutoLoad ?? false);
Writer.Write(MappingsFile);
Writer.Close();
if (Changed != null)
Changed();
}
public static void Read()
{
if (File.Exists(SettingsFile))
{
CBinaryReader Reader = new CBinaryReader(File.Open(SettingsFile, FileMode.Open, FileAccess.Read));
if (Reader.BaseStream.Length != 0)
{
GameDirectory = Reader.ReadString();
AutoLoad = Reader.ReadBoolean();
MappingsFile = Reader.ReadString();
}
Reader.Close();
}
}
}
public class CBinaryWriter : BinaryWriter
{
public CBinaryWriter(Stream output) : base(output)
{
}
public override void Write(string value)
{
Write((byte)value.Length);
Write(value.ToCharArray());
}
}
public class CBinaryReader : BinaryReader
{
public CBinaryReader(Stream input) : base(input)
{
}
public override string ReadString()
{
int length = ReadByte();
return new string(ReadChars(length));
}
}
}