Merge branch 'charlesmchen/saeVsFileTypes2_'

pull/1/head
Matthew Chen 7 years ago
commit 0ba93a1a09

@ -12,7 +12,9 @@
#import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
#import <AxolotlKit/PreKeyBundle.h>
#import <SignalMessaging/AttachmentSharing.h>
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/UIImage+OWS.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
@ -95,15 +97,24 @@ NS_ASSUME_NONNULL_BEGIN
[DebugUIMisc sendUnencryptedDatabase:thread];
}]];
}
[items addObject:[OWSTableItem
subPageItemWithText:@"Export Backup w/o Password"
actionBlock:^(UIViewController *viewController) {
OWSBackupExportViewController *backupViewController =
[OWSBackupExportViewController new];
[backupViewController exportBackup:thread skipPassword:YES];
[viewController.navigationController pushViewController:backupViewController
animated:YES];
}]];
[items addObject:[OWSTableItem subPageItemWithText:@"Export Backup w/o Password"
actionBlock:^(UIViewController *viewController) {
OWSBackupExportViewController *backupViewController =
[OWSBackupExportViewController new];
[backupViewController exportBackup:thread skipPassword:YES];
[viewController.navigationController
pushViewController:backupViewController
animated:YES];
}]];
#ifdef DEBUG
[items addObject:[OWSTableItem subPageItemWithText:@"Share UIImage"
actionBlock:^(UIViewController *viewController) {
UIImage *image =
[UIImage imageWithColor:UIColor.redColor size:CGSizeMake(1.f, 1.f)];
[AttachmentSharing showShareUIForUIImage:image];
}]];
#endif
return [OWSTableSection sectionWithTitle:self.name items:items];
}
@ -175,9 +186,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)sendEncryptedDatabase:(TSThread *)thread
{
NSString *temporaryDirectory = NSTemporaryDirectory();
NSString *fileName = [[NSUUID UUID].UUIDString stringByAppendingString:@".sqlite"];
NSString *filePath = [temporaryDirectory stringByAppendingPathComponent:fileName];
NSString *filePath = [OWSFileSystem temporaryFilePathWithFileExtension:@"sqlite"];
NSString *fileName = filePath.lastPathComponent;
__block BOOL success;
[TSStorageManager.sharedManager.newDatabaseConnection
@ -212,9 +222,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)sendUnencryptedDatabase:(TSThread *)thread
{
NSString *temporaryDirectory = NSTemporaryDirectory();
NSString *fileName = [[NSUUID UUID].UUIDString stringByAppendingString:@".sqlite"];
NSString *filePath = [temporaryDirectory stringByAppendingPathComponent:fileName];
NSString *filePath = [OWSFileSystem temporaryFilePathWithFileExtension:@"sqlite"];
NSString *fileName = filePath.lastPathComponent;
NSError *error = [TSStorageManager.sharedManager.newDatabaseConnection backupToPath:filePath];
if (error) {

@ -225,9 +225,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)createTempDatabaseFilePath
{
NSString *temporaryDirectory = NSTemporaryDirectory();
NSString *filename = [[NSUUID UUID].UUIDString stringByAppendingString:@".sqlite"];
NSString *databaseFilePath = [temporaryDirectory stringByAppendingPathComponent:filename];
NSString *databaseFilePath = [OWSFileSystem temporaryFilePathWithFileExtension:@"sqlite"];
DDLogInfo(@"%@ databaseFilePath: %@", self.logTag, databaseFilePath);
[DDLog flushLog];

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
@class TSAttachmentStream;
@ -12,4 +12,8 @@
+ (void)showShareUIForText:(NSString *)text;
#ifdef DEBUG
+ (void)showShareUIForUIImage:(UIImage *)image;
#endif
@end

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "AttachmentSharing.h"
@ -35,6 +35,17 @@
]];
}
#ifdef DEBUG
+ (void)showShareUIForUIImage:(UIImage *)image
{
OWSAssert(image);
[AttachmentSharing showShareUIForActivityItems:@[
image,
]];
}
#endif
+ (void)showShareUIForActivityItems:(NSArray *)activityItems
{
OWSAssert(activityItems);

@ -1,10 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "DataSource.h"
#import "MIMETypeUtil.h"
#import "NSData+Image.h"
#import "OWSFileSystem.h"
NS_ASSUME_NONNULL_BEGIN
@ -173,9 +174,7 @@ NS_ASSUME_NONNULL_BEGIN
@synchronized(self)
{
if (!self.cachedFilePath) {
NSString *dirPath = NSTemporaryDirectory();
NSString *fileName = [[[NSUUID UUID] UUIDString] stringByAppendingPathExtension:self.fileExtension];
NSString *filePath = [dirPath stringByAppendingPathComponent:fileName];
NSString *filePath = [OWSFileSystem temporaryFilePathWithFileExtension:self.fileExtension];
if ([self writeToPath:filePath]) {
self.cachedFilePath = filePath;
} else {

@ -29,6 +29,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSArray<NSString *> *_Nullable)allFilesInDirectoryRecursive:(NSString *)dirPath error:(NSError **)error;
+ (NSString *)temporaryFilePath;
+ (NSString *)temporaryFilePathWithFileExtension:(NSString *_Nullable)fileExtension;
// Returns nil on failure.
+ (nullable NSString *)writeDataToTemporaryFile:(NSData *)data fileExtension:(NSString *_Nullable)fileExtension;

@ -166,16 +166,28 @@ NS_ASSUME_NONNULL_BEGIN
return filePaths;
}
+ (nullable NSString *)writeDataToTemporaryFile:(NSData *)data fileExtension:(NSString *_Nullable)fileExtension
+ (NSString *)temporaryFilePath
{
OWSAssert(data);
return [self temporaryFilePathWithFileExtension:nil];
}
+ (NSString *)temporaryFilePathWithFileExtension:(NSString *_Nullable)fileExtension
{
NSString *temporaryDirectory = NSTemporaryDirectory();
NSString *tempFileName = NSUUID.UUID.UUIDString;
if (fileExtension.length > 0) {
tempFileName = [[tempFileName stringByAppendingString:@"."] stringByAppendingString:fileExtension];
}
NSString *tempFilePath = [temporaryDirectory stringByAppendingPathComponent:tempFileName];
return tempFilePath;
}
+ (nullable NSString *)writeDataToTemporaryFile:(NSData *)data fileExtension:(NSString *_Nullable)fileExtension
{
OWSAssert(data);
NSString *tempFilePath = [self temporaryFilePathWithFileExtension:fileExtension];
NSError *error;
BOOL success = [data writeToFile:tempFilePath options:NSDataWritingAtomic error:&error];
if (!success || error) {

@ -608,6 +608,19 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
} else {
fulfill((itemUrl: url, utiType: srcUtiType))
}
} else if let image = value as? UIImage {
if let data = UIImagePNGRepresentation(image) {
let tempFilePath = OWSFileSystem.temporaryFilePath(withFileExtension:"png")
do {
let url = NSURL.fileURL(withPath:tempFilePath)
try data.write(to: url, options: .atomicWrite)
fulfill((url, srcUtiType))
} catch {
reject(ShareViewControllerError.assertionError(description: "couldn't write UIImage: \(String(describing: error))"))
}
} else {
reject(ShareViewControllerError.assertionError(description: "couldn't convert UIImage to PNG: \(String(describing: error))"))
}
} else {
// It's unavoidable that we may sometimes receives data types that we
// don't know how to handle.

Loading…
Cancel
Save