From 0211bdc7d3b4e88c1491f2d6293e15ee17d08275 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Fri, 5 Aug 2011 15:31:02 +0200 Subject: [PATCH] [ios] Closes #213 - warning dialog if no free space is available on the device --- iphone/Common/DiskFreeSpace.h | 19 ++++++++++++++ iphone/Maps/Maps.xcodeproj/project.pbxproj | 2 ++ .../Maps/Settings/CountriesViewController.mm | 25 +++++++++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 iphone/Common/DiskFreeSpace.h diff --git a/iphone/Common/DiskFreeSpace.h b/iphone/Common/DiskFreeSpace.h new file mode 100644 index 0000000000..51c8ff425a --- /dev/null +++ b/iphone/Common/DiskFreeSpace.h @@ -0,0 +1,19 @@ +#pragma once + +uint64_t FreeDiskSpaceInBytes() +{ + NSError * error = nil; + NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSDictionary * dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error]; + + if (dictionary) + { + NSNumber * freeFileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize]; + return [freeFileSystemSizeInBytes longLongValue]; + } + else + { + NSLog(@"Error Obtaining Free File System Info: Domain = %@, Code = %@", [error domain], [error code]); + return 0; + } +} diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index a4d469d462..e5b42ccbe3 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -187,6 +187,7 @@ FA500587128907F0002961F0 /* visibility.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = visibility.txt; path = ../../data/visibility.txt; sourceTree = SOURCE_ROOT; }; FA87151A12B1518F00592DAF /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; FA8F8937132D5DB00048E3FE /* libtomcrypt.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libtomcrypt.a; sourceTree = SOURCE_ROOT; }; + FAA4B13E13EC1C8C00BCAB63 /* DiskFreeSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiskFreeSpace.h; sourceTree = ""; }; FAAE8D5D1338FF8B003ECAD5 /* GetActiveConnectionType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetActiveConnectionType.h; sourceTree = ""; }; FAAFD696139D9BE2000AE70C /* categories.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = categories.txt; path = ../../data/categories.txt; sourceTree = SOURCE_ROOT; }; FAAFD698139D9C6B000AE70C /* libsearch.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsearch.a; sourceTree = SOURCE_ROOT; }; @@ -431,6 +432,7 @@ FA34BEC81338D72F00FFB2A7 /* CustomAlertView.mm */, FA34BEC91338D72F00FFB2A7 /* CustomAlertView.h */, FAAE8D5D1338FF8B003ECAD5 /* GetActiveConnectionType.h */, + FAA4B13E13EC1C8C00BCAB63 /* DiskFreeSpace.h */, ); name = Common; path = ../Common; diff --git a/iphone/Maps/Settings/CountriesViewController.mm b/iphone/Maps/Settings/CountriesViewController.mm index b15aac9264..d0d896085a 100644 --- a/iphone/Maps/Settings/CountriesViewController.mm +++ b/iphone/Maps/Settings/CountriesViewController.mm @@ -4,6 +4,7 @@ #import "MapViewController.h" #import "WebViewController.h" #import "CustomAlertView.h" +#import "DiskFreeSpace.h" #include "GetActiveConnectionType.h" #include "IPhonePlatform.hpp" @@ -289,9 +290,25 @@ TIndex g_clickedIndex; [popupQuery release]; } break; - case ENotDownloaded: - case EDownloadFailed: - { + case ENotDownloaded: + case EDownloadFailed: + { + TLocalAndRemoteSize sizePair = m_storage->CountrySizeInBytes(g_clickedIndex); + TLocalAndRemoteSize::first_type size = sizePair.second - sizePair.first; + + // check for disk free space first + if (FreeDiskSpaceInBytes() < (size + 1024*1024)) + { // display warning dialog about not enough free disk space + CustomAlertView * alert = [[CustomAlertView alloc] initWithTitle:@"There is not enough free disk space" + message:[NSString stringWithFormat:@"Please, free some space on your device first to download %@", countryName] + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil]; + [alert show]; + [alert release]; + break; + } + TActiveConnectionType connType = GetActiveConnectionType(); if (connType == ENotConnected) { // do not initiate any download @@ -306,8 +323,6 @@ TIndex g_clickedIndex; } else { - TLocalAndRemoteSize sizePair = m_storage->CountrySizeInBytes(g_clickedIndex); - TLocalAndRemoteSize::first_type size = sizePair.second - sizePair.first; if (connType == EConnectedBy3G && size > MAX_3G_MEGABYTES * MB) { // If user uses 3G, do not allow him to download large countries CustomAlertView * alert =