Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud and Local Files importing #2356

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Build.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ PRODUCT_NAME = $(TARGET_NAME)

_PRODUCT_BUNDLE_IDENTIFIER_ = $(ORG_PREFIX).$(PROJECT_NAME:lower)
PRODUCT_BUNDLE_IDENTIFIER = $(ORG_PREFIX).$(PROJECT_NAME:lower)
PRODUCT_BUNDLE_IDENTIFIER_LITE = $(ORG_PREFIX).$(PROJECT_NAME:lower).lite
//PRODUCT_BUNDLE_IDENTIFIER[configuration=Debug] = $(ORG_PREFIX).$(PROJECT_NAME:lower)-debug

APP_GROUP_IDENTIFIER = group.$(ORG_PREFIX).$(PROJECT_NAME:lower)
Expand Down
11 changes: 5 additions & 6 deletions PVLibrary/Sources/DirectoryWatcher/DirectoryWatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,13 @@ extension DirectoryWatcher {
/// Handle an imported file
public func handleImportedFile(at url: URL) {
ILOG("Handling imported file: \(url.lastPathComponent)")
guard url.startAccessingSecurityScopedResource() else {
ELOG("Failed to access security scoped resource for file: \(url.lastPathComponent)")
return
}
let secureDoc = url.startAccessingSecurityScopedResource()

defer {
url.stopAccessingSecurityScopedResource()
ILOG("Stopped accessing security scoped resource for file: \(url.lastPathComponent)")
if secureDoc {
url.stopAccessingSecurityScopedResource()
ILOG("Stopped accessing security scoped resource for file: \(url.lastPathComponent)")
}
}

let coordinator = NSFileCoordinator()
Expand Down
10 changes: 5 additions & 5 deletions PVLibrary/Sources/PVLibrary/Importer/iCloud/iCloudSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ public enum iCloudSync {
await jsonFiles.concurrentForEach { @MainActor json in
let realm = try! await Realm()
do {
guard json.startAccessingSecurityScopedResource() else {
ELOG("startAccessingSecurityScopedResource failed")
return
}

let secureDoc = json.startAccessingSecurityScopedResource()

defer {
json.stopAccessingSecurityScopedResource()
if secureDoc {
json.stopAccessingSecurityScopedResource()
}
}

var dataMaybe = FileManager.default.contents(atPath: json.path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ public extension PVGameLibraryUpdatesController {
}

private func copyFileToImports(from sourceURL: URL) {
guard sourceURL.startAccessingSecurityScopedResource() else {
ELOG("startAccessingSecurityScopedResource failed for \(sourceURL.path)")
return
let secureDoc = sourceURL.startAccessingSecurityScopedResource()
defer {
if secureDoc {
sourceURL.stopAccessingSecurityScopedResource()
}
}
defer { sourceURL.stopAccessingSecurityScopedResource() }

let destinationURL = Paths.romsImportPath.appendingPathComponent(sourceURL.lastPathComponent)

Expand Down
27 changes: 15 additions & 12 deletions Provenance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8973,7 +8973,7 @@
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = S32Z3HMYVQ;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -9025,9 +9025,10 @@
OTHER_CFLAGS = "-Wno-deprecated-declarations";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=300 -Xfrontend -warn-long-expression-type-checking=200 -DAPP_STORE -DAPPSTORE";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvos*]" = "org.provenance-emu.provenance.lite";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]" = "org.provenance-emu.provenance.lite";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = "org.provenance-emu.provenance.lite";
PRODUCT_BUNDLE_IDENTIFIER = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvos*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
PRODUCT_NAME = "Provenance Lite";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
Expand Down Expand Up @@ -9072,7 +9073,7 @@
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = S32Z3HMYVQ;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -9127,9 +9128,10 @@
);
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=300 -Xfrontend -warn-long-expression-type-checking=200 -DAPP_STORE -DAPPSTORE";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvos*]" = "org.provenance-emu.provenance.lite";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]" = "org.provenance-emu.provenance.lite";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = "org.provenance-emu.provenance.lite";
PRODUCT_BUNDLE_IDENTIFIER = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvos*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
PRODUCT_NAME = "Provenance Lite";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
Expand Down Expand Up @@ -9170,7 +9172,7 @@
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = S32Z3HMYVQ;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -9225,9 +9227,10 @@
);
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=300 -Xfrontend -warn-long-expression-type-checking=200 -DAPP_STORE -DAPPSTORE";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvos*]" = "org.provenance-emu.provenance.lite";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]" = "org.provenance-emu.provenance.lite";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = "org.provenance-emu.provenance.lite";
PRODUCT_BUNDLE_IDENTIFIER = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvos*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = "$(PRODUCT_BUNDLE_IDENTIFIER_LITE)";
PRODUCT_NAME = "Provenance Lite";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
Expand Down
9 changes: 6 additions & 3 deletions Provenance/PVAppDelegate+Open.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,17 @@ extension PVAppDelegate {
func handle(fileURL url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
let filename = url.lastPathComponent
let destinationPath = Paths.romsImportPath.appendingPathComponent(filename, isDirectory: false)

var secureDocument = false
do {
defer {
url.stopAccessingSecurityScopedResource()
if secureDocument {
url.stopAccessingSecurityScopedResource()
}

}

// Doesn't seem we need access in dev builds?
_ = url.startAccessingSecurityScopedResource()
secureDocument = url.startAccessingSecurityScopedResource()

if let openInPlace = options[.openInPlace] as? Bool, openInPlace {
try FileManager.default.copyItem(at: url, to: destinationPath)
Expand Down
8 changes: 4 additions & 4 deletions Provenance/Provenance-AppStore.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.org.provenance-emu.provenance</string>
<string>$(ICLOUD_CONTAINER_IDENTIFIER)</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
Expand All @@ -26,16 +26,16 @@
<true/>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.org.provenance-emu.provenance</string>
<string>$(ICLOUD_CONTAINER_IDENTIFIER)</string>
</array>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>group.org.provenance-emu.provenance</string>
<string>group.org.provenance-emu</string>
<string>$(APP_GROUP_IDENTIFIER).provenance</string>
<string>$(APP_GROUP_IDENTIFIER)</string>
</array>
<key>com.apple.security.assets.pictures.read-write</key>
<true/>
Expand Down
Loading