Created
November 24, 2015 02:57
-
-
Save gmodeblog/fde76d5b889d91c91bc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // JNIを使うので以下をインクルードする | |
| #include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h" | |
| // 例:Resourcesフォルダ内にあるpiyo.binを展開する場合。 | |
| // apkファイルの中にあるファイル名(apk以下相対パス)、Resourcesの中身はassetsに入っている。 | |
| string fromZipFileName = "assets/piyo.bin"; | |
| // 展開ファイルデータサイズ | |
| unsigned long size = 0; | |
| // 展開ファイルデータ | |
| unsigned char* data = NULL; | |
| // Cocos2d-xの関数を使いzip(apk)ファイルに内包されているファイルを読み込む | |
| data = CCFileUtils::sharedFileUtils()->getFileDataFromZip(getApkPath(), fromZipFileName.c_str(),&size); | |
| // メモリ上に展開したファイルを保存する | |
| string unzipFileName = CCFileUtils::sharedFileUtils()->getWritablePath() + string("/piyo.bin"); | |
| // バイナリファイルとして保存する | |
| FILE* unzipFp = fopen(unzipFileName.c_str(), "wb"); | |
| // ファイル書き込み | |
| fwrite(data, size, 1, unzipFp); | |
| fclose(unzipFp); | |
| // new されているのでdeleteする | |
| delete []data; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment