|
|
@@ -437,7 +437,7 @@
|
|
|
NSString *cachefolder = [paths objectAtIndex:0];
|
|
|
|
|
|
NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
|
|
|
- // upfolder = [upfolder stringByAppendingPathComponent:serial];
|
|
|
+ // upfolder = [upfolder stringByAppendingPathComponent:serial];
|
|
|
|
|
|
NSFileManager* fileManager = [NSFileManager defaultManager];
|
|
|
BOOL bdir=YES;
|
|
|
@@ -459,7 +459,7 @@
|
|
|
// }
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
// NSString* order_filter_source_path =[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate" ofType:@"json" ];
|
|
|
@@ -553,8 +553,8 @@
|
|
|
}
|
|
|
|
|
|
|
|
|
-// [self test_descrypt];
|
|
|
-// [self test_descrypt1];
|
|
|
+ // [self test_descrypt];
|
|
|
+ // [self test_descrypt1];
|
|
|
//UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:uialertcontroller.class, nil];
|
|
|
// [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
|
|
|
return YES;
|
|
|
@@ -562,79 +562,79 @@
|
|
|
//-(void)test_descrypt
|
|
|
//{
|
|
|
// sqlite3 *db = [iSalesDB get_db];
|
|
|
-//
|
|
|
+//
|
|
|
// int result= [iSalesDB AddExFunction:db];
|
|
|
-//
|
|
|
+//
|
|
|
// NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
|
|
|
// sqlite3_stmt * statement;
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
|
|
|
// {
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// while (sqlite3_step(statement) == SQLITE_ROW)
|
|
|
// {
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// char *url = (char*)sqlite3_column_text(statement, 0);
|
|
|
// if(url==nil)
|
|
|
// url="";
|
|
|
// NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
|
|
|
// NSLog(nsurl);
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
// }
|
|
|
// // [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// sqlite3_finalize(statement);
|
|
|
// }
|
|
|
-//
|
|
|
+//
|
|
|
// [iSalesDB close_db:db];
|
|
|
//}
|
|
|
//
|
|
|
//-(void)test_descrypt1
|
|
|
//{
|
|
|
// sqlite3 *db = [iSalesDB get_db];
|
|
|
-//
|
|
|
+//
|
|
|
// int result= [iSalesDB AddExFunction:db];
|
|
|
-//
|
|
|
+//
|
|
|
// NSString* sqlindex= @"CREATE INDEX hijk ON offline_contact (lower(company_name));";
|
|
|
-//
|
|
|
+//
|
|
|
// [iSalesDB execSql:sqlindex];
|
|
|
-////
|
|
|
+////
|
|
|
//// NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
|
|
|
//// sqlite3_stmt * statement;
|
|
|
-////
|
|
|
-////
|
|
|
-////
|
|
|
+////
|
|
|
+////
|
|
|
+////
|
|
|
//// if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
|
|
|
//// {
|
|
|
-////
|
|
|
-////
|
|
|
+////
|
|
|
+////
|
|
|
//// while (sqlite3_step(statement) == SQLITE_ROW)
|
|
|
//// {
|
|
|
-////
|
|
|
-////
|
|
|
+////
|
|
|
+////
|
|
|
//// char *url = (char*)sqlite3_column_text(statement, 0);
|
|
|
//// if(url==nil)
|
|
|
//// url="";
|
|
|
//// NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
|
|
|
//// NSLog(nsurl);
|
|
|
-////
|
|
|
-////
|
|
|
-////
|
|
|
-////
|
|
|
+////
|
|
|
+////
|
|
|
+////
|
|
|
+////
|
|
|
//// }
|
|
|
//// // [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
|
|
|
-////
|
|
|
-////
|
|
|
+////
|
|
|
+////
|
|
|
//// sqlite3_finalize(statement);
|
|
|
//// }
|
|
|
-//
|
|
|
+//
|
|
|
// [iSalesDB close_db:db];
|
|
|
//}
|
|
|
|
|
|
@@ -774,7 +774,7 @@
|
|
|
{
|
|
|
[self add_downloadlog:@"Begin sync, please wait."];
|
|
|
[self add_downloadlog:@"Prepare upload data."];
|
|
|
- // NSArray* arr_order=[OLDataProvider enumOfflineOrder];
|
|
|
+ // NSArray* arr_order=[OLDataProvider enumOfflineOrder];
|
|
|
NSDictionary* upjson=[OLDataProvider prepareUpload:arr_order];
|
|
|
|
|
|
NSString* upfile=upjson[@"file"];
|
|
|
@@ -853,10 +853,15 @@
|
|
|
[iSalesDB execSql:@"delete from wishlist"];
|
|
|
[iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_order where so_id=in(%@)",so_id]];
|
|
|
[iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_cart where so_no=in(%@)",so_id]];
|
|
|
-// NSDictionary* contactjson= upjson[@"contact"];
|
|
|
-// NSDictionary* wishlistjson= upjson[@"wishlist"];
|
|
|
-// NSDictionary* orderjson= upjson[@"order"];
|
|
|
+ // NSDictionary* contactjson= upjson[@"contact"];
|
|
|
+ // NSDictionary* wishlistjson= upjson[@"wishlist"];
|
|
|
+ // NSDictionary* orderjson= upjson[@"order"];
|
|
|
+
|
|
|
|
|
|
+ NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
+ [defaults removeObjectForKey:@"Forcedownload"];
|
|
|
+ [defaults setValue:@"true" forKey:@"Forcedownload"];
|
|
|
+ [defaults synchronize];
|
|
|
|
|
|
[self download_offline:ver useInternalAddress:buseinternaladdress];
|
|
|
|
|
|
@@ -874,7 +879,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -883,7 +888,7 @@
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
-(void) download_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress
|
|
|
@@ -891,11 +896,11 @@
|
|
|
if(self.downloading)
|
|
|
return;
|
|
|
|
|
|
- self.downloading=true;
|
|
|
+ self.downloading=true;
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
NSString* pvid = [defaults stringForKey:@"vid"] ;
|
|
|
@@ -938,7 +943,7 @@
|
|
|
count++;
|
|
|
download_json=[[iSalesNetwork download_Offline:downSerial] mutableCopy];
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -987,7 +992,10 @@
|
|
|
}
|
|
|
-(void) check_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress parentvc:(UIViewController*) parent
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
NSArray* arr_order=[OLDataProvider enumOfflineOrder];
|
|
|
if(arr_order.count>0)
|
|
|
{
|
|
|
@@ -1038,7 +1046,7 @@
|
|
|
else
|
|
|
[self upload_offline:ver useInternalAddress:buseinternaladdress orderid:nil];
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1049,256 +1057,261 @@
|
|
|
{
|
|
|
if(start)
|
|
|
{
|
|
|
- [ [ UIApplication sharedApplication] setIdleTimerDisabled:YES ] ;
|
|
|
-
|
|
|
- long long size= [[self.download_task valueForKey:@"size"] longLongValue] /1024/1024;
|
|
|
-// [self add_downloadlog:[NSString stringWithFormat:@"Total size %lldMB",size]];
|
|
|
- long long freespace=[RAUtils freeDiskSpaceInMegaBytes];
|
|
|
- long long needsize = size+500;
|
|
|
- if(needsize>freespace &&checkdiskspace)
|
|
|
- {
|
|
|
- //size not enough.
|
|
|
- NSString* space=[NSString stringWithFormat:@"Disk space not enough, need %lldMB free space at least, current free space %lldMB",needsize,freespace];
|
|
|
-
|
|
|
- [self add_downloadlog:space];
|
|
|
- [self.settingUI onSyncFinish];
|
|
|
-
|
|
|
-
|
|
|
- return ;
|
|
|
- }
|
|
|
-
|
|
|
- NSString* temp = NSTemporaryDirectory();
|
|
|
-
|
|
|
-
|
|
|
- NSString * ver = self.download_task[@"ver"];
|
|
|
-
|
|
|
- NSString *tempfolder = [temp stringByAppendingPathComponent:ver];
|
|
|
-
|
|
|
- //创建版本临时目录
|
|
|
- NSFileManager* fileManager = [NSFileManager defaultManager];
|
|
|
- BOOL bdir=YES;
|
|
|
- if(! [fileManager fileExistsAtPath:tempfolder isDirectory:&bdir])
|
|
|
- {
|
|
|
+ [ [ UIApplication sharedApplication] setIdleTimerDisabled:YES ] ;
|
|
|
|
|
|
- NSError *error = nil;
|
|
|
- bool bsuccess=[fileManager createDirectoryAtPath:tempfolder withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
+ long long size= [[self.download_task valueForKey:@"size"] longLongValue] /1024/1024;
|
|
|
+ // [self add_downloadlog:[NSString stringWithFormat:@"Total size %lldMB",size]];
|
|
|
+ long long freespace=[RAUtils freeDiskSpaceInMegaBytes];
|
|
|
+ long long needsize = size+500;
|
|
|
+ if(needsize>freespace &&checkdiskspace)
|
|
|
+ {
|
|
|
+ //size not enough.
|
|
|
+ NSString* space=[NSString stringWithFormat:@"Disk space not enough, need %lldMB free space at least, current free space %lldMB",needsize,freespace];
|
|
|
+
|
|
|
+ [self add_downloadlog:space];
|
|
|
+ [self.settingUI onSyncFinish];
|
|
|
+
|
|
|
+
|
|
|
+ return ;
|
|
|
+ }
|
|
|
|
|
|
- if(!bsuccess)
|
|
|
- DebugLog(@"Create temp folder failed");
|
|
|
+ NSString* temp = NSTemporaryDirectory();
|
|
|
|
|
|
- // if(bsuccess)
|
|
|
- // {
|
|
|
- // sqlite3 *db = [self get_db];
|
|
|
- //
|
|
|
- // [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
|
|
|
- // [iSalesDB close_db:db];
|
|
|
- // }
|
|
|
- }
|
|
|
-
|
|
|
- NSString* cachefolder=[NSString stringWithFormat:@"%@/image_cache/",ver];
|
|
|
-
|
|
|
- NSString *imagecache = [temp stringByAppendingPathComponent:cachefolder];
|
|
|
- if(! [fileManager fileExistsAtPath:imagecache isDirectory:&bdir])
|
|
|
- {
|
|
|
|
|
|
- NSError *error = nil;
|
|
|
- bool bsuccess=[fileManager createDirectoryAtPath:imagecache withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
-
|
|
|
- if(!bsuccess)
|
|
|
- DebugLog(@"Create cache folder failed");
|
|
|
+ NSString * ver = self.download_task[@"ver"];
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- NSString* resourcefolder=[NSString stringWithFormat:@"%@/offline_data/",ver];
|
|
|
-
|
|
|
- NSString *resource = [temp stringByAppendingPathComponent:resourcefolder];
|
|
|
-// if(! [fileManager fileExistsAtPath:resource isDirectory:&bdir])
|
|
|
-// {
|
|
|
-//
|
|
|
-// NSError *error = nil;
|
|
|
-// bool bsuccess=[fileManager createDirectoryAtPath:resource withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
-//
|
|
|
-// if(!bsuccess)
|
|
|
-// DebugLog(@"Create resource folder failed");
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
- NSString *documents = /*[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];*/[paths objectAtIndex:0];
|
|
|
- NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
-
|
|
|
- NSString* tempdb=[NSString stringWithFormat:@"%@%@/%@",temp,ver,DBNAME];
|
|
|
- // tempdb=[documents stringByAppendingPathComponent:DBNAME];
|
|
|
- NSError *error = nil;
|
|
|
- bdir=NO;
|
|
|
- if(! [fileManager fileExistsAtPath:tempdb isDirectory:&bdir])
|
|
|
- {
|
|
|
- // [iSalesDB execSql:@"PRAGMA journal_mode = DELETE;"];
|
|
|
+ NSString *tempfolder = [temp stringByAppendingPathComponent:ver];
|
|
|
|
|
|
- if(![fileManager copyItemAtPath:database_path toPath:tempdb error:&error])
|
|
|
+ //创建版本临时目录
|
|
|
+ NSFileManager* fileManager = [NSFileManager defaultManager];
|
|
|
+ BOOL bdir=YES;
|
|
|
+ if(! [fileManager fileExistsAtPath:tempfolder isDirectory:&bdir])
|
|
|
{
|
|
|
- DebugLog(@"copy database failed");
|
|
|
+
|
|
|
+ NSError *error = nil;
|
|
|
+ bool bsuccess=[fileManager createDirectoryAtPath:tempfolder withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
+
|
|
|
+ if(!bsuccess)
|
|
|
+ DebugLog(@"Create temp folder failed");
|
|
|
+
|
|
|
+ // if(bsuccess)
|
|
|
+ // {
|
|
|
+ // sqlite3 *db = [self get_db];
|
|
|
+ //
|
|
|
+ // [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
|
|
|
+ // [iSalesDB close_db:db];
|
|
|
+ // }
|
|
|
}
|
|
|
- }
|
|
|
- bdir=YES;
|
|
|
- error=nil;
|
|
|
- int count = [[self.download_task valueForKey:@"count"] intValue];
|
|
|
- bool alldone=true;
|
|
|
- bool trouble=false;
|
|
|
- for (int i = 0;i<count;i++)
|
|
|
- {
|
|
|
- NSDictionary* itemjson = [self.download_task objectForKey:[NSString stringWithFormat:@"item_%d",i]];
|
|
|
- NSString* url = [itemjson valueForKey:@"url"];
|
|
|
- NSString* type = [itemjson valueForKey:@"type"];
|
|
|
|
|
|
- NSString* status = itemjson[@"status"];
|
|
|
- //bool finish = [[itemjson valueForKey:@"finish"] boolValue];
|
|
|
- if(! [status isEqualToString:@"finish"])
|
|
|
+ NSString* cachefolder=[NSString stringWithFormat:@"%@/image_cache/",ver];
|
|
|
+
|
|
|
+ NSString *imagecache = [temp stringByAppendingPathComponent:cachefolder];
|
|
|
+ if(! [fileManager fileExistsAtPath:imagecache isDirectory:&bdir])
|
|
|
{
|
|
|
|
|
|
- if([itemjson[@"retry"] intValue]<DOWNLOAD_RETRY_TIMES)
|
|
|
- {
|
|
|
- [self handle_download:url start:start type:type taskid:i];
|
|
|
- alldone=false;
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- alldone=false;
|
|
|
- trouble=true;
|
|
|
- break;
|
|
|
- }
|
|
|
+ NSError *error = nil;
|
|
|
+ bool bsuccess=[fileManager createDirectoryAtPath:imagecache withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
+
|
|
|
+ if(!bsuccess)
|
|
|
+ DebugLog(@"Create cache folder failed");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- if(trouble)
|
|
|
- {
|
|
|
- [self add_downloadlog:@"offline sync got some trouble, sync canceled."];
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-// self.downloadlog=nil;
|
|
|
- self.downloading=false;
|
|
|
- });
|
|
|
- [self.settingUI onSyncFinish];
|
|
|
- }
|
|
|
- else if(alldone)
|
|
|
- {
|
|
|
-
|
|
|
- [self add_downloadlog:@"Finalizing download..."];
|
|
|
- //全部下载完成;
|
|
|
- //写入当前版本
|
|
|
-
|
|
|
-
|
|
|
- NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
|
|
|
- [formatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
|
|
|
- NSString* lastsync = [formatter stringFromDate:[NSDate date]];
|
|
|
|
|
|
+ NSString* resourcefolder=[NSString stringWithFormat:@"%@/offline_data/",ver];
|
|
|
|
|
|
-
|
|
|
- NSString* ver= self.download_task[@"ver"];
|
|
|
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
- [defaults removeObjectForKey:@"OfflineVer"];
|
|
|
- [defaults setValue:ver forKey:@"OfflineVer"];
|
|
|
- [defaults removeObjectForKey:@"LastSync"];
|
|
|
- [defaults setValue:lastsync forKey:@"LastSync"];
|
|
|
- [defaults removeObjectForKey:@"vid"];
|
|
|
- [defaults setValue:self.vid forKey:@"vid"];
|
|
|
-
|
|
|
- [defaults synchronize];
|
|
|
-
|
|
|
-
|
|
|
+ NSString *resource = [temp stringByAppendingPathComponent:resourcefolder];
|
|
|
+ // if(! [fileManager fileExistsAtPath:resource isDirectory:&bdir])
|
|
|
+ // {
|
|
|
+ //
|
|
|
+ // NSError *error = nil;
|
|
|
+ // bool bsuccess=[fileManager createDirectoryAtPath:resource withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
+ //
|
|
|
+ // if(!bsuccess)
|
|
|
+ // DebugLog(@"Create resource folder failed");
|
|
|
+ //
|
|
|
+ // }
|
|
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
- NSString *cachefolder = [paths objectAtIndex:0];
|
|
|
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
|
|
|
- //NSString *cached_offline_data = [cachefolder stringByAppendingPathComponent:@"offline_data"];
|
|
|
-
|
|
|
- if(![RAUtils mergeContentsOfPath:imagecache intoPath:img_cache error:&error])
|
|
|
- {
|
|
|
- DebugLog(@"move image folder failed");
|
|
|
- [self add_downloadlog:@"move image folder failed"];
|
|
|
- trouble=true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DebugLog(@"move image folder successful");
|
|
|
- }
|
|
|
- error=nil;
|
|
|
+ NSString *documents = /*[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];*/[paths objectAtIndex:0];
|
|
|
+ NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
|
-
|
|
|
- // copy temp db to cache.
|
|
|
- if( [fileManager fileExistsAtPath:database_path isDirectory:&bdir])
|
|
|
+ NSString* tempdb=[NSString stringWithFormat:@"%@%@/%@",temp,ver,DBNAME];
|
|
|
+ // tempdb=[documents stringByAppendingPathComponent:DBNAME];
|
|
|
+ NSError *error = nil;
|
|
|
+ bdir=NO;
|
|
|
+ if(! [fileManager fileExistsAtPath:tempdb isDirectory:&bdir])
|
|
|
{
|
|
|
+ // [iSalesDB execSql:@"PRAGMA journal_mode = DELETE;"];
|
|
|
|
|
|
- if(![fileManager removeItemAtPath:database_path error:nil])
|
|
|
+ if(![fileManager copyItemAtPath:database_path toPath:tempdb error:&error])
|
|
|
{
|
|
|
- DebugLog(@"delete database failed");
|
|
|
+ DebugLog(@"copy database failed");
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ bdir=YES;
|
|
|
+ error=nil;
|
|
|
+ int count = [[self.download_task valueForKey:@"count"] intValue];
|
|
|
+ bool alldone=true;
|
|
|
+ bool trouble=false;
|
|
|
+ for (int i = 0;i<count;i++)
|
|
|
+ {
|
|
|
+ NSDictionary* itemjson = [self.download_task objectForKey:[NSString stringWithFormat:@"item_%d",i]];
|
|
|
+ NSString* url = [itemjson valueForKey:@"url"];
|
|
|
+ NSString* type = [itemjson valueForKey:@"type"];
|
|
|
+
|
|
|
+ NSString* status = itemjson[@"status"];
|
|
|
+ //bool finish = [[itemjson valueForKey:@"finish"] boolValue];
|
|
|
+ if(! [status isEqualToString:@"finish"])
|
|
|
{
|
|
|
- if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
|
|
|
+
|
|
|
+ if([itemjson[@"retry"] intValue]<DOWNLOAD_RETRY_TIMES)
|
|
|
{
|
|
|
- DebugLog(@"copy database failed");
|
|
|
- [self add_downloadlog:@"copy database failed"];
|
|
|
- trouble=true;
|
|
|
-
|
|
|
+ [self handle_download:url start:start type:type taskid:i];
|
|
|
+ alldone=false;
|
|
|
+ break;
|
|
|
}
|
|
|
- else{
|
|
|
- BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
|
|
|
- // [iSalesDB execSql:@"PRAGMA journal_mode = WAL;"];
|
|
|
+ else
|
|
|
+ {
|
|
|
+ alldone=false;
|
|
|
+ trouble=true;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
- else if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
|
|
|
- {
|
|
|
- DebugLog(@"copy database failed");
|
|
|
- BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
|
|
|
- [self add_downloadlog:@"copy database failed"];
|
|
|
- trouble=true;
|
|
|
- }
|
|
|
-
|
|
|
-// if(![RAUtils mergeContentsOfPath:tempdb intoPath:database_path error:&error])
|
|
|
-// {
|
|
|
-// DebugLog(@"move db file failed");
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// DebugLog(@"move db file successful");
|
|
|
-// }
|
|
|
- error=nil;
|
|
|
- if(![RAUtils mergeContentsOfPath:resource intoPath:cachefolder error:&error])
|
|
|
- {
|
|
|
- DebugLog(@"move data folder failed");
|
|
|
- [self add_downloadlog:@"move data folder failed"];
|
|
|
- trouble=true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DebugLog(@"move data folder successful");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- [ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
|
|
|
-
|
|
|
-
|
|
|
if(trouble)
|
|
|
{
|
|
|
- [self add_downloadlog:@"offline sync failed."];
|
|
|
- // 尚缺更新失败还原逻辑。
|
|
|
+ [self add_downloadlog:@"offline sync got some trouble, sync canceled."];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ // self.downloadlog=nil;
|
|
|
+ self.downloading=false;
|
|
|
+ });
|
|
|
+ [self.settingUI onSyncFinish];
|
|
|
}
|
|
|
- else
|
|
|
+ else if(alldone)
|
|
|
{
|
|
|
- [self add_downloadlog:@"offline sync complete."];
|
|
|
+
|
|
|
+ [self add_downloadlog:@"Finalizing download..."];
|
|
|
+ //全部下载完成;
|
|
|
+ //写入当前版本
|
|
|
+
|
|
|
+
|
|
|
+ NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
|
|
|
+ [formatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
|
|
|
+ NSString* lastsync = [formatter stringFromDate:[NSDate date]];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSString* ver= self.download_task[@"ver"];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
+ NSString *cachefolder = [paths objectAtIndex:0];
|
|
|
+ NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
|
|
|
+ //NSString *cached_offline_data = [cachefolder stringByAppendingPathComponent:@"offline_data"];
|
|
|
+
|
|
|
+ if(![RAUtils mergeContentsOfPath:imagecache intoPath:img_cache error:&error])
|
|
|
+ {
|
|
|
+ DebugLog(@"move image folder failed");
|
|
|
+ [self add_downloadlog:@"move image folder failed"];
|
|
|
+ trouble=true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DebugLog(@"move image folder successful");
|
|
|
+ }
|
|
|
+ error=nil;
|
|
|
+
|
|
|
+
|
|
|
+ // copy temp db to cache.
|
|
|
+ if( [fileManager fileExistsAtPath:database_path isDirectory:&bdir])
|
|
|
+ {
|
|
|
+
|
|
|
+ if(![fileManager removeItemAtPath:database_path error:nil])
|
|
|
+ {
|
|
|
+ DebugLog(@"delete database failed");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
|
|
|
+ {
|
|
|
+ DebugLog(@"copy database failed");
|
|
|
+ [self add_downloadlog:@"copy database failed"];
|
|
|
+ trouble=true;
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
|
|
|
+ // [iSalesDB execSql:@"PRAGMA journal_mode = WAL;"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
|
|
|
+ {
|
|
|
+ DebugLog(@"copy database failed");
|
|
|
+ BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
|
|
|
+ [self add_downloadlog:@"copy database failed"];
|
|
|
+ trouble=true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // if(![RAUtils mergeContentsOfPath:tempdb intoPath:database_path error:&error])
|
|
|
+ // {
|
|
|
+ // DebugLog(@"move db file failed");
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // DebugLog(@"move db file successful");
|
|
|
+ // }
|
|
|
+ error=nil;
|
|
|
+ if(![RAUtils mergeContentsOfPath:resource intoPath:cachefolder error:&error])
|
|
|
+ {
|
|
|
+ DebugLog(@"move data folder failed");
|
|
|
+ [self add_downloadlog:@"move data folder failed"];
|
|
|
+ trouble=true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DebugLog(@"move data folder successful");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ [ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
|
|
|
+
|
|
|
+
|
|
|
+ if(trouble)
|
|
|
+ {
|
|
|
+ [self add_downloadlog:@"offline sync failed."];
|
|
|
+ // 尚缺更新失败还原逻辑。
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [self add_downloadlog:@"offline sync complete."];
|
|
|
+
|
|
|
+
|
|
|
+ NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
+ [defaults removeObjectForKey:@"OfflineVer"];
|
|
|
+ [defaults setValue:ver forKey:@"OfflineVer"];
|
|
|
+ [defaults removeObjectForKey:@"LastSync"];
|
|
|
+ [defaults setValue:lastsync forKey:@"LastSync"];
|
|
|
+ [defaults removeObjectForKey:@"vid"];
|
|
|
+ [defaults setValue:self.vid forKey:@"vid"];
|
|
|
+ [defaults removeObjectForKey:@"Forcedownload"];
|
|
|
+ [defaults synchronize];
|
|
|
+ }
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ // self.downloadlog=nil;
|
|
|
+ self.downloading=false;
|
|
|
+ self.download_task=nil;
|
|
|
+ self.vid=nil;
|
|
|
+
|
|
|
+
|
|
|
+ [self.settingUI onSyncFinish];
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-// self.downloadlog=nil;
|
|
|
- self.downloading=false;
|
|
|
- self.download_task=nil;
|
|
|
- self.vid=nil;
|
|
|
- [self.settingUI onSyncFinish];
|
|
|
- });
|
|
|
- }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1317,22 +1330,22 @@
|
|
|
if([itemjson[@"retry"] intValue]<DOWNLOAD_RETRY_TIMES)
|
|
|
{
|
|
|
[self handle_download:url start:start type:type taskid:i];
|
|
|
-
|
|
|
+
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- self.downloading=false;
|
|
|
+ self.downloading=false;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-(void) add_downloadlog:(NSString*) newtext
|
|
|
{
|
|
|
-// if(!self.downloading)
|
|
|
-// return;
|
|
|
+ // if(!self.downloading)
|
|
|
+ // return;
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
NSString* date;
|
|
|
@@ -1398,7 +1411,7 @@
|
|
|
long long freespace=[RAUtils freeDiskSpaceInMegaBytes];
|
|
|
if(freespace<=10)
|
|
|
{
|
|
|
- return UNZIP_NO_SPACE;
|
|
|
+ return UNZIP_NO_SPACE;
|
|
|
}
|
|
|
[zip UnzipCloseFile];
|
|
|
//文件损坏,删除文件重试
|
|
|
@@ -1633,7 +1646,7 @@
|
|
|
|
|
|
NSString *imagecache = [temp stringByAppendingPathComponent:cachefolder];
|
|
|
|
|
|
- BOOL bdir=YES;
|
|
|
+ BOOL bdir=YES;
|
|
|
NSError *error = nil;
|
|
|
if(! [[NSFileManager defaultManager] fileExistsAtPath:imagecache isDirectory:&bdir])
|
|
|
{
|
|
|
@@ -1648,7 +1661,7 @@
|
|
|
// NSString* backupfolder=[NSString stringWithFormat:@"%@/test.xml",ver];
|
|
|
// NSString* backup=[temp stringByAppendingPathComponent:backupfolder];
|
|
|
|
|
|
-// NSError *error = nil;
|
|
|
+ // NSError *error = nil;
|
|
|
// NSURL* uf=[NSURL fileURLWithPath:imagecache];
|
|
|
// if( [[NSFileManager defaultManager] replaceItemAtURL:[NSURL fileURLWithPath:imagecache]
|
|
|
// withItemAtURL:[NSURL fileURLWithPath:unZipTo]
|
|
|
@@ -1711,7 +1724,7 @@
|
|
|
sqlite3_free(errmsg);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
//提交事务
|
|
|
@@ -1738,7 +1751,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1764,7 +1777,7 @@
|
|
|
|
|
|
|
|
|
sqlite3_close(tdb);
|
|
|
- // [iSalesDB close_db:tdb];
|
|
|
+ // [iSalesDB close_db:tdb];
|
|
|
// [self SelectData];
|
|
|
}
|
|
|
|
|
|
@@ -1775,7 +1788,7 @@
|
|
|
}
|
|
|
else if([type isEqualToString:@"resource"])
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
int c=self.current_task+1;
|
|
|
double t=[ self.download_task[@"count"] doubleValue];
|
|
|
@@ -1787,7 +1800,7 @@
|
|
|
case UNZIP_NO_SPACE:
|
|
|
{
|
|
|
[self add_downloadlog:@"Disk space not enough."];
|
|
|
-
|
|
|
+
|
|
|
break;
|
|
|
}
|
|
|
case UNZIP_OPEN_FAILED:
|