Now, we have a filetype association!!!! :)

This commit is contained in:
Jairo Luiz
2014-02-12 20:56:11 -03:00
parent 667c4750ea
commit 8069dc02c6
5 changed files with 82 additions and 7 deletions
+13
View File
@@ -24,6 +24,19 @@
<category android:name="tv.ouya.intent.category.GAME"/>
</intent-filter>
</activity>
<activity
android:name="GameLauncher"
android:configChanges="orientation|screenSize"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.love" />
<data android:host="*" />
</intent-filter>
</activity>
</application>
<!-- Android 2.3.3 -->
+24
View File
@@ -52,6 +52,30 @@ double getScreenScale()
return result;
}
const char* getSelectedGameFile()
{
static const char *path;
if (!path) {
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
jclass activity = env->FindClass("org/love2d/android/GameLauncher");
jmethodID getGamePath = env->GetStaticMethodID(activity, "getGamePath", "()Ljava/lang/String;");
jstring gamePath = (jstring) env->CallStaticObjectMethod(activity, getGamePath);
const char *utf = env->GetStringUTFChars(gamePath, 0);
if (utf)
{
path = SDL_strdup(utf);
env->ReleaseStringUTFChars(gamePath, utf);
}
env->DeleteLocalRef (gamePath);
env->DeleteLocalRef (activity);
}
return path;
}
} // android
} // love
+5
View File
@@ -36,6 +36,11 @@ namespace android
**/
double getScreenScale();
/**
* Gets the selected love file in the device filesystem.
**/
const char* getSelectedGameFile();
} // android
} // love
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "common/android.h"
#endif
namespace
@@ -65,18 +66,18 @@ namespace
delete[] game_love_data;
}
bool androidMountAssetGame () {
SDL_Log ("Trying to mount assets/game.love");
SDL_RWops *asset_game_file = SDL_RWFromFile("game.love", "rb");
bool androidMountGame (const char *filename) {
SDL_Log ("Trying to mount %s", filename);
SDL_RWops *asset_game_file = SDL_RWFromFile(filename, "rb");
if (!asset_game_file) {
SDL_Log ("Could not find assets/game.love");
SDL_Log ("Could not find %s", filename);
return false;
}
Sint64 file_size = asset_game_file->size(asset_game_file);
if (file_size == 0) {
SDL_Log ("Could not find valid game.love in assets. File has zero size.", (int) file_size);
SDL_Log ("Could not find valid %s. File has zero size.", filename);
return false;
}
@@ -106,6 +107,14 @@ namespace
return result;
}
bool androidMountAssetGame () {
return androidMountGame ("game.love");
}
bool androidMountSelectedGame () {
return androidMountGame (love::android::getSelectedGameFile());
}
bool androidDirectoryExists(const char* path) {
SDL_Log ("Checking directory exists for %s", path);
struct stat s;
@@ -289,7 +298,7 @@ bool Filesystem::setSource(const char *source)
SDL_Log ("Error creating storage directories!");
}
if (!androidMountAssetGame()) {
if (!androidMountSelectedGame() && !androidMountAssetGame()) {
SDL_RWops *sdcard_main = SDL_RWFromFile("/sdcard/lovegame/main.lua", "rb");
if (sdcard_main) {
@@ -306,7 +315,7 @@ bool Filesystem::setSource(const char *source)
// sucessfully, therefore simply fail.
return false;
}
}
}
#else
// Add the directory.
if (!PHYSFS_addToSearchPath(new_search_path.c_str(), 1)) {
+24
View File
@@ -0,0 +1,24 @@
package org.love2d.android;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
public class GameLauncher extends GameActivity {
private static String gamePath;
@Override
protected void onCreate(Bundle bundle) {
Uri game = this.getIntent().getData();
if (game != null) {
gamePath = game.getPath();
Log.d("GameLauncher", "Selected the file: " + gamePath);
}
super.onCreate(bundle);
}
public static String getGamePath() {
return gamePath;
}
}