mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: use temporary folder for lldb if support is locked
This commit is contained in:
@@ -27,19 +27,23 @@ using namespace std;
|
|||||||
- (instancetype) init:(NSString *) name {
|
- (instancetype) init:(NSString *) name {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
[self createDB:name];
|
bool status = [self createDB:name];
|
||||||
|
if (!status) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)createDB:(NSString *) path {
|
-(bool)createDB:(NSString *) path {
|
||||||
leveldb::Options options;
|
leveldb::Options options;
|
||||||
options.create_if_missing = true;
|
options.create_if_missing = true;
|
||||||
leveldb::Status status = leveldb::DB::Open(options, [path UTF8String], &self->db);
|
leveldb::Status status = leveldb::DB::Open(options, [path UTF8String], &self->db);
|
||||||
if (false == status.ok()) {
|
if (false == status.ok()) {
|
||||||
NSLog(@"ERROR: Unable to open/create database.");
|
NSLog(@"ERROR: Unable to open/create database: %s", status.ToString().c_str());
|
||||||
std::cout << status.ToString();
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(NSArray *)keys:(NSString *)key {
|
-(NSArray *)keys:(NSString *)key {
|
||||||
|
|||||||
@@ -31,19 +31,36 @@ public class DB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var dbPath: URL
|
|
||||||
|
|
||||||
let fileManager = FileManager.default
|
let fileManager = FileManager.default
|
||||||
let appSupportURL = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
|
let supportPath = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!.appendingPathComponent("Stats")
|
||||||
let folder = appSupportURL.appendingPathComponent("Stats")
|
let tmpPath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("Stats")
|
||||||
do {
|
|
||||||
try fileManager.createDirectory(at: folder, withIntermediateDirectories: true, attributes: nil)
|
try? fileManager.createDirectory(at: supportPath, withIntermediateDirectories: true, attributes: nil)
|
||||||
dbPath = folder.appendingPathComponent("lldb")
|
try? fileManager.createDirectory(at: tmpPath, withIntermediateDirectories: true, attributes: nil)
|
||||||
} catch {
|
|
||||||
dbPath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("Stats").appendingPathComponent("lldb")
|
var dbURL: URL?
|
||||||
|
var tmpURL: URL?
|
||||||
|
|
||||||
|
if let values = try? supportPath.resourceValues(forKeys: [.isDirectoryKey]), values.isDirectory ?? false {
|
||||||
|
dbURL = supportPath.appendingPathComponent("lldb")
|
||||||
|
}
|
||||||
|
if let values = try? tmpPath.resourceValues(forKeys: [.isDirectoryKey]), values.isDirectory ?? false {
|
||||||
|
tmpURL = tmpPath.appendingPathComponent("lldb")
|
||||||
|
}
|
||||||
|
if dbURL == nil && tmpURL != nil {
|
||||||
|
dbURL = tmpURL
|
||||||
}
|
}
|
||||||
|
|
||||||
self.lldb = LLDB(dbPath.path)
|
if let url = dbURL, let lldb = LLDB(url.path) {
|
||||||
|
self.lldb = lldb
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if let url = tmpURL, let lldb = LLDB(url.path) {
|
||||||
|
self.lldb = lldb
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("ERROR INITIALIZE DB")
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
|||||||
Reference in New Issue
Block a user