Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ of this software and associated documentation files (the "Software"), to deal

import java.io.IOException;
import java.io.File;
import java.io.FilenameFilter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -193,16 +194,23 @@ public static void init(final Activity activity) {
public static String getAssetsPath()
{
if (Cocos2dxHelper.sAssetsPath == "") {
int versionCode = 1;
try {
versionCode = Cocos2dxHelper.sActivity.getPackageManager().getPackageInfo(Cocos2dxHelper.sPackageName, 0).versionCode;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
String pathToOBB = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/obb/" + Cocos2dxHelper.sPackageName + "/main." + versionCode + "." + Cocos2dxHelper.sPackageName + ".obb";
File obbFile = new File(pathToOBB);

String pathToOBB = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/obb/" + Cocos2dxHelper.sPackageName;

// Listing all files inside the folder (pathToOBB) where OBB files are expected to be found.
String[] fileNames = new File(pathToOBB).list(new FilenameFilter() { // Using filter to pick up only main OBB file name.
public boolean accept(File dir, String name) {
return name.startsWith("main.") && name.endsWith(".obb"); // It's possible to filter only by extension here to get path to patch OBB file also.
}
});

String fullPathToOBB = "";
if (fileNames != null && fileNames.length > 0) // If there is at least 1 element inside the array with OBB file names, then we may think fileNames[0] will have desired main OBB file name.
fullPathToOBB = pathToOBB + "/" + fileNames[0]; // Composing full file name for main OBB file.

File obbFile = new File(fullPathToOBB);
if (obbFile.exists())
Cocos2dxHelper.sAssetsPath = pathToOBB;
Cocos2dxHelper.sAssetsPath = fullPathToOBB;
else
Cocos2dxHelper.sAssetsPath = Cocos2dxHelper.sActivity.getApplicationInfo().sourceDir;
}
Expand Down