TrueCraft/TrueCraft.Core/UserSettings.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2015-06-02 17:52:22 -06:00
using System;
using Newtonsoft.Json;
using System.IO;
namespace TrueCraft.Core
2015-06-02 17:52:22 -06:00
{
public class UserSettings
{
public static UserSettings Local { get; set; }
public static string SettingsPath
2015-06-02 17:52:22 -06:00
{
get
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".truecraft", "settings.json");
2015-06-02 17:52:22 -06:00
}
}
public bool AutoLogin { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string LastIP { get; set; }
public string SelectedTexturePack { get; set; }
public FavoriteServer[] FavoriteServers { get; set; }
2015-06-02 17:52:22 -06:00
public UserSettings()
{
AutoLogin = false;
Username = "";
Password = "";
LastIP = "";
SelectedTexturePack = TexturePack.DefaultID;
2015-06-02 20:31:43 -06:00
FavoriteServers = new FavoriteServer[0];
2015-06-02 17:52:22 -06:00
}
public void Load()
{
if (File.Exists(SettingsPath))
JsonConvert.PopulateObject(File.ReadAllText(SettingsPath), this);
}
public void Save()
{
Directory.CreateDirectory(Path.GetDirectoryName(SettingsPath));
File.WriteAllText(SettingsPath, JsonConvert.SerializeObject(this, Formatting.Indented));
2015-06-02 17:52:22 -06:00
}
}
public class FavoriteServer
{
public string Name { get; set; }
public string Address { get; set; }
}
2015-06-02 17:52:22 -06:00
}