/// <summary> /// Saves the settings to file. This method is invoked automatically internally when changes are detected, but can be called /// externally to ensure that changes are saved properly. /// </summary> public void Save() { lock (_saveSync) { var sb = new StringBuilder(); // Write the settings AddSetting(sb, _headerLiveVersion, LiveVersion.ToString()); lock (_fileServersSync) { foreach (var s in _fileServers) { AddSetting(sb, _headerFileServer, s.GetCreationString()); } } lock (_masterServersSync) { foreach (var s in _masterServers) { AddSetting(sb, _headerMasterServer, s.GetCreationString()); } } // Save the file var tmpFile = FilePath + ".tmp"; if (File.Exists(tmpFile)) { File.Delete(tmpFile); } File.WriteAllText(tmpFile, sb.ToString()); File.Copy(tmpFile, FilePath, true); try { if (File.Exists(tmpFile)) { File.Delete(tmpFile); } } catch (Exception ex) { Debug.Fail(ex.ToString()); } } }
/// <summary> /// Updates the live version file. /// </summary> void UpdateLiveVersionFile() { var p = LiveVersionFilePath; var tmpPath = p + ".tmp"; if (File.Exists(tmpPath)) { File.Delete(tmpPath); } File.WriteAllText(tmpPath, LiveVersion.ToString()); File.Copy(tmpPath, p, true); if (File.Exists(tmpPath)) { File.Delete(tmpPath); } }