mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
get image from either download dir or cache dir
This commit is contained in:
parent
b6587a2bb9
commit
7c08c38829
6 changed files with 35 additions and 16 deletions
|
|
@ -901,7 +901,7 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
}
|
||||
|
||||
+ (void)writeMediaToGallery:(NSString *)name fileType:(NSString *)fileType {
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
NSString *filePath = [LinphoneManager getValidFile:name];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:filePath]) {
|
||||
NSData* data = [NSData dataWithContentsOfFile:filePath];
|
||||
|
|
@ -1325,17 +1325,17 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog
|
|||
}
|
||||
|
||||
+ (NSData *)getCacheFileData: (NSString *)name {
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
NSString *filePath = [LinphoneManager getValidFile:name];
|
||||
return [NSData dataWithContentsOfFile:filePath];
|
||||
}
|
||||
|
||||
+ (NSURL *)getCacheFileUrl: (NSString *)name {
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
NSString *filePath = [LinphoneManager getValidFile:name];
|
||||
return [NSURL fileURLWithPath:filePath];
|
||||
}
|
||||
|
||||
+ (void)writeFileInCache:(NSData *)data name:(NSString *)name {
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
NSString *filePath =[LinphoneManager getValidFile:name];
|
||||
if (name || [name isEqualToString:@""]) {
|
||||
LOGW(@"try to write file in %@", filePath);
|
||||
}
|
||||
|
|
@ -1383,7 +1383,7 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog
|
|||
return [data writeToURL:fileURL atomically:TRUE];
|
||||
} else {
|
||||
// get the url of localfile
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
|
||||
NSString *filePath = [LinphoneManager getValidFile:fileName];
|
||||
NSURL *localURL = nil;
|
||||
if (fileName || [fileName isEqualToString:@""]) {
|
||||
LOGW(@"[writeFileInICloud] try to write file in %@", filePath);
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ typedef struct _LinphoneManagerSounds {
|
|||
+ (NSString *)documentFile:(NSString *)file;
|
||||
+ (NSString*)dataFile:(NSString*)file;
|
||||
+ (NSString*)cacheDirectory;
|
||||
+ (NSString *)getValidFile:(NSString *)name;
|
||||
// migration
|
||||
+ (NSString *)oldPreferenceFile:(NSString *)file;
|
||||
+ (NSString *)oldDataFile:(NSString *)file;
|
||||
|
|
|
|||
|
|
@ -1885,6 +1885,24 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
|
|||
return fullPath;
|
||||
}
|
||||
|
||||
+ (NSString *)getValidFile:(NSString *)name {
|
||||
// At present, downlaod_dir is .../Library/Images, but during sometimes download_dir was .../Library/Caches
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
NSString *objcGroupdId = [NSString stringWithCString:kLinphoneMsgNotificationAppGroupId.UTF8String encoding:[NSString defaultCStringEncoding]];
|
||||
NSURL *basePath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:objcGroupdId];
|
||||
NSString * fullPath = [[basePath path] stringByAppendingString:@"/Library/Caches/"];
|
||||
fullPath = [fullPath stringByAppendingPathComponent:name];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
|
||||
[[NSFileManager defaultManager] copyItemAtPath:fullPath toPath:filePath error:nil];
|
||||
}
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
+ (NSString *)oldPreferenceFile:(NSString *)file {
|
||||
// migration
|
||||
LinphoneFactory *factory = linphone_factory_get();
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@
|
|||
ms_free(cPath);
|
||||
[LinphoneManager setValueInMessageAppData:filePath forKey:@"encryptedfile" inMessage:self.message];
|
||||
} else {
|
||||
filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
|
||||
filePath = [LinphoneManager getValidFile:fileName];
|
||||
}
|
||||
}
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
||||
|
|
@ -435,7 +435,7 @@
|
|||
if (!filePath) {
|
||||
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:self.message];
|
||||
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
|
||||
filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:(localVideo?:localFile)];
|
||||
filePath = [LinphoneManager getValidFile:(localVideo?:localFile)];
|
||||
}
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
||||
|
|
@ -492,7 +492,7 @@
|
|||
return;
|
||||
}
|
||||
NSString *name = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
|
||||
if([[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name]]) {
|
||||
if([[NSFileManager defaultManager] fileExistsAtPath:[LinphoneManager getValidFile:name]]) {
|
||||
[view openFileWithURL:[ChatConversationView getCacheFileUrl:name]];
|
||||
} else {
|
||||
[view openFileWithURL:[view getICloudFileUrl:name]];
|
||||
|
|
@ -540,16 +540,16 @@
|
|||
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:self.message];
|
||||
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
|
||||
NSString *imageName = NULL;
|
||||
if (localImage && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localImage]]) {
|
||||
if (localImage && [[NSFileManager defaultManager] fileExistsAtPath:[LinphoneManager getValidFile:localImage]]) {
|
||||
imageName = localImage;
|
||||
} else if (localFile && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localFile]]) {
|
||||
} else if (localFile && [[NSFileManager defaultManager] fileExistsAtPath:[LinphoneManager getValidFile:localFile]]) {
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"] || [localFile hasSuffix:@"jpg"] || [localFile hasSuffix:@"png"]) {
|
||||
imageName = localFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (imageName) {
|
||||
NSData *data = [NSData dataWithContentsOfFile:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:imageName]];
|
||||
NSData *data = [NSData dataWithContentsOfFile:[LinphoneManager getValidFile:imageName]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
if (image)
|
||||
[view setImage:image];
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@
|
|||
NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)];
|
||||
NSString *filePath = [encrptedFilePaths valueForKey:name];
|
||||
if (filePath == NULL) {
|
||||
filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
filePath = [LinphoneManager getValidFile:name];
|
||||
}
|
||||
[newfileContext addObject:[NSData dataWithContentsOfFile:filePath] name:name type:[NSString stringWithUTF8String:linphone_content_get_type(content)]];
|
||||
}
|
||||
|
|
@ -441,7 +441,7 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 44;
|
|||
NSString *type = [NSString stringWithUTF8String:linphone_content_get_type(content)];
|
||||
NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)];
|
||||
if (!filePath) {
|
||||
filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
filePath = [LinphoneManager getValidFile:name];
|
||||
}
|
||||
|
||||
UIImage *image = nil;
|
||||
|
|
@ -502,7 +502,7 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 44;
|
|||
NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)];
|
||||
NSString *filePath=[encrptedFilePaths valueForKey:name];
|
||||
if (filePath == NULL) {
|
||||
filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
filePath = [LinphoneManager getValidFile:name];
|
||||
}
|
||||
|
||||
image = [UIChatBubbleTextCell getImageFromContent:content filePath:filePath];
|
||||
|
|
@ -562,7 +562,7 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 44;
|
|||
|
||||
CGSize originalImageSize = CGSizeMake(230, 50);
|
||||
if (!filePath) {
|
||||
filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
|
||||
filePath = [LinphoneManager getValidFile:fileName];
|
||||
}
|
||||
if (localFile) {
|
||||
UIImage *image = nil;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
} else {
|
||||
if (_filePath == NULL) {
|
||||
NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)];
|
||||
_filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
_filePath = [LinphoneManager getValidFile:name];
|
||||
}
|
||||
UIImage *image = [UIChatBubbleTextCell getImageFromContent:content filePath:_filePath];
|
||||
[self setImage:image];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue