diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index c8c826ef4..79c28212a 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -63,6 +63,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, private let feedsPath: ODBPath private let feedsTable: ODBTable + private let opmlFilePath: String + private struct SettingsKey { static let unreadCount = "unreadCount" } @@ -115,6 +117,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, self.settingsFile = settingsFile self.dataFolder = dataFolder + self.opmlFilePath = (dataFolder as NSString).appendingPathComponent("Subscriptions.opml") + let databaseFilePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3") self.database = ArticlesDatabase(databaseFilePath: databaseFilePath, accountID: accountID) @@ -417,6 +421,32 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, flattenedFeeds().forEach { $0.unreadCount = 0 } } + public func opmlDocument() -> String { + let escapedTitle = nameForDisplay.rs_stringByEscapingSpecialXMLCharacters() + let openingText = + """ + + + + + \(escapedTitle) + + + + """ + + let middleText = OPMLString(indentLevel: 0) + + let closingText = + """ + + + """ + + let opml = openingText + middleText + closingText + return opml + } + // MARK: - Debug public func debugDropConditionalGetInfo() { @@ -585,6 +615,8 @@ private extension Account { func saveToDisk() { + dirty = false + let d = diskDictionary() do { try RSPlist.write(d, filePath: settingsFile) @@ -592,7 +624,15 @@ private extension Account { catch let error as NSError { NSApplication.shared.presentError(error) } - dirty = false + + let opmlDocumentString = opmlDocument() + do { + let url = URL(fileURLWithPath: opmlFilePath) + try opmlDocumentString.write(to: url, atomically: true, encoding: .utf8) + } + catch let error as NSError { + NSApplication.shared.presentError(error) + } } }