-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for setting shared folder and hard disk location
Needs testing when distributed by Mac app store
- Loading branch information
*
committed
May 5, 2023
1 parent
99c3ed6
commit a67f096
Showing
11 changed files
with
379 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Data+Bookmark.swift | ||
// virtualOS | ||
// | ||
// Created by Jahn Bertsch on 24.03.23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Bookmark { | ||
enum BookmarkType { | ||
case hardDisk | ||
case sharedFolder | ||
} | ||
|
||
fileprivate static var accessedURLs: [BookmarkType: URL] = [:] | ||
|
||
static func createBookmarkData(fromUrl url: URL) -> Data? { | ||
if let bookmarkData = try? url.bookmarkData(options: .withSecurityScope, relativeTo: nil) { | ||
return bookmarkData | ||
} | ||
return nil | ||
} | ||
|
||
static func startAccess(data: Data?, forType key: BookmarkType) -> URL? { | ||
var bookmarkDataIsStale = false | ||
if let bookmarkData = data, | ||
let bookmarkURL = try? URL(resolvingBookmarkData: bookmarkData, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &bookmarkDataIsStale), | ||
!bookmarkDataIsStale | ||
{ | ||
// stop accessing previous resource | ||
if let previousURL = accessedURLs[key], | ||
previousURL != bookmarkURL | ||
{ | ||
previousURL.stopAccessingSecurityScopedResource() | ||
} | ||
|
||
if accessedURLs[key] == bookmarkURL { | ||
// resource already accessed, do nothing | ||
} else { | ||
// start access resource | ||
if !bookmarkURL.startAccessingSecurityScopedResource() { | ||
// access failed | ||
bookmarkURL.stopAccessingSecurityScopedResource() | ||
return nil | ||
} | ||
accessedURLs[key] = bookmarkURL | ||
} | ||
return bookmarkURL | ||
} | ||
|
||
return nil | ||
} | ||
|
||
static func stopAccess(url: URL, forKey key: BookmarkType) { | ||
url.stopAccessingSecurityScopedResource() | ||
Self.accessedURLs[key] = nil | ||
} | ||
|
||
static func stopAllAccess() { | ||
for (_, accessedURL) in accessedURLs { | ||
accessedURL.stopAccessingSecurityScopedResource() | ||
} | ||
Self.accessedURLs = [:] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.