forked from organicmaps/organicmaps
[ios] Added "Do not backup to iCloud" attribute for all downloaded map files
This commit is contained in:
parent
c5ad7cb730
commit
2f8c21c44b
2 changed files with 78 additions and 0 deletions
|
@ -4,17 +4,65 @@
|
|||
#import "Preferences.h"
|
||||
#import "LocationManager.h"
|
||||
|
||||
#include <sys/xattr.h>
|
||||
|
||||
#include "../../../platform/settings.hpp"
|
||||
|
||||
@implementation MapsAppDelegate
|
||||
|
||||
@synthesize m_window;
|
||||
@synthesize m_mapViewController;
|
||||
@synthesize m_locationManager;
|
||||
|
||||
#define V2_0_TAG "2.0"
|
||||
#define FIRST_LAUNCH_KEY "FirstLaunchOnVersion"
|
||||
|
||||
+ (MapsAppDelegate *) theApp
|
||||
{
|
||||
return [[UIApplication sharedApplication] delegate];
|
||||
}
|
||||
|
||||
- (void) onFirstLaunchCheck
|
||||
{
|
||||
// Called only for V1.0.1 -> V2.0 upgrade
|
||||
string v;
|
||||
if (!Settings::Get(FIRST_LAUNCH_KEY, v))
|
||||
{
|
||||
// Scan all files in the Documents directory and do necessary actions with them
|
||||
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString * documentsDirectoryPath = [paths objectAtIndex:0];
|
||||
NSFileManager * fileManager = [NSFileManager defaultManager];
|
||||
|
||||
// Delete old travel guide temporary files
|
||||
[fileManager removeItemAtPath:[documentsDirectoryPath stringByAppendingPathComponent:@"index.stamp"] error:nil];
|
||||
[fileManager removeItemAtPath:[documentsDirectoryPath stringByAppendingPathComponent:@"index.idx"] error:nil];
|
||||
|
||||
// Delete ".downloading" and ".resume" files and disable iCloud backup for downloaded ".mwm" maps
|
||||
NSArray * files = [fileManager contentsOfDirectoryAtPath:documentsDirectoryPath error:nil];
|
||||
for (NSInteger i = 0; i < [files count]; ++i)
|
||||
{
|
||||
NSString * fileName = [files objectAtIndex:i];
|
||||
|
||||
if ([fileName rangeOfString:@".downloading"].location != NSNotFound)
|
||||
[fileManager removeItemAtPath:[documentsDirectoryPath stringByAppendingPathComponent:fileName] error:nil];
|
||||
else if ([fileName rangeOfString:@".resume"].location != NSNotFound)
|
||||
[fileManager removeItemAtPath:[documentsDirectoryPath stringByAppendingPathComponent:fileName] error:nil];
|
||||
else if ([fileName rangeOfString:@".mwm"].location != NSNotFound)
|
||||
{ // Disable iCloud backup
|
||||
static char const * attrName = "com.apple.MobileBackup";
|
||||
u_int8_t attrValue = 1;
|
||||
int result = setxattr([[documentsDirectoryPath stringByAppendingPathComponent:fileName] UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0);
|
||||
if (result == 0)
|
||||
NSLog(@"Disabled iCloud backup for %@", fileName);
|
||||
else
|
||||
NSLog(@"Error %d while disabling iCloud backup for %@", errno, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
Settings::Set(FIRST_LAUNCH_KEY, string(V2_0_TAG));
|
||||
}
|
||||
}
|
||||
|
||||
- (void) applicationWillTerminate: (UIApplication *) application
|
||||
{
|
||||
[m_mapViewController OnTerminate];
|
||||
|
@ -32,6 +80,8 @@
|
|||
|
||||
- (void) applicationDidFinishLaunching: (UIApplication *) application
|
||||
{
|
||||
[self onFirstLaunchCheck];
|
||||
|
||||
[Preferences setup:m_mapViewController];
|
||||
m_locationManager = [[LocationManager alloc] init];
|
||||
|
||||
|
|
|
@ -9,12 +9,28 @@
|
|||
#endif
|
||||
|
||||
#include "../base/std_serialization.hpp"
|
||||
#include "../base/logging.hpp"
|
||||
|
||||
#include "../coding/file_writer_stream.hpp"
|
||||
#include "../coding/file_reader_stream.hpp"
|
||||
|
||||
#include "../std/scoped_ptr.hpp"
|
||||
|
||||
#ifdef OMIM_OS_IPHONE
|
||||
|
||||
#include <sys/xattr.h>
|
||||
|
||||
void DisableiCloudBackupForFile(string const & filePath)
|
||||
{
|
||||
static char const * attrName = "com.apple.MobileBackup";
|
||||
u_int8_t attrValue = 1;
|
||||
const int result = setxattr(filePath.c_str(), attrName, &attrValue, sizeof(attrValue), 0, 0);
|
||||
if (result != 0)
|
||||
LOG(LWARNING, ("Error while disabling iCloud backup for file", filePath));
|
||||
}
|
||||
|
||||
#endif // OMIM_OS_IPHONE
|
||||
|
||||
class HttpThread;
|
||||
|
||||
namespace downloader
|
||||
|
@ -166,6 +182,11 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
|
|||
FileWriter::DeleteFileX(m_filePath + RESUME_FILE_EXTENSION);
|
||||
// rename finished file to it's original name
|
||||
rename((m_filePath + DOWNLOADING_FILE_EXTENSION).c_str(), m_filePath.c_str());
|
||||
#ifdef OMIM_OS_IPHONE
|
||||
// We need to disable iCloud backup for downloaded files.
|
||||
// This is the reason for rejecting from the AppStore
|
||||
DisableiCloudBackupForFile(m_filePath.c_str());
|
||||
#endif
|
||||
}
|
||||
else // or save "chunks left" otherwise
|
||||
SaveRanges(m_filePath + RESUME_FILE_EXTENSION, m_strategy.ChunksLeft());
|
||||
|
@ -199,6 +220,9 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
|
|||
FileWriterStream fws(file);
|
||||
fws << ranges;
|
||||
}
|
||||
#ifdef OMIM_OS_IPHONE
|
||||
DisableiCloudBackupForFile(file);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct CalcRanges
|
||||
|
@ -234,6 +258,10 @@ public:
|
|||
m_strategy.SetChunksToDownload(ranges);
|
||||
}
|
||||
|
||||
#ifdef OMIM_OS_IPHONE
|
||||
m_writer->Flush();
|
||||
DisableiCloudBackupForFile(filePath + DOWNLOADING_FILE_EXTENSION);
|
||||
#endif
|
||||
StartThreads();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue