fix small bugs

This commit is contained in:
Bob Sun 2017-02-13 14:30:38 +08:00
parent 892cc02f5f
commit 0b714ffec2
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
4 changed files with 16 additions and 36 deletions

View file

@ -36,7 +36,9 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
var size = UInt64(0)
do {
size = try fm.allocatedSizeOfDirectoryAtURL(directoryURL: PasswordStore.shared.storeURL)
if fm.fileExists(atPath: PasswordStore.shared.storeURL.path) {
size = try fm.allocatedSizeOfDirectoryAtURL(directoryURL: PasswordStore.shared.storeURL)
}
} catch {
print(error)
}

View file

@ -26,9 +26,7 @@ class SettingsTableViewController: UITableViewController {
@IBAction func save(segue: UIStoryboardSegue) {
if let controller = segue.source as? PGPKeySettingTableViewController {
if Defaults[.pgpPrivateKeyURL] != URL(string: controller.pgpPrivateKeyURLTextField.text!) ||
Defaults[.pgpPublicKeyURL] != URL(string: controller.pgpPublicKeyURLTextField.text!) ||
Defaults[.pgpKeyPassphrase] != controller.pgpKeyPassphraseTextField.text! {
if Defaults[.pgpKeyID] == nil {
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text!
@ -49,6 +47,8 @@ class SettingsTableViewController: UITableViewController {
}
} catch {
DispatchQueue.main.async {
self.pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
Defaults[.pgpKeyID] = nil
SVProgressHUD.showError(withStatus: error.localizedDescription)
SVProgressHUD.dismiss(withDelay: 1)
}

View file

@ -14,14 +14,14 @@ extension DefaultsKeys {
static let pgpPublicKeyURL = DefaultsKey<URL?>("pgpPublicKeyURL")
static let pgpPrivateKeyURL = DefaultsKey<URL?>("pgpPrivateKeyURL")
static let pgpKeyPassphrase = DefaultsKey<String>("pgpKeyPassphrase")
static let pgpKeyID = DefaultsKey<String>("pgpKeyID")
static let pgpKeyUserID = DefaultsKey<String>("pgpKeyUserID")
static let pgpKeyPassphrase = DefaultsKey<String?>("pgpKeyPassphrase")
static let pgpKeyID = DefaultsKey<String?>("pgpKeyID")
static let pgpKeyUserID = DefaultsKey<String?>("pgpKeyUserID")
static let gitRepositoryURL = DefaultsKey<URL?>("gitRepositoryURL")
static let gitRepositoryAuthenticationMethod = DefaultsKey<String>("gitRepositoryAuthenticationMethod")
static let gitRepositoryUsername = DefaultsKey<String>("gitRepositoryUsername")
static let gitRepositoryPassword = DefaultsKey<String>("gitRepositoryPassword")
static let gitRepositoryAuthenticationMethod = DefaultsKey<String?>("gitRepositoryAuthenticationMethod")
static let gitRepositoryUsername = DefaultsKey<String?>("gitRepositoryUsername")
static let gitRepositoryPassword = DefaultsKey<String?>("gitRepositoryPassword")
static let gitRepositorySSHPublicKeyURL = DefaultsKey<URL?>("gitRepositorySSHPublicKeyURL")
static let gitRepositorySSHPrivateKeyURL = DefaultsKey<URL?>("gitRepositorySSHPrivateKeyURL")
static let gitRepositorySSHPrivateKeyPassphrase = DefaultsKey<String?>("gitRepositorySSHPrivateKeyPassphrase")
@ -30,26 +30,3 @@ extension DefaultsKeys {
static let isTouchIDOn = DefaultsKey<Bool>("isTouchIDOn")
static let passcodeKey = DefaultsKey<String?>("passcodeKey")
}
extension Utils {
static func eraseAllUserDefaults() {
Defaults.remove(.pgpPublicKeyURL)
Defaults.remove(.pgpPrivateKeyURL)
Defaults.remove(.pgpKeyPassphrase)
Defaults.remove(.pgpKeyID)
Defaults.remove(.pgpKeyUserID)
Defaults.remove(.gitRepositoryURL)
Defaults.remove(.gitRepositoryAuthenticationMethod)
Defaults.remove(.gitRepositoryUsername)
Defaults.remove(.gitRepositoryPassword)
Defaults.remove(.gitRepositorySSHPublicKeyURL)
Defaults.remove(.gitRepositorySSHPrivateKeyURL)
Defaults.remove(.gitRepositorySSHPrivateKeyPassphrase)
Defaults.remove(.lastUpdatedTime)
Defaults.remove(.isTouchIDOn)
Defaults.remove(.passcodeKey)
}
}

View file

@ -63,9 +63,9 @@ class PasswordStore {
}
if Defaults[.gitRepositoryAuthenticationMethod] == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername], password: Defaults[.gitRepositoryPassword]))
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername]!, password: Defaults[.gitRepositoryPassword]!))
} else if Defaults[.gitRepositoryAuthenticationMethod] == "SSH Key"{
gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: Defaults[.gitRepositoryUsername], password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Globals.sshPublicKeyURL, privateKeyFile: Globals.sshPrivateKeyURL))
gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: Defaults[.gitRepositoryUsername]!, password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Globals.sshPublicKeyURL, privateKeyFile: Globals.sshPrivateKeyURL))
} else {
gitCredential = nil
}
@ -358,6 +358,7 @@ class PasswordStore {
deleteCoreData(entityName: "PasswordEntity")
deleteCoreData(entityName: "PasswordCategoryEntity")
Utils.eraseAllUserDefaults()
Defaults.removeAll()
storeRepository = nil
}
}