Skip to content

Commit

Permalink
now reading directly from zip obb file, without extracting resources.…
Browse files Browse the repository at this point in the history
… first working version, needs more testing.
  • Loading branch information
asmodehn committed Jan 8, 2015
1 parent 3b87311 commit 05ebed3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions Android/app/build.gradle
Expand Up @@ -256,6 +256,7 @@ android.buildTypes.all { buildType ->
//matching versioncode
def ver = (4 * 10000) + 74

into 'assets'
exclude { details -> details.file.name == 'manifest.json' } // not needed for apk expansion
destinationDir = file('build/outputs/xapk')
baseName = 'main.' + ver + '.' + android.defaultConfig.applicationId + (buildType.applicationIdSuffix?buildType.applicationIdSuffix:'')
Expand Down
Expand Up @@ -11,7 +11,7 @@ public XAPKFile getMainXAPK() {
// it should be the version code added to the obb filename
// so it s possible that it doesn't match current BuildConfig.VERSION_CODE
151536L, // the length of the file in bytes
true
false
);

}
Expand Down
Expand Up @@ -41,6 +41,8 @@
import com.google.android.vending.expansion.downloader.IDownloaderService;
import com.google.android.vending.expansion.downloader.IStub;

import org.cocos2dx.lib.Cocos2dxHelper;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -201,30 +203,30 @@ protected Boolean bgExtract(String fileName, String unzipLocation, boolean check
DataInputStream dis = null;
ZipInputStream zis = null;
try {
Log.d(Constants.TAG, "uncompressing " + entry.mFileName + "...");

//creating parent directories if needed
File unziploc = new File(unzipLocation);
File f = new File(unziploc, entry.mFileName);
File parent = f.getParentFile();
if ( !parent.exists() && !parent.mkdirs())
{
throw new IllegalStateException("Could not create required dir : " + parent);
}

FileOutputStream fos = null;
// write the inputStream to a FileOutputStream
if ( ! f.isDirectory() ) {
fos = new FileOutputStream(f);
}
//Log.d(Constants.TAG, "uncompressing " + entry.mFileName + "...");

////creating parent directories if needed
//File unziploc = new File(unzipLocation);
//File f = new File(unziploc, entry.mFileName);
//File parent = f.getParentFile();
//if ( !parent.exists() && !parent.mkdirs())
//{
// throw new IllegalStateException("Could not create required dir : " + parent);
//}

//FileOutputStream fos = null;
//// write the inputStream to a FileOutputStream
//if ( ! f.isDirectory() ) {
// fos = new FileOutputStream(f);
//}

dis = new DataInputStream(zrf.getInputStream(entry.mFileName));
long startTime = SystemClock.uptimeMillis();
while (length > 0) {
int seek = (int) (length > buf.length ? buf.length : length);
dis.readFully(buf, 0, seek);
//write to file
if (fos != null) fos.write(buf, 0, seek);
////write to file
//if (fos != null) fos.write(buf, 0, seek);
if ( checkCRC ) {
//check crc
crc.update(buf, 0, seek);
Expand Down Expand Up @@ -373,7 +375,7 @@ public void onClick(View view) {
* least one LVL check that requires the network to be present, so this is
* not as necessary.
*
* @return XAPKFile with its filepath set to proper path if it is present. it is set null if still missing, or default empty String if not needed.
* @return XAPKFile with its filepath set to proper path if it is present. it is set null if missing ( may be not needed ).
*/
protected WkDownloaderInfo.XAPKFile expansionFilePath(boolean main) {
try {
Expand All @@ -389,6 +391,16 @@ protected WkDownloaderInfo.XAPKFile expansionFilePath(boolean main) {
|| (!xf.mCheckEnabled && new File(expFilePath).exists()) )//if check disabled we only check it exists
{
xf.setFilePath(expFilePath);
//Now setting XAPK path for cocos to find resources in it.
if ( main )
{
Cocos2dxHelper.nativeSetMainXApkPath(expFilePath);
}
else
{
Cocos2dxHelper.nativeSetPatchXApkPath(expFilePath);
}

}else{
Log.e(TAG, "Missing " + (main?"Main":"Patch") + " XAPK at : " + expFilePath );
if (xf.mCheckEnabled) Log.e(TAG, "Expected Size = " + xf.mFileSize);
Expand Down
6 changes: 3 additions & 3 deletions Android/lib/src/main/res/values/strings.xml
Expand Up @@ -6,9 +6,9 @@
<string name="text_paused_cellular_2">If you choose not to enable downloading over cellular connections, the download will automatically resume when wi-fi is available.</string>
<string name="text_button_resume_cellular">Resume download</string>
<string name="text_button_wifi_settings">Wi-Fi settings</string>
<string name="text_verifying_download">Verifying Download and Extracting...</string>
<string name="text_validation_complete">XAPK File Validation and Extraction Complete. Select OK to exit.</string>
<string name="text_validation_failed">XAPK File Validation and Extraction Failed.</string>
<string name="text_verifying_download">Verifying Download...</string>
<string name="text_validation_complete">XAPK File Validation Complete. Select OK to exit.</string>
<string name="text_validation_failed">XAPK File Validation Failed.</string>
<string name="text_button_pause">Pause Download</string>
<string name="text_button_resume">Resume Download</string>
<string name="text_button_cancel">Cancel</string>
Expand Down
4 changes: 4 additions & 0 deletions Classes/App/AppDelegate.cpp
Expand Up @@ -12,6 +12,8 @@ AppDelegate::AppDelegate()
, m_fileApp(nullptr)
, m_cocosApp(nullptr)
{
//WARNING : On Android, XAPK files are not loaded yet here. Do not use any resource from them.

//initializing search paths for different platforms
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
cocos2d::FileUtils::getInstance()->addSearchPath("Resources");
Expand Down Expand Up @@ -72,6 +74,8 @@ AppDelegate::~AppDelegate()

bool AppDelegate::applicationDidFinishLaunching() {

CCLOG ("AppDelegate::applicationDidFinishLaunching()");

// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
Expand Down

0 comments on commit 05ebed3

Please sign in to comment.