|
|
@@ -235,101 +235,105 @@
|
|
|
NSString *documents = [paths objectAtIndex:0];
|
|
|
|
|
|
// NSString* file_name=[appDelegate.downloadurl lastPathComponent];
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
-
|
|
|
- NSData* download_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
+ __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update local data" completion:^{
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
|
|
|
-
|
|
|
- if(download_data!=nil)
|
|
|
- {
|
|
|
-
|
|
|
- [RAUtils deletefiles:[documents stringByAppendingPathComponent:@"download"]];
|
|
|
+ NSData* download_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
- NSString* file_name=[appDelegate.downloadurl lastPathComponent];
|
|
|
- NSString* path = [documents stringByAppendingPathComponent:file_name];
|
|
|
- [RAUtils saveData:download_data toPath:path];
|
|
|
-
|
|
|
- ZipArchive* zip = [[ZipArchive alloc] init];
|
|
|
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
|
|
|
-// NSFileManager* fileManager=[NSFileManager defaultManager];
|
|
|
-// [fileManager removeItemAtPath:unZipTo error:nil];
|
|
|
-// NSString *unZipTo = [temp stringByAppendingPathComponent:unziplocation];
|
|
|
- //
|
|
|
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
- // NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
|
|
|
- //NSString* zipFile = [documentPath stringByAppendingString:@"/images.zip"] ;
|
|
|
- // NSString* unZipTo = img_cache;//[documentPath stringByAppendingString:@"/images"] ;
|
|
|
-
|
|
|
- DebugLog(@"path: %@",unZipTo);
|
|
|
- if( [zip UnzipOpenFile:path Password:nil] ){
|
|
|
- BOOL result = [zip UnzipFileTo:unZipTo overWrite:YES];
|
|
|
- if( NO==result )
|
|
|
+ [waitalert dismissViewControllerAnimated:false completion:^{
|
|
|
+ if(download_data!=nil)
|
|
|
{
|
|
|
- // int aaa=0;
|
|
|
- //解压失败
|
|
|
-
|
|
|
- [zip UnzipCloseFile];
|
|
|
- //文件损坏,删除文件重试
|
|
|
|
|
|
+ [RAUtils deletefiles:[documents stringByAppendingPathComponent:@"download"]];
|
|
|
|
|
|
- NSFileManager* fileManager=[NSFileManager defaultManager];
|
|
|
- //debug
|
|
|
- // BOOL blDele= [fileManager removeItemAtPath:zipFile error:nil];
|
|
|
- [fileManager removeItemAtPath:path error:nil];
|
|
|
- [fileManager removeItemAtPath:unZipTo error:nil];
|
|
|
-
|
|
|
- [RAUtils message_alert:@"Can not unzip template file, please try download again." title:@"Warrning" controller:self];
|
|
|
+ NSString* file_name=[appDelegate.downloadurl lastPathComponent];
|
|
|
+ NSString* path = [documents stringByAppendingPathComponent:file_name];
|
|
|
+ [RAUtils saveData:download_data toPath:path];
|
|
|
|
|
|
+ ZipArchive* zip = [[ZipArchive alloc] init];
|
|
|
+ NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
|
|
|
+ // NSFileManager* fileManager=[NSFileManager defaultManager];
|
|
|
+ // [fileManager removeItemAtPath:unZipTo error:nil];
|
|
|
+ // NSString *unZipTo = [temp stringByAppendingPathComponent:unziplocation];
|
|
|
+ //
|
|
|
+ // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
+ // NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
|
|
|
+ //NSString* zipFile = [documentPath stringByAppendingString:@"/images.zip"] ;
|
|
|
+ // NSString* unZipTo = img_cache;//[documentPath stringByAppendingString:@"/images"] ;
|
|
|
|
|
|
+ DebugLog(@"path: %@",unZipTo);
|
|
|
+ if( [zip UnzipOpenFile:path Password:nil] ){
|
|
|
+ BOOL result = [zip UnzipFileTo:unZipTo overWrite:YES];
|
|
|
+ if( NO==result )
|
|
|
+ {
|
|
|
+ // int aaa=0;
|
|
|
+ //解压失败
|
|
|
+
|
|
|
+ [zip UnzipCloseFile];
|
|
|
+ //文件损坏,删除文件重试
|
|
|
+
|
|
|
+
|
|
|
+ NSFileManager* fileManager=[NSFileManager defaultManager];
|
|
|
+ //debug
|
|
|
+ // BOOL blDele= [fileManager removeItemAtPath:zipFile error:nil];
|
|
|
+ [fileManager removeItemAtPath:path error:nil];
|
|
|
+ [fileManager removeItemAtPath:unZipTo error:nil];
|
|
|
+
|
|
|
+ [RAUtils message_alert:@"Can not unzip template file, please try download again." title:@"Warrning" controller:self];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [zip UnzipCloseFile];
|
|
|
+
|
|
|
+
|
|
|
+ NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
+ [fileManager removeItemAtPath:path error:nil];
|
|
|
+ [RAUtils message_alert:@"Update template file successful." title:@"Message" controller:self];
|
|
|
+
|
|
|
+ // [RADataProvider encrypt_scan_models];
|
|
|
+
|
|
|
+ NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
|
|
|
+ NSString* datetime= [RAUtils current_date_time];
|
|
|
+ templateDic[@"updatetime"]= datetime;
|
|
|
+ [self setUserDefaultsValue:templateDic forKey:@"ScanTemplate"];
|
|
|
+ [self loadTemplate];
|
|
|
+ [RADataProvider load_scan_models];
|
|
|
+
|
|
|
+ }
|
|
|
+ //[zip UnzipCloseFile];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //打开文件失败,通常是文件路径有问题或密码错误。
|
|
|
+ [RAUtils message_alert:@"Can not unzip template file, please contact the Administrator." title:@"Warrning" controller:self];
|
|
|
+
|
|
|
+ // NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
+ // [fileManager removeItemAtPath:zipFile error:nil];
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ // [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
+ //
|
|
|
+ // UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
+ // cell.imageView.image=img;
|
|
|
}
|
|
|
else
|
|
|
- {
|
|
|
- [zip UnzipCloseFile];
|
|
|
-
|
|
|
-
|
|
|
- NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
- [fileManager removeItemAtPath:path error:nil];
|
|
|
- [RAUtils message_alert:@"Update template file successful." title:@"Message" controller:self];
|
|
|
-
|
|
|
-// [RADataProvider encrypt_scan_models];
|
|
|
-
|
|
|
- NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
|
|
|
- NSString* datetime= [RAUtils current_date_time];
|
|
|
- templateDic[@"updatetime"]= datetime;
|
|
|
- [self setUserDefaultsValue:templateDic forKey:@"ScanTemplate"];
|
|
|
- [self loadTemplate];
|
|
|
- [RADataProvider load_scan_models];
|
|
|
-
|
|
|
- }
|
|
|
- //[zip UnzipCloseFile];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //打开文件失败,通常是文件路径有问题或密码错误。
|
|
|
- [RAUtils message_alert:@"Can not unzip template file, please contact the Administrator." title:@"Warrning" controller:self];
|
|
|
-
|
|
|
- // NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
- // [fileManager removeItemAtPath:zipFile error:nil];
|
|
|
- }
|
|
|
+ [RAUtils message_alert:@"Can not download template file, please check your server setting or contact the Administrator." title:@"Warrning" controller:self];
|
|
|
+ }];
|
|
|
|
|
|
+
|
|
|
+ // cell.imageView.image=[UIImage imageNamed:@"notfound_s"];
|
|
|
|
|
|
-// [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
-//
|
|
|
-// UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
-// cell.imageView.image=img;
|
|
|
- }
|
|
|
- else
|
|
|
- [RAUtils message_alert:@"Can not download template file, please check your server setting or contact the Administrator." title:@"Warrning" controller:self];
|
|
|
-// cell.imageView.image=[UIImage imageNamed:@"notfound_s"];
|
|
|
+ });
|
|
|
|
|
|
});
|
|
|
-
|
|
|
- });
|
|
|
+ }];
|
|
|
+
|
|
|
|
|
|
|
|
|
// NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
|