Kinda save settings
This commit is contained in:
@@ -3,13 +3,61 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace EvilSatellites
|
||||
{
|
||||
public static class GameSettings
|
||||
{
|
||||
public static string SettingsDirectory = Environment.SpecialFolder.Personal + "/EvilSatellites";
|
||||
public static string SettingsFile = SettingsDirectory + "/settings.dat";
|
||||
public static bool PreferSAPI = true;
|
||||
public static bool UseForceFeedback = true;
|
||||
public static bool EnableAI = true;
|
||||
|
||||
public static void SaveSettings()
|
||||
{
|
||||
if (!Directory.Exists(SettingsDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(SettingsDirectory);
|
||||
}
|
||||
try
|
||||
{
|
||||
var file = new BinaryWriter(File.Open(SettingsFile, FileMode.Create));
|
||||
file.Write(PreferSAPI);
|
||||
file.Write(UseForceFeedback);
|
||||
file.Write(EnableAI);
|
||||
file.Close();
|
||||
} catch (Exception e)
|
||||
{
|
||||
DavyKager.Tolk.Output("Error saving settings: " + e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void ReadSettings()
|
||||
{
|
||||
if (!Directory.Exists(SettingsDirectory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!File.Exists(SettingsFile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var file = new BinaryReader(File.OpenRead(SettingsFile));
|
||||
PreferSAPI = file.ReadBoolean();
|
||||
UseForceFeedback = file.ReadBoolean();
|
||||
EnableAI = file.ReadBoolean();
|
||||
file.Close();
|
||||
} catch (Exception e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user