rendered paste bodyusing System;
using System.IO;
using System.Xml.Serialization;
namespace TheFisher.Utility
{
public class ApplicationSettings
{
private static string filename = "TheFisher.xml";
private bool firstrun = true;
// form positions
private int settingsformx = 0;
private int settingsformy = 0;
private int mainformx = 0;
private int mainformy = 0;
private int mainformwidth = 0;
private int mainformheight = 0;
// login information
private string username = string.Empty;
private string password = string.Empty;
private bool rememberlogins = false;
// delays
private int lootdelay = 0;
private int castingdelay = 0;
private int updateinterval = 0;
public ApplicationSettings()
{
}
#region Public Properties
public static string Filename
{
get { return filename; }
}
public bool FirstRun
{
get { return firstrun; }
set { firstrun = value; }
}
// form positions
public int SettingsFormX
{
get { return settingsformx; }
set { settingsformx = value; }
}
public int SettingsFormY
{
get { return settingsformy; }
set { settingsformy = value; }
}
public int MainFormX
{
get { return mainformx; }
set { mainformx = value; }
}
public int MainFormY
{
get { return mainformy; }
set { mainformy = value; }
}
public int MainFormWidth
{
get { return mainformwidth; }
set { mainformy = value; }
}
public int MainFormHeight
{
get { return mainformheight; }
set { mainformheight = value; }
}
// login information
public string Username
{
get { return username; }
set { username = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public bool RememberLogins
{
get { return rememberlogins; }
set { rememberlogins = value; }
}
// delays
public int LootDelay
{
get { return lootdelay; }
set { lootdelay = value; }
}
public int CastingDelay
{
get { return castingdelay; }
set { castingdelay = value; }
}
public int UpdateInterval
{
get { return updateinterval; }
set { updateinterval = value; }
}
#endregion
public static ApplicationSettings LoadFromFile()
{
ApplicationSettings newSettingsObj = new ApplicationSettings();
if (!File.Exists(Filename))
{
return new ApplicationSettings();
}
return (ApplicationSettings) ApplicationSettings.Load(newSettingsObj.GetType(), Filename);
}
public static object Load(Type type, string filename)
{
FileStream stream = null;
try
{
stream = new FileStream(filename, FileMode.Open, FileAccess.Read);
XmlSerializer serializer = new XmlSerializer(type);
return serializer.Deserialize(stream);
}
finally
{
if (stream != null)
stream.Close();
}
}
public virtual void Save()
{
FileStream stream = null;
try
{
stream = new FileStream(Filename, FileMode.Create);
Save(stream);
}
finally
{
if (stream != null)
stream.Close();
}
}
public void Save(Stream stream)
{
try
{
XmlSerializer serializer = new XmlSerializer(this.GetType());
serializer.Serialize(stream, this);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}