/// <summary> /// Loads the settings of the application from the configuration file. /// </summary> public void LoadSettings() { //we must use Globals.GetAppPath because the Globals instance will not have //been created yet string ConfigFile = Globals.GetAppPath() + "data\\CrawlWave.Client.Config.xml"; try { if (!File.Exists(ConfigFile)) { //perhaps the file does not exist - probably because it has not been //created yet. In this case just let the class retain default values. return; } Stream ReadStream = File.Open(ConfigFile, FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(AppSettings)); AppSettings settings = (AppSettings)serializer.Deserialize(ReadStream); ReadStream.Close(); this.ClientID = settings.ClientID; this.ConnectionSpeed = settings.ConnectionSpeed; this.Email = settings.Email; this.EnableScheduler = settings.EnableScheduler; this.HardwareInfo = settings.HardwareInfo; this.LoadAtStartup = settings.LoadAtStartup; this.MinimizeOnExit = settings.MinimizeOnExit; this.MinimizeToTray = settings.MinimizeToTray; this.Password = settings.Password; this.StartTime = settings.StartTime; this.StopTime = settings.StopTime; this.UserID = settings.UserID; this.UserName = settings.UserName; } catch {} }
/// <summary> /// Saves the application's settings in a new xml file on disk /// </summary> /// <remarks> /// The code that updates the registry according to the LoadAtStartup value must /// be changed once CrawlWave.Updater or something is built. /// </remarks> public void SaveSettings() { //first of all save the configuration file to disk string ConfigFile = Globals.GetAppPath() + "data\\CrawlWave.Client.Config.xml"; try { Stream WriteStream = File.Open(ConfigFile, FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(AppSettings)); serializer.Serialize(WriteStream, this); WriteStream.Close(); } catch {} //now update the registry if necessary try { RegistryKey regKey = Registry.LocalMachine; RegistryKey cwrKey = regKey.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (cwrKey != null) { string ValueName = "CrawlWave.Client"; if (LoadAtStartup) { if (cwrKey.GetValue(ValueName) == null) { cwrKey.SetValue(ValueName, (string)(Globals.GetAppPath() + "\\CrawlWave.Client.UI.exe")); } } else { if (cwrKey.GetValue(ValueName) != null) { cwrKey.DeleteValue(ValueName); } } } } catch {} }