macOS - Adds Full Disk Access check to client launch

This commit is contained in:
Moisie2000 2021-12-30 16:25:20 +00:00
parent a57be36ec1
commit 7b4f15bf70
2 changed files with 88 additions and 0 deletions

View File

@ -143,6 +143,7 @@ HRESULT ModifyPrivilege(
#ifdef __APPLE__
extern "C" void bring_to_foreground();
extern "C" void remove_login_item();
extern "C" void check_full_disk_access();
#endif
class TheFrame : public wxFrame {
@ -512,6 +513,10 @@ bool MyApp::OnInit()
timer=new MyTimer;
timer->Start(1000);
#ifdef __APPLE__
check_full_disk_access();
#endif
}
else if(cmd==wxT("settings"))
{

View File

@ -49,3 +49,86 @@ extern "C" void remove_login_item()
}
}
}
// check_full_disk_access() based on MacPaw's PermissionsKit
// https://github.com/MacPaw/PermissionsKit
// PermissionsKit Copyright (c) 2018 MacPaw
// MIT License
//
extern "C" void check_full_disk_access()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (@available(macOS 10.14, *))
{
// Full Disk Access only required for macOS 10.14+
NSLog(@"[macOS] macOS 10.14 or higher installed - need to check for Full Disk Access");
} else {
NSLog(@"[macOS] macOS 10.13 or lower installed - no need to check for Full Disk Access");
return;
}
// Check for file access
NSFileManager *filemanager = [NSFileManager defaultManager];
NSString *path;
BOOL fileExists;
path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Safari/CloudTabs.db"];
fileExists = [filemanager fileExistsAtPath:path];
if (fileExists)
{
NSLog(@"[macOS] ~/Library/Safari/CloudTabs.db exists - use for Full Disk Access check");
}
else
{
path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Safari/Bookmarks.plist"];
fileExists = [filemanager fileExistsAtPath:path];
if (fileExists)
{
NSLog(@"[macOS] ~/Library/Safari/Bookmarks.plist exists - use for Full Disk Access check");
}
else
{
path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Accounts/Accounts4.sqlite"];
fileExists = [filemanager fileExistsAtPath:path];
if (fileExists)
{
NSLog(@"[macOS] ~/Library/Accounts/Accounts4.sqlite exists - use for Full Disk Access check");
}
}
}
NSData* data = [NSData dataWithContentsOfFile:path];
NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSAlertStyleCritical];
if (data != nil && fileExists)
{
// Full Disk Access Allowed
NSLog(@"[macOS] Full Disk Access Allowed");
}
else
{
if (data == nil && fileExists)
{
// Full Disk Access Denied
NSLog(@"[macOS] Full Disk Access Denied");
[alert setMessageText:@"Full Disk Access Denied"];
[alert setInformativeText:@"UrBackup needs Full Disk Access to operate.\n\nPlease use System Preferences to allow the UrBackup Client application Full Disk Access.\n\nSystem Preferences will open when you press OK."];
}
else
{
// Cannot determine Full Disk Access status
NSLog(@"[macOS] Full Disk Access cannot be determined");
[alert setMessageText:@"Cannot determine Full Disk Access status"];
[alert setInformativeText:@"UrBackup needs Full Disk Access to operate.\n\nPlease try using System Preferences to allow the UrBackup Client application Full Disk Access.\n\nSystem Preferences will open when you press OK."];
}
// Display dialogue
[alert runModal];
// Open System Preferences
NSWorkspace *workspace = [[NSWorkspace alloc] init];
[workspace openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"]];
}
[pool drain];
return;
}