From 365c1d14fafb98f18312da6f256c6c0fe883bf2d Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sun, 1 Sep 2019 13:44:45 -0400 Subject: [PATCH] precise version --- RSwitch.xcodeproj/project.pbxproj | 4 ++-- RSwitch/Base.lproj/Main.storyboard | 2 +- RSwitch/Swift/Utils/RVersions.swift | 39 ++++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/RSwitch.xcodeproj/project.pbxproj b/RSwitch.xcodeproj/project.pbxproj index 30a6315..31ff4b8 100644 --- a/RSwitch.xcodeproj/project.pbxproj +++ b/RSwitch.xcodeproj/project.pbxproj @@ -502,7 +502,7 @@ "$(PROJECT_DIR)/RSwitch/ObjC/ProcInfo", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 1.4.1; + MARKETING_VERSION = 1.4.2; PRODUCT_BUNDLE_IDENTIFIER = is.rud.bob.RSwitch; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -535,7 +535,7 @@ "$(PROJECT_DIR)/RSwitch/ObjC/ProcInfo", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 1.4.1; + MARKETING_VERSION = 1.4.2; PRODUCT_BUNDLE_IDENTIFIER = is.rud.bob.RSwitch; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/RSwitch/Base.lproj/Main.storyboard b/RSwitch/Base.lproj/Main.storyboard index cd6ebb1..3e57839 100644 --- a/RSwitch/Base.lproj/Main.storyboard +++ b/RSwitch/Base.lproj/Main.storyboard @@ -741,7 +741,7 @@ -RSwitch v1.4.1 +RSwitch v1.4.2 Copyright © 2019 Bob Rudis diff --git a/RSwitch/Swift/Utils/RVersions.swift b/RSwitch/Swift/Utils/RVersions.swift index c8affdb..16a186c 100644 --- a/RSwitch/Swift/Utils/RVersions.swift +++ b/RSwitch/Swift/Utils/RVersions.swift @@ -18,6 +18,8 @@ class RVersions { static let macos_r_framework = "/Library/Frameworks/R.framework/Versions" // Where the official R installs go + static let replRegex = try!NSRegularExpression(pattern: "[[:alpha:][:space:]\"#_]+", options: NSRegularExpression.Options.caseInsensitive) + static func currentVersionTarget() -> String { // get where Current points to @@ -36,6 +38,41 @@ class RVersions { } + static func preciseVersion(versionPath : String) -> String { + + let actualPath = (versionPath.starts(with: "/") ? "" : RVersions.macos_r_framework + "/" ) + + versionPath + "/Headers/Rversion.h" + var out = "" + + if (FileManager.default.fileExists(atPath:actualPath)) { + + do { + + let versionHeader = (try NSString(contentsOfFile: actualPath, encoding: String.Encoding.utf8.rawValue)) as String + + let majMin = versionHeader + .split(separator: "\n") + .filter{ + $0.contains("R_MAJOR") || $0.contains("R_MINOR") + } + .map{ + replRegex.stringByReplacingMatches(in: String($0), + options: [], + range: NSMakeRange(0, $0.count), + withTemplate: "") + } + + out = " (" + majMin[0] + "." + majMin[1] + ")" + + } catch { + } + + } + + return(out) + + } + static func hasRBinary(versionPath : String) -> Bool { return( FileManager.default.fileExists( @@ -70,7 +107,7 @@ class RVersions { let complete = RVersions.hasRBinary(versionPath: version) let keynum = (i < 10) ? String(i) : "" let item = NSMenuItem( - title: complete ? version : version + " (incomplete)", + title: complete ? version + RVersions.preciseVersion(versionPath: version) : version + " (incomplete)", action: complete ? handler : nil, keyEquivalent: complete ? keynum : "" )