Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

remove deletion for now

rorycleara9e3c426c35e
diff --git a/clearcam/ViewController.m b/clearcam/ViewController.m
index e497e8c..6fe700e 100644
--- a/clearcam/ViewController.m
+++ b/clearcam/ViewController.m
@@ -514,112 +514,8 @@ NSMutableDictionary *classColorMap;
- (void)ensureFreeDiskSpace {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
- NSFileManager *fileManager = [NSFileManager defaultManager];
- NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
double freeSpace = (double)[[[[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil] objectForKey:NSFileSystemFreeSize] unsignedLongLongValue] / (1024.0 * 1024.0 * 1024.0);
NSLog(@"Current free space: %.2f GB", freeSpace);
-
- while (freeSpace < (MIN_FREE_SPACE_MB / 1024.0)) {
- NSError *error;
- NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentsPath error:&error];
- if (error) {
- NSLog(@"Error retrieving contents of Documents directory: %@", error.localizedDescription);
- return;
- }
-
- NSMutableArray *folders = [NSMutableArray array];
- for (NSString *item in contents) {
- NSString *fullPath = [documentsPath stringByAppendingPathComponent:item];
- BOOL isDirectory;
- if ([fileManager fileExistsAtPath:fullPath isDirectory:&isDirectory] && isDirectory) {
- [folders addObject:fullPath];
- }
- }
-
- [folders sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
-
- BOOL deletedSomething = NO;
- for (NSString *folderPath in folders) {
- NSString *segmentsFilePath = [folderPath stringByAppendingPathComponent:@"segments.txt"];
-
- if (![fileManager fileExistsAtPath:segmentsFilePath]) {
- NSLog(@"No segments.txt found in folder: %@", folderPath);
- continue;
- }
-
- NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:segmentsFilePath];
- if (!fileHandle) {
- NSLog(@"Failed to open segments.txt in folder: %@", folderPath);
- continue;
- }
-
- NSData *data = [fileHandle readDataToEndOfFile];
- if (!data) {
- NSLog(@"Failed to read data from segments.txt in folder: %@", folderPath);
- [fileHandle closeFile];
- continue;
- }
-
- NSError *jsonError;
- NSMutableArray *segmentsArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonError];
- if (jsonError || ![segmentsArray isKindOfClass:[NSMutableArray class]] || segmentsArray.count == 0) {
- NSLog(@"Error parsing segments.txt in folder %@: %@", folderPath, jsonError.localizedDescription);
- [fileHandle closeFile];
- continue;
- }
-
- NSDictionary *firstEntry = segmentsArray[0];
- NSString *fileToDelete = firstEntry[@"url"];
- if (!fileToDelete) {
- NSLog(@"No 'url' field found in the first entry of segments.txt in folder %@.", folderPath);
- [fileHandle closeFile];
- continue;
- }
-
- NSString *filePath = [documentsPath stringByAppendingPathComponent:fileToDelete];
- if ([fileManager fileExistsAtPath:filePath]) {
- NSLog(@"Deleting file: %@", filePath);
- [fileManager removeItemAtPath:filePath error:&error];
- if (error) {
- NSLog(@"Error deleting file: %@", error.localizedDescription);
- [fileHandle closeFile];
- continue;
- }
-
- [segmentsArray removeObjectAtIndex:0];
- NSData *updatedSegmentsData = [NSJSONSerialization dataWithJSONObject:segmentsArray options:NSJSONWritingPrettyPrinted error:&error];
- if (error) {
- NSLog(@"Error serializing updated segments.txt in folder %@: %@", folderPath, error.localizedDescription);
- [fileHandle closeFile];
- continue;
- }
-
- [fileHandle truncateFileAtOffset:0];
- [fileHandle seekToFileOffset:0];
- [fileHandle writeData:updatedSegmentsData];
- [fileHandle closeFile];
-
- deletedSomething = YES;
-
- freeSpace = (double)[[[[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil] objectForKey:NSFileSystemFreeSize] unsignedLongLongValue] / (1024.0 * 1024.0 * 1024.0);
- NSLog(@"New free space: %.2f GB", freeSpace);
-
- if (freeSpace >= (MIN_FREE_SPACE_MB / 1024.0)) {
- break;
- }
- } else {
- NSLog(@"File to delete does not exist: %@", filePath);
- [fileHandle closeFile];
- continue;
- }
- }
-
- if (!deletedSomething) {
- NSLog(@"No more deletable files found.");
- break;
- }
- }
});
}