Permalink
Browse files

new expansions format support

  • Loading branch information...
1 parent 9b311ea commit 3874f6280b6aa58de07af7e5060c3fe971822b7b @nazarov-andrey nazarov-andrey committed Sep 13, 2012
View
@@ -124,6 +124,8 @@ external rm : string -> string -> (unit -> unit) -> unit = "ml_rm";
external downloadExpansions : unit -> unit = "ml_downloadExpansions";
external getExpansionPath : bool -> string = "ml_getExpansionPath";
external getExpansionVer : bool -> int = "ml_getExpansionVer";
+external _extractExpansions : (bool -> unit) -> unit = "ml_extractExpansions";
+external expansionExtracted : unit -> bool = "ml_expansionExtracted";
value unzipCbs = Hashtbl.create 0;
@@ -146,13 +148,13 @@ value apkPath = _apkPath ();
value apkVer = _getVersion ();
value externalStoragePath = _externalStoragePath ();
value assetsVerFilename = externalStoragePath ^ "assets/a" ^ apkVer;
-value expansionVerFilename = externalStoragePath ^ "assets/e" ^ (string_of_int (getExpansionVer True));
+(* value expansionVerFilename = externalStoragePath ^ "assets/e" ^ (string_of_int (getExpansionVer True)); *)
value assetsExtracted () =
Sys.file_exists assetsVerFilename;
-value expansionExtracted () =
- Sys.file_exists expansionVerFilename;
+(* value expansionExtracted () =
+ Sys.file_exists expansionVerFilename; *)
value extractAssets cb =
let assetsPath = externalStoragePath ^ "assets" in
@@ -172,16 +174,15 @@ value extractAssets cb =
value extractExpansions cb =
(
- Callback.register "expnsDownloadComplete" (
- fun () -> unzip (getExpansionPath True) (externalStoragePath ^ "assets/") (
+ Callback.register "expnsDownloadComplete" (fun () -> _extractExpansions cb);
+ downloadExpansions ();
+(* fun () -> unzip (getExpansionPath True) (externalStoragePath ^ "assets/") (
fun success ->
(
if success then close_out (open_out expansionVerFilename) else ();
cb success;
)
- )
- );
- downloadExpansions ();
+ ) *)
);
value extractAssetsIfRequired cb =
@@ -193,28 +194,19 @@ value extractAssetsIfRequired cb =
else
rm (ExtString.String.slice ~last:~-1 externalStoragePath) "assets" (fun () -> extractAssets cb);
-value extractAssetsAndExpansionsIfRequired cb =
- if (assetsExtracted ()) && (expansionExtracted ()) then
- (
- setAssetsDir (externalStoragePath ^ "assets/");
- cb True;
- )
- else
- let extractAssetsRes = ref None
- and extractExpansionRes = ref None in
- let callCb () =
- match (!extractAssetsRes, !extractExpansionRes) with
- [ (Some ear, Some eer) -> cb (ear && eer)
- | _ -> ()
- ]
- in
- let rmCb () =
- (
- extractAssets (fun success -> ( extractAssetsRes.val := Some success; callCb (); ));
- extractExpansions (fun success -> ( extractExpansionRes.val := Some success; callCb (); ));
- )
- in
- rm (ExtString.String.slice ~last:~-1 externalStoragePath) "assets" rmCb;
+value extractAssetsAndExpansionsIfRequired cb =
+ let extractAssetsRes = ref None
+ and extractExpansionRes = ref None in
+ let callCb () =
+ match (!extractAssetsRes, !extractExpansionRes) with
+ [ (Some ear, Some eer) -> cb (ear && eer)
+ | _ -> ()
+ ]
+ in
+ (
+ extractAssetsIfRequired (fun success -> ( extractAssetsRes.val := Some success; callCb (); ));
+ extractExpansions (fun success -> ( extractExpansionRes.val := Some success; callCb (); ));
+ );
(* external test_c_fun: (unit -> unit) -> unit = "ml_test_c_fun"; *)
View
@@ -29,5 +29,4 @@ value setSupportEmail: string -> unit;
value getMACID: unit -> string;
value extractAssetsIfRequired: (bool -> unit) -> unit;
-value extractAssetsAndExpansionsIfRequired: (bool -> unit) -> unit;
-(* value test_c_fun: (unit -> unit) -> unit; *)
+value extractAssetsAndExpansionsIfRequired: (bool -> unit) -> unit;
View
@@ -110,6 +110,8 @@ value zero : c =
type imageInfo;
external loadImage: ?textureID:textureID -> ~path:string -> ~suffix:option string -> filter -> bool -> textureInfo = "ml_loadImage";
+
+
(* external loadImage: ?textureID:textureID -> ~path:string -> ~suffix:option string -> filter -> unit = "ml_loadImage";
value zero_textureInfo =
{
@@ -527,25 +527,36 @@ void ml_downloadExpansions() {
static jmethodID gGetExpansionPathMid;
static jmethodID gGetExpansionVerMid;
-value ml_getExpansionPath(value isMain) {
- CAMLparam1(isMain);
- CAMLlocal1(vpath);
-
+char* get_expansion_path(int main) {
JNIEnv *env;
- (*gJavaVM)->GetEnv(gJavaVM, (void**) &env, JNI_VERSION_1_4);
+ (*gJavaVM)->AttachCurrentThread(gJavaVM, &env, NULL);
+ //(*gJavaVM)->GetEnv(gJavaVM, (void**) &env, JNI_VERSION_1_4);
if (!gGetExpansionPathMid) {
gGetExpansionPathMid = (*env)->GetMethodID(env, jViewCls, "getExpansionPath", "(Z)Ljava/lang/String;");
}
- jstring jpath = (*env)->CallObjectMethod(env, jView, gGetExpansionPathMid, Bool_val(isMain));
- if (!jpath) caml_failwith("Expansion path not specified");
+ jstring jpath = (*env)->CallObjectMethod(env, jView, gGetExpansionPathMid, main);
+ if (!jpath) caml_failwith("Expansion path not specified");
const char* cpath = (*env)->GetStringUTFChars(env, jpath, JNI_FALSE);
- vpath = caml_copy_string(cpath);
+
+ char* retval = (char*)malloc(strlen(cpath) + 1);
+ strcpy(retval, cpath);
(*env)->ReleaseStringUTFChars(env, jpath, cpath);
(*env)->DeleteLocalRef(env, jpath);
+ return retval;
+}
+
+value ml_getExpansionPath(value isMain) {
+ CAMLparam1(isMain);
+ CAMLlocal1(vpath);
+
+ char* cpath = get_expansion_path(Bool_val(isMain));
+ vpath = caml_copy_string(cpath);
+ free(cpath);
+
CAMLreturn(vpath);
}
@@ -5,4 +5,5 @@
void ml_miniunz(value vzipPath, value vdstPath, value testPathFunc);
JNIEXPORT void JNICALL Java_ru_redspell_lightning_LightView_00024UnzipCallbackRunnable_run(JNIEnv *env, jobject this);
value ml_apkPath();
-value ml_externalStoragePath();
+value ml_externalStoragePath();
+char* get_expansion_path(int main);
@@ -215,6 +215,9 @@ public static String getExpansionAPKFileName(Context c, boolean mainFile, int ve
static public String generateSaveFileName(Context c, String fileName) {
String path = getSaveFilePath(c)
+ File.separator + fileName;
+
+ Log.d("LIGHTNING", "generateSaveFileName " + path);
+
return path;
}
@@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.io.IOException;
+import java.io.FileInputStream;
public class LightMediaPlayer extends MediaPlayer {
private static ArrayList<LightMediaPlayer> instances;
@@ -94,11 +95,27 @@ public static void pauseAll() {
}
}
+ private static class OffsetSizePair {
+ public int offset;
+ public int size;
+
+ public OffsetSizePair(int offset, int size) {
+ this.offset = offset;
+ this.size = size;
+ }
+ }
+
+ private static native OffsetSizePair getOffsetSizePair(String path);
+
public static MediaPlayer createMediaPlayer(String assetsDir, String path) throws IOException {
MediaPlayer mp = new LightMediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
- if (assetsDir != null) {
+ OffsetSizePair pair = getOffsetSizePair(path);
+
+ if (pair != null) {
+ mp.setDataSource((new FileInputStream(LightView.instance.getExpansionPath(true))).getFD(), pair.offset, pair.size);
+ } else if (assetsDir != null) {
mp.setDataSource(assetsDir + (assetsDir.charAt(assetsDir.length() - 1) == '/' ? "" : "/") + path);
} else {
AssetFileDescriptor afd = LightView.instance.getContext().getAssets().openFd(path);
@@ -109,7 +126,11 @@ public static MediaPlayer createMediaPlayer(String assetsDir, String path) throw
}
public static int getSoundId(String path, SoundPool sndPool) throws IOException {
- if (path.charAt(0) == '/') {
+ OffsetSizePair pair = getOffsetSizePair(path);
+
+ if (pair != null) {
+ sndPool.load((new FileInputStream(LightView.instance.getExpansionPath(true))).getFD(), pair.offset, pair.size, 1);
+ } else if (path.charAt(0) == '/') {
return sndPool.load(path, 1);
}
@@ -646,4 +646,18 @@ public void curlExternalLoaderError(int req, int errCode, int errMes) {
Log.d("LIGHTNING", "curlExternalLoaderError " + errCode + " " + errMes);
queueEvent(new CurlExternErrorCallbackRunnable(req, errCode, errMes));
}
+
+ private static class ExpansionsCallbackRunnable implements Runnable {
+ private int cb;
+
+ public ExpansionsCallbackRunnable(int cb) {
+ this.cb = cb;
+ }
+
+ public native void run();
+ }
+
+ public void callExpansionsComplete(int cb) {
+ queueEvent(new ExpansionsCallbackRunnable(cb));
+ }
}
Oops, something went wrong. Retry.

0 comments on commit 3874f62

Please sign in to comment.