O2.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // O2.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/9/26.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import Foundation
  9. import CocoaLumberjack
  10. struct O2 {
  11. public static let O2_Word_draft_mode = "draft"
  12. public static let O2_First_ID = "(0)"
  13. /// EZSE: Returns app's name
  14. public static var appDisplayName: String? {
  15. if let bundleDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
  16. return bundleDisplayName
  17. } else if let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String {
  18. return bundleName
  19. }
  20. return nil
  21. }
  22. /// EZSE: Returns app's version number
  23. public static var appVersion: String? {
  24. return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
  25. }
  26. /// EZSE: Return app's build number
  27. public static var appBuild: String? {
  28. return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
  29. }
  30. /// EZSE: Return app's bundle ID
  31. public static var appBundleID: String? {
  32. return Bundle.main.bundleIdentifier
  33. }
  34. /// EZSE: Returns both app's version and build numbers "v0.3(7)"
  35. public static var appVersionAndBuild: String? {
  36. if appVersion != nil && appBuild != nil {
  37. if appVersion == appBuild {
  38. return "v\(appVersion!)"
  39. } else {
  40. return "v\(appVersion!)(\(appBuild!))"
  41. }
  42. }
  43. return nil
  44. }
  45. /// EZSE: Return device version ""
  46. public static var deviceVersion: String {
  47. var size: Int = 0
  48. sysctlbyname("hw.machine", nil, &size, nil, 0)
  49. var machine = [CChar](repeating: 0, count: Int(size))
  50. sysctlbyname("hw.machine", &machine, &size, nil, 0)
  51. return String(cString: machine)
  52. }
  53. // MARK: - 本地缓存目录
  54. ///云盘缓存目录
  55. public static func cloudFileLocalFolder() -> URL {
  56. let manager = FileManager.default
  57. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  58. let cloudFolder = documentsURL
  59. .appendingPathComponent("O2")
  60. .appendingPathComponent("cloud")
  61. if !manager.fileExists(atPath: cloudFolder.path) {
  62. do {
  63. try manager.createDirectory(at: cloudFolder, withIntermediateDirectories: true, attributes: nil)
  64. } catch {
  65. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  66. }
  67. }
  68. return cloudFolder
  69. }
  70. ///base64缓存目录
  71. public static func base64CacheLocalFolder() -> URL {
  72. let manager = FileManager.default
  73. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  74. let base64Folder = documentsURL
  75. .appendingPathComponent("O2")
  76. .appendingPathComponent("base64")
  77. if !manager.fileExists(atPath: base64Folder.path) {
  78. do {
  79. try manager.createDirectory(at: base64Folder, withIntermediateDirectories: true, attributes: nil)
  80. } catch {
  81. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  82. }
  83. }
  84. return base64Folder
  85. }
  86. ///info缓存目录
  87. public static func inforCacheLocalFolder() -> URL {
  88. let manager = FileManager.default
  89. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  90. let inforFolder = documentsURL
  91. .appendingPathComponent("O2")
  92. .appendingPathComponent("infor")
  93. if !manager.fileExists(atPath: inforFolder.path) {
  94. do {
  95. try manager.createDirectory(at: inforFolder, withIntermediateDirectories: true, attributes: nil)
  96. } catch {
  97. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  98. }
  99. }
  100. return inforFolder
  101. }
  102. ///删除文件夹
  103. public static func deleteFolder(folder: URL) {
  104. do{
  105. try FileManager.default.removeItem(atPath: folder.path)
  106. }catch{
  107. DDLogError("删除目录失败,\(error.localizedDescription)")
  108. }
  109. }
  110. }