// // ViewController.m // cocos2d_libs // // Created by AR on 27/04/21. // -(void)moveAssetsFromCachesToLocal:(NSString*)bookName cachePath:(NSString*)tempPath { NSLog(@"Temporary File :%@\n", tempPath); NSLog(@"Temporary URL :%@\n",[NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:tempPath.lastPathComponent]]); NSLog(@"[self assetsUnzipPath:bookName] File :%@\n", [self assetsUnzipPath:bookName]); NSString *zipFolderPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:[tempPath.lastPathComponent stringByAppendingString:@"/Contents"]]; if (@available(iOS 14, *)) { std::string text = [zipFolderPath UTF8String]; std::string textfind = "Caches/"; std::size_t found = text.find(textfind); if (found != std::string::npos){ text.insert(found + textfind.size(),"StoreKit/"); zipFolderPath = [NSString stringWithUTF8String:text.c_str()]; } } NSString *destinationPath = [self assetsUnzipPath:bookName]; dispatch_queue_t queue = dispatch_queue_create("DISPATCH_QUEUE_CONCURRENT",DISPATCH_QUEUE_CONCURRENT); dispatch_async(queue, ^{ NSError *error = nil; NSFileManager *fileManager = [[NSFileManager alloc] init]; BOOL isMoved = false; BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:destinationPath]; if (fileExists) isMoved = true; else isMoved = [fileManager copyItemAtPath:zipFolderPath toPath:destinationPath error:&error]; if (isMoved) { NSLog(@"unzipping"); NSString *str = [self assetsDestinationPath:bookName]; dispatch_async(dispatch_get_main_queue(), ^{ [[MyScrollView sharedScrollView] stop_animation]; }); BOOL success = [SSZipArchive unzipFileAtPath:[destinationPath stringByAppendingString:[NSString stringWithFormat:@"%@%@", bookName, @"AllAssets.zip"]] toDestination:str]; if (!success) { [self showIAPFailMessage:bookName]; return; } else { dispatch_async(dispatch_get_main_queue(), ^{ g_pBookManager->onUnzipSuccess([bookName UTF8String]); g_pBookManager->getButton([bookName UTF8String])->canChangedToState(EButtonState::DOWNLOAD_COMPLETE); }); if (!isiPhone_XR) { NSString *strBookPath = [NSString stringWithFormat:@"%@%@", bookName, @"AllAssets"]; [[NSFileManager defaultManager] removeItemAtPath:[self assetsUnzipPath:bookName] error:nil]; if (Application::getInstance()->getTargetPlatform() == cocos2d::Application::Platform::OS_IPHONE) { if (cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().width < 2048 && cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().height < 1536) { if (isiPhone_XR) { NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images", [self assetsDestinationPath:bookName], strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil]; NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images", [self assetsDestinationPath:bookName], strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil]; NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images", [self assetsDestinationPath:bookName], strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil]; NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images", [self assetsDestinationPath:bookName], strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil]; } else { NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/HD_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil]; NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/HD_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil]; NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/HD_images", [self assetsDestinationPath:bookName], strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil]; NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/HD_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil]; } } else { NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil]; NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil]; NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images", [self assetsDestinationPath:bookName], strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil]; NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil]; } } else if (Application::getInstance()->getTargetPlatform() == cocos2d::Application::Platform::OS_IPAD) { if (cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().width < 2048 && cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().height < 1536) { if (isiPhone_XR) { NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil]; NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil]; NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil]; NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil]; } else { NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/HD_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil]; NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/HD_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil]; NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/HD_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil]; NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/HD_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil]; } } else { NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil]; NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil]; NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil]; NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images", [self assetsDestinationPath:bookName],strBookPath]; [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil]; } } NSString *macOSXFilePath = [@"" stringByAppendingFormat:@"%@/__MACOSX",[self assetsDestinationPath:bookName]]; [[NSFileManager defaultManager] removeItemAtPath:macOSXFilePath error:nil]; } } } else { [self showIAPFailMessage:bookName]; return; } [self cacheDicFileDeleteByNAme:tempPath.lastPathComponent]; dispatch_async(dispatch_get_main_queue(), ^{ [[MyScrollView sharedScrollView] stop_animation]; }); }); } @end