Skip to content

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

delete all bool

roryclear12a7d456a018
diff --git a/clearcam/FileServer.m b/clearcam/FileServer.m
index 991f934..f162fda 100644
--- a/clearcam/FileServer.m
+++ b/clearcam/FileServer.m
@@ -24,11 +24,6 @@
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.context = appDelegate.persistentContainer.viewContext;
-
- //TODO REMOVE THIS
- //[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LastDeletedDayIndex"];
- //[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LastDeletedSegmentIndex"];
- //[[NSUserDefaults standardUserDefaults] synchronize];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
@@ -42,26 +37,24 @@
return;
}
- for (NSString *file in contents) {
- continue;
- if ([file hasPrefix:@"batch_req"]) continue;
- NSString *filePath = [documentsPath stringByAppendingPathComponent:file];
- BOOL success = [fileManager removeItemAtPath:filePath error:&error];
+ if ([SettingsManager sharedManager].delete_on_launch) {
+ for (NSString *file in contents) {
+ if ([file hasPrefix:@"batch_req"]) continue;
+ NSString *filePath = [documentsPath stringByAppendingPathComponent:file];
+ NSError *error = nil;
+ BOOL success = [fileManager removeItemAtPath:filePath error:&error];
- if (!success) {
- NSLog(@"Failed to delete %@: %@", file, error.localizedDescription);
- } else {
- NSLog(@"Deleted: %@", file);
+ if (!success) {
+ NSLog(@"Failed to delete %@: %@", file, error.localizedDescription);
+ } else {
+ NSLog(@"Deleted: %@", file);
+ }
}
+ [self deleteAllDayEntitiesInContext:self.context];
+ [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LastDeletedDayIndex"];
+ [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LastDeletedSegmentIndex"];
+ [[NSUserDefaults standardUserDefaults] synchronize];
}
-
- ///TODO
-
- // Save a new string
- NSLog(@"core data segments?:");
- //[self deleteAllDayEntitiesInContext:self.context]; //to delete all, not thread safe yet!
- // Fetch all saved strings
- // coredata stuff
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
self.segment_length = 60;
diff --git a/clearcam/SettingsManager.h b/clearcam/SettingsManager.h
index c9a32c4..5203a39 100644
--- a/clearcam/SettingsManager.h
+++ b/clearcam/SettingsManager.h
@@ -5,6 +5,7 @@
@property (nonatomic, strong) NSArray<NSNumber *> *yolo_indexes;
@property (nonatomic, strong) NSArray<NSNumber *> *events;
@property (nonatomic, strong) NSDictionary *alerts;
+@property (nonatomic, assign) BOOL *delete_on_launch;
+ (instancetype)sharedManager;
diff --git a/clearcam/SettingsManager.m b/clearcam/SettingsManager.m
index dd558e9..0cc0078 100644
--- a/clearcam/SettingsManager.m
+++ b/clearcam/SettingsManager.m
@@ -16,6 +16,7 @@
if (self) {
[self loadYoloIndexes];
[self loadEvents];
+ [self loadDeleteOnLaunch];
}
return self;
}
@@ -46,10 +47,6 @@
for (int i = 0; i < 80; i++) { //todo unhardcode 80
[defaultIndexes addObject:@(i)];
}
-
- /*
- NSArray<NSNumber *> *defaultIndexes = @[@0, @1, @2, @3, @5, @7]; //vehicles+people preset for now (person, bicycle, car, motorcycle, bus, truck)
- */
return [defaultIndexes copy];
}
@@ -64,16 +61,37 @@
- (NSArray<NSNumber *> *)generateDefaultEvents {
NSMutableArray<NSNumber *> *defaultEvents = [NSMutableArray array];
- [defaultEvents addObject:@0]; // 1 person for now // todo, default will be none, +/- person will be a bool
- [defaultEvents addObject:@2];
- [defaultEvents addObject:@63]; //laptop for now
+ //[defaultEvents addObject:@0]; // 1 person for now
+ //[defaultEvents addObject:@2];
+ [defaultEvents addObject:@63]; // laptop for now
return [defaultEvents copy];
}
-- (NSDictionary*)generateDefaultAlerts { //todo, alerts events, min-max all in one object?
+- (NSDictionary*)generateDefaultAlerts {
NSMutableDictionary *defaultAlerts = [[NSMutableDictionary alloc] init];
- defaultAlerts[@2] = 0; //just min 0 for now
+ defaultAlerts[@2] = @0; // just min 0 for now
return [defaultAlerts copy];
}
+// New property: delete_on_launch
+- (void)saveDeleteOnLaunch {
+ [[NSUserDefaults standardUserDefaults] setBool:self.delete_on_launch forKey:@"delete_on_launch"];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+}
+
+- (void)loadDeleteOnLaunch {
+ if ([[NSUserDefaults standardUserDefaults] objectForKey:@"delete_on_launch"] == nil) {
+ NSLog(@"no delete_on_launch value found");
+ self.delete_on_launch = NO;
+ } else {
+ self.delete_on_launch = [[NSUserDefaults standardUserDefaults] boolForKey:@"delete_on_launch"];
+ }
+}
+
+- (void)updateDeleteOnLaunch:(BOOL)value {
+ self.delete_on_launch = value;
+ [self saveDeleteOnLaunch];
+}
+
+
@end
diff --git a/clearcam/ViewController.m b/clearcam/ViewController.m
index 9379ec6..1bde5c8 100644
--- a/clearcam/ViewController.m
+++ b/clearcam/ViewController.m
@@ -52,7 +52,7 @@
@property (nonatomic, strong) NSString *dayFolderName;
@property (nonatomic, strong) Resolution *res;
-#define MIN_FREE_SPACE_MB 500 //threshold to start deleting
+#define MIN_FREE_SPACE_MB 3000 //threshold to start deleting
@end
@@ -504,6 +504,7 @@ NSMutableDictionary *classColorMap;
@try {
if((double)[[[[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil] objectForKey:NSFileSystemFreeSize] unsignedLongLongValue] / (1024.0 * 1024.0) < MIN_FREE_SPACE_MB){
+ NSLog(@"deleting stuff");
while ((double)[[[[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil] objectForKey:NSFileSystemFreeSize] unsignedLongLongValue] / (1024.0 * 1024.0) < MIN_FREE_SPACE_MB + 500) {
NSLog(@"NOT ENOUGH SPACE!");