Browse Source

Sync versions

marinofaggiana 5 years ago
parent
commit
9c21245427
3 changed files with 102 additions and 29 deletions
  1. 57 28
      iOSClient/Networking/CCNetworking.m
  2. 18 1
      iOSClient/Utility/CCUtility.m
  3. 27 0
      iOSClient/Utility/NCUtility.swift

+ 57 - 28
iOSClient/Networking/CCNetworking.m

@@ -1042,6 +1042,8 @@
     NSString *tempSession = metadata.session;
     NSString *errorMessage = @"";
     BOOL isE2EEDirectory = false;
+    BOOL isIMIFile = false;
+    if ([fileName.pathExtension.lowercaseString isEqualToString:@"imi"]) isIMIFile = true;
     
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
     if (tableAccount == nil) {
@@ -1102,40 +1104,67 @@
         }
         
     } else {
-            
-        // Replace Metadata
-        metadata.date = date;
-        if (isE2EEDirectory) {
-            metadata.e2eEncrypted = true;
-        } else {
-            metadata.e2eEncrypted = false;
-        }
-        metadata.etag = etag;
-        metadata.ocId = ocId;
-        metadata.session = @"";
-        metadata.sessionError = @"";
-        metadata.sessionTaskIdentifier = k_taskIdentifierDone;
-        metadata.status = k_metadataStatusNormal;
-        
-        [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, metadata.fileName]];
-        metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata];
-        
-        NSLog(@"[LOG] Insert new upload : %@ - ocId : %@", metadata.fileName, ocId);
-
+    
         // remove tempocId and adjust the directory provider storage
-        if ([tempocId isEqualToString:[CCUtility createMetadataIDFromAccount:metadata.account serverUrl:metadata.serverUrl fileNameView:metadata.fileNameView directory:metadata.directory]]) {
+        if (isIMIFile) {
+            
+            // Update metadata tempocId
+            [[NCManageDatabase sharedInstance] setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusNormal predicate:[NSPredicate predicateWithFormat:@"ocId == %@", tempocId]];
+            
+            // Add metadata ocId
+            metadata.date = date;
+            if (isE2EEDirectory) {
+                metadata.e2eEncrypted = true;
+            } else {
+                metadata.e2eEncrypted = false;
+            }
+            metadata.etag = etag;
+            metadata.ocId = ocId;
+            metadata.session = @"";
+            metadata.sessionError = @"";
+            metadata.sessionTaskIdentifier = k_taskIdentifierDone;
+            metadata.status = k_metadataStatusNormal;
             
-            [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", tempocId]];
+            metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata];
             
-            // adjust file system Directory Provider Storage
-            if ([tempSession isEqualToString:k_upload_session_extension]) {
-                // this is for File Provider Extension [Apple Works and ... ?]
+            if (![tempocId isEqualToString:metadata.ocId]) {
                 [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], tempocId] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], metadata.ocId]];
+            }
+            
+        } else {
+            
+            // Replace Metadata
+            metadata.date = date;
+            if (isE2EEDirectory) {
+                metadata.e2eEncrypted = true;
             } else {
-                [CCUtility moveFileAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], tempocId] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], metadata.ocId]];
+                metadata.e2eEncrypted = false;
+            }
+            metadata.etag = etag;
+            metadata.ocId = ocId;
+            metadata.session = @"";
+            metadata.sessionError = @"";
+            metadata.sessionTaskIdentifier = k_taskIdentifierDone;
+            metadata.status = k_metadataStatusNormal;
+            
+            [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, metadata.fileName]];
+            metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata];
+            
+            NSLog(@"[LOG] Insert new upload : %@ - ocId : %@", metadata.fileName, ocId);
+            
+            if ([tempocId isEqualToString:[CCUtility createMetadataIDFromAccount:metadata.account serverUrl:metadata.serverUrl fileNameView:metadata.fileNameView directory:metadata.directory]]) {
+                
+                [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", tempocId]];
+                
+                // adjust file system Directory Provider Storage
+                if ([tempSession isEqualToString:k_upload_session_extension]) {
+                    // this is for File Provider Extension [Apple Works and ... ?]
+                    [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], tempocId] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], metadata.ocId]];
+                } else {
+                    [CCUtility moveFileAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], tempocId] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], metadata.ocId]];
+                }
             }
         }
-        
 #ifndef EXTENSION
         
         // EXIF
@@ -1163,7 +1192,7 @@
  #endif
         
         // Add Local or Remove from cache
-        if ([CCUtility getDisableLocalCacheAfterUpload]) {
+        if ([CCUtility getDisableLocalCacheAfterUpload] && !isIMIFile) {
             [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId] error:nil];
         } else {
             // Add Local

+ 18 - 1
iOSClient/Utility/CCUtility.m

@@ -819,8 +819,25 @@
     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
     [formatter setDateFormat:@"yy-MM-dd HH-mm-ss"];
     NSString *fileNameDate = [formatter stringFromDate:[NSDate date]];
+    NSString *returnFileName;
     
-    return [NSString stringWithFormat:@"%@ %@.%@", fileName, fileNameDate, extension];
+    if ([fileName isEqualToString:@""] && ![extension isEqualToString:@""]) {
+        returnFileName = [NSString stringWithFormat:@"%@.%@", fileNameDate, extension];
+    }
+    
+    if (![fileName isEqualToString:@""] && [extension isEqualToString:@""]) {
+        returnFileName = [NSString stringWithFormat:@"%@ %@", fileName, fileNameDate];
+    }
+    
+    if ([fileName isEqualToString:@""] && [extension isEqualToString:@""]) {
+        returnFileName = fileNameDate;
+    }
+    
+    if (![fileName isEqualToString:@""] && ![extension isEqualToString:@""]) {
+        returnFileName = [NSString stringWithFormat:@"%@ %@.%@", fileName, fileNameDate, extension];
+    }
+    
+    return returnFileName;
 }
 
 + (NSString *)createFileName:(NSString *)fileName fileDate:(NSDate *)fileDate fileType:(PHAssetMediaType)fileType keyFileName:(NSString *)keyFileName keyFileNameType:(NSString *)keyFileNameType keyFileNameOriginal:(NSString *)keyFileNameOriginal

+ 27 - 0
iOSClient/Utility/NCUtility.swift

@@ -452,6 +452,33 @@ class NCUtility: NSObject {
         }
     }
     
+    func UIColorFromRGB(rgbValue: UInt32) -> UIColor {
+        return UIColor(
+            red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
+            green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
+            blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
+            alpha: CGFloat(1.0)
+        )
+    }
+    
+    func RGBFromUIColor(uicolorValue: UIColor) -> UInt32 {
+        
+        var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
+
+        if uicolorValue.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
+
+            var colorAsUInt : UInt32 = 0
+
+            colorAsUInt += UInt32(red * 255.0) << 16 +
+                           UInt32(green * 255.0) << 8 +
+                           UInt32(blue * 255.0)
+
+            return colorAsUInt
+        }
+        
+        return 0
+    }
+    
     func IMUnzip(metadata: tableMetadata) -> Bool {
         
         // bak