Commit 9dd62e50 authored by kenan's avatar kenan

open file

parent 5383f1c9
...@@ -19,17 +19,17 @@ char* sub_string(const char* str, int start, int count=-1){ ...@@ -19,17 +19,17 @@ char* sub_string(const char* str, int start, int count=-1){
char* tmp = new char[1024]; char* tmp = new char[1024];
int len = strlen(str); int len = strlen(str);
int index = 0; int index = 0;
if(count < 0){ if(count < 0) {
count = len - start; count = len - start;
} }
for (int j = start; j < len && count > 0; count--, j++) { for (int j = start; j < len && count > 0; count--, j++) {
tmp[index++] = str[j]; tmp[index++] = str[j];
} }
tmp[index] = '\0'; tmp[index] = '\0';
return tmp; return tmp;
} }
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
int GetListBoxIndex(IGUIListBox* listbox, const wchar_t* target){ int GetListBoxIndex(IGUIListBox* listbox, const wchar_t * target){
int count = listbox->getItemCount(); int count = listbox->getItemCount();
for(int i = 0; i < count; i++){ for(int i = 0; i < count; i++){
auto item = listbox->getListItem(i); auto item = listbox->getListItem(i);
...@@ -37,7 +37,7 @@ int GetListBoxIndex(IGUIListBox* listbox, const wchar_t* target){ ...@@ -37,7 +37,7 @@ int GetListBoxIndex(IGUIListBox* listbox, const wchar_t* target){
return i; return i;
} }
} }
return 0; return -1;
} }
void android_main(ANDROID_APP app) { void android_main(ANDROID_APP app) {
app->inputPollSource.process = android::process_input; app->inputPollSource.process = android::process_input;
...@@ -63,7 +63,6 @@ int main(int argc, char* argv[]) { ...@@ -63,7 +63,6 @@ int main(int argc, char* argv[]) {
* -r: replay * -r: replay
*/ */
bool keep_on_return = false; bool keep_on_return = false;
bool open_file = false;
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_WARN, "ygo", "handle args %d", argc); __android_log_print(ANDROID_LOG_WARN, "ygo", "handle args %d", argc);
//android //android
...@@ -95,46 +94,53 @@ int main(int argc, char* argv[]) { ...@@ -95,46 +94,53 @@ int main(int argc, char* argv[]) {
break; break;
} else if(!strcmp(arg, "-r")) { // Replay } else if(!strcmp(arg, "-r")) { // Replay
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
int index = 0; //显示录像窗口
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ygo::mainGame->ShowElement(ygo::mainGame->wReplay);
ygo::mainGame->ebRepStartTurn->setText(L"1");
ygo::mainGame->stReplayInfo->setText(L"");
ygo::mainGame->RefreshReplay();
int index = -1;
if((i+1) < argc){//下一个参数是录像名 if((i+1) < argc){//下一个参数是录像名
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
const char* name = argv[i+1].c_str(); const char* name = argv[i+1].c_str();
#else #else
char* name = argv[i+1]; char* name = argv[i+1];
#endif #endif
wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname);
open_file = true;
wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname);
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname); index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "open replay file:index=%d, name=%s", index, name);
} }
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu); ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
if(open_file){ if (index >= 0) {
ygo::mainGame->lstReplayList->setSelected(index); ygo::mainGame->lstReplayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadReplay); ClickButton(ygo::mainGame->btnLoadReplay);
} }
break;//只播放一个 break;//只播放一个
} else if(!strcmp(arg, "-s")) { // Single } else if(!strcmp(arg, "-s")) { // Single
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
//显示单人模式窗口
int index = 0; ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ygo::mainGame->ShowElement(ygo::mainGame->wSinglePlay);
ygo::mainGame->RefreshSingleplay();
ygo::mainGame->RefreshBot();
int index = -1;
if((i+1) < argc){//下一个参数是文件名 if((i+1) < argc){//下一个参数是文件名
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
const char* name = argv[i+1].c_str(); const char* name = argv[i+1].c_str();
#else #else
char* name = argv[i+1]; char* name = argv[i+1];
#endif #endif
wchar_t fname[1024]; wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname); BufferIO::DecodeUTF8(name, fname);
open_file = true; index = GetListBoxIndex(ygo::mainGame->lstSinglePlayList, fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "open single file:index=%d, name=%s", index, name);
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
} }
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu); if(index >= 0){
ClickButton(ygo::mainGame->btnSingleMode); ygo::mainGame->lstSinglePlayList->setSelected(index);
if(open_file){
ygo::mainGame->lstSinglePlayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadSinglePlay); ClickButton(ygo::mainGame->btnLoadSinglePlay);
} }
break; break;
......
...@@ -118,7 +118,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -118,7 +118,7 @@ public class YGOMobileActivity extends NativeActivity implements
mFullScreenUtils.fullscreen(); mFullScreenUtils.fullscreen();
mFullScreenUtils.onCreate(); mFullScreenUtils.onCreate();
//argv //argv
mArgV = getIntent().getStringArrayExtra(IrrlichtBridge.EXTRA_ARGV); mArgV = IrrlichtBridge.getArgs(getIntent());
// //
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.e("YGOStarter","跳转完成"+System.currentTimeMillis()); Log.e("YGOStarter","跳转完成"+System.currentTimeMillis());
...@@ -418,6 +418,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -418,6 +418,7 @@ public class YGOMobileActivity extends NativeActivity implements
options.mArgvList.clear(); options.mArgvList.clear();
if (mArgV != null) { if (mArgV != null) {
options.mArgvList.addAll(Arrays.asList(mArgV)); options.mArgvList.addAll(Arrays.asList(mArgV));
mArgV = null;
} }
return options.toNativeBuffer(); return options.toNativeBuffer();
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package cn.garymb.ygomobile.core; package cn.garymb.ygomobile.core;
import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.util.Log; import android.util.Log;
...@@ -27,6 +28,7 @@ public final class IrrlichtBridge { ...@@ -27,6 +28,7 @@ public final class IrrlichtBridge {
public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop"; public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop";
public static final String EXTRA_PID = "extras.mypid"; public static final String EXTRA_PID = "extras.mypid";
public static final String EXTRA_ARGV = "extras.argv"; public static final String EXTRA_ARGV = "extras.argv";
public static final String EXTRA_ARGV_TIME_OUT = "extras.argv_timeout";
public static int gPid; public static int gPid;
static { static {
try { try {
...@@ -65,6 +67,19 @@ public final class IrrlichtBridge { ...@@ -65,6 +67,19 @@ public final class IrrlichtBridge {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final String TAG = IrrlichtBridge.class.getSimpleName(); private static final String TAG = IrrlichtBridge.class.getSimpleName();
public static void setArgs(Intent intent, String[] args) {
intent.putExtra(EXTRA_ARGV, args);
intent.putExtra(EXTRA_ARGV_TIME_OUT, (System.currentTimeMillis() + 15 * 1000));
}
public static String[] getArgs(Intent intent){
long time = intent.getLongExtra(EXTRA_ARGV_TIME_OUT, 0);
if(time > System.currentTimeMillis()){
return intent.getStringArrayExtra(EXTRA_ARGV);
}
return null;
}
public static Bitmap getBpgImage(InputStream inputStream, Bitmap.Config config) { public static Bitmap getBpgImage(InputStream inputStream, Bitmap.Config config) {
ByteArrayOutputStream outputStream = null; ByteArrayOutputStream outputStream = null;
try { try {
......
...@@ -7,6 +7,7 @@ android { ...@@ -7,6 +7,7 @@ android {
defaultConfig { defaultConfig {
applicationId "cn.garymb.ygomobile" applicationId "cn.garymb.ygomobile"
minSdkVersion 21 minSdkVersion 21
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 29 targetSdkVersion 29
versionCode 380400630 versionCode 380400630
versionName "3.8.6" versionName "3.8.6"
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
android:supportsRtl="false" android:supportsRtl="false"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:extractNativeLibs="true"
android:requestLegacyExternalStorage="true" android:requestLegacyExternalStorage="true"
tools:replace="android:allowBackup,android:supportsRtl" tools:replace="android:allowBackup,android:supportsRtl"
tools:targetApi="m"> tools:targetApi="m">
<activity <activity
......
...@@ -124,6 +124,7 @@ public interface Constants { ...@@ -124,6 +124,7 @@ public interface Constants {
int REQUEST_CHOOSE_FILE = 0x1000 + 0x20; int REQUEST_CHOOSE_FILE = 0x1000 + 0x20;
int REQUEST_CHOOSE_IMG = 0x1000 + 0x21; int REQUEST_CHOOSE_IMG = 0x1000 + 0x21;
int REQUEST_CHOOSE_FOLDER = 0x1000 + 0x22; int REQUEST_CHOOSE_FOLDER = 0x1000 + 0x22;
int REQUEST_SETTINGS_CODE = 0x1000 + 0x23;
int STRING_TYPE_START = 1050; int STRING_TYPE_START = 1050;
int STRING_ATTRIBUTE_START = 1010; int STRING_ATTRIBUTE_START = 1010;
......
package cn.garymb.ygomobile; package cn.garymb.ygomobile;
import android.app.Activity; import android.app.Activity;
import android.content.ComponentName; import android.content.ContentUris;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.documentfile.provider.DocumentFile;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.Locale; import java.util.Locale;
...@@ -18,14 +26,16 @@ import cn.garymb.ygomobile.bean.Deck; ...@@ -18,14 +26,16 @@ import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity; import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.preference.SettingsActivity; import cn.garymb.ygomobile.ui.preference.SettingsActivity;
import cn.garymb.ygomobile.utils.ComponentUtils;
import cn.garymb.ygomobile.utils.FileUtils; import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import ocgcore.DataManager; import ocgcore.DataManager;
import static cn.garymb.ygomobile.Constants.ACTION_OPEN_DECK; import static cn.garymb.ygomobile.Constants.ACTION_OPEN_DECK;
import static cn.garymb.ygomobile.Constants.ACTION_OPEN_GAME; import static cn.garymb.ygomobile.Constants.ACTION_OPEN_GAME;
import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH; import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SINGLE_PATH;
import static cn.garymb.ygomobile.Constants.QUERY_NAME; import static cn.garymb.ygomobile.Constants.QUERY_NAME;
import static cn.garymb.ygomobile.Constants.REQUEST_SETTINGS_CODE;
public class GameUriManager { public class GameUriManager {
...@@ -74,17 +84,18 @@ public class GameUriManager { ...@@ -74,17 +84,18 @@ public class GameUriManager {
} }
private String getDeckName(Uri uri) { private String getPathName(String path, boolean withOutEx) {
String path = uri.getPath(); Log.d("ygo", "path=" + path);
Log.i("kk", "path=" + path);
if (path != null) { if (path != null) {
int index = path.lastIndexOf("/"); int index = path.lastIndexOf("/");
if (index > 0) { if (index > 0) {
String name = path.substring(index + 1); String name = path.substring(index + 1);
index = name.lastIndexOf("."); if(withOutEx) {
if (index > 0) { index = name.lastIndexOf(".");
//1.ydk if (index > 0) {
name = name.substring(0, index); //1.ydk
name = name.substring(0, index);
}
} }
return name; return name;
} }
...@@ -118,34 +129,96 @@ public class GameUriManager { ...@@ -118,34 +129,96 @@ public class GameUriManager {
return TextUtils.equals(deck, file.getParentFile().getAbsolutePath()); return TextUtils.equals(deck, file.getParentFile().getAbsolutePath());
} }
private void doUri(Uri uri) { private File toLocalFile(Uri uri){
Intent startSeting = new Intent(activity, SettingsActivity.class); String path = uri.getPath();
Log.i("ygo", "doUri:"+uri); File remoteFile = null;
if ("file".equals(uri.getScheme())) { if ("file".equals(uri.getScheme())) {
File file = new File(uri.getPath()); remoteFile = new File(uri.getPath());
if (file.getName().toLowerCase(Locale.US).endsWith(".ydk")) { if (getActivity().getApplicationInfo().targetSdkVersion > 28) {
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (isDeckDir(file)) { if (Environment.isExternalStorageManager()) {
//deck目录 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath()); intent.setData(Uri.parse("package:$packageName"));
} else { getActivity().startActivityForResult(intent, REQUEST_SETTINGS_CODE);
//非deck目录 return null;
File ydk = getDeckFile(new File(AppsSettings.get().getDeckDir()), getDeckName(uri));
FileUtils.copyFile(file, ydk);
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath());
}
activity.startActivity(startdeck);
} else if (file.getName().toLowerCase(Locale.US).endsWith(".ypk")) {
File ypk = new File(AppsSettings.get().getExpansionsPath() + "/" + file.getName());
if (ypk.exists() && file.lastModified() == ypk.lastModified()) {
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_LONG).show();
} else {
try {
FileUtils.copyFile(file, ypk);
} catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show();
} }
} }
}
try {
if (!remoteFile.canRead()) {
Log.w("ygo", "don't read file " + remoteFile.getAbsolutePath());
return null;
}
} catch (Throwable e) {
Log.e("ygo", "don't read file " + remoteFile.getAbsolutePath(), e);
return null;
}
}
String name = getPathName(path, false);
File local;
if(name.toLowerCase(Locale.US).endsWith(".ydk")){
File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache");
local = getDeckFile(dir, name);
} else if (name.toLowerCase(Locale.US).endsWith(".ypk")) {
local = new File(AppsSettings.get().getExpansionsPath(), name);
} else if (name.toLowerCase(Locale.US).endsWith(".yrp")) {
local = new File(AppsSettings.get().getResourcePath() + "/" + CORE_REPLAY_PATH, name);
} else if (name.toLowerCase(Locale.US).endsWith(".lua")) {
local = new File(AppsSettings.get().getResourcePath() + "/" + CORE_SINGLE_PATH, name);
} else {
local = new File(AppsSettings.get().getResourcePath() + "/temp", name);
}
if (local.exists()) {
Log.w("ygo", "Overwrite file "+local.getAbsolutePath());
}
if(remoteFile != null && TextUtils.equals(remoteFile.getAbsolutePath(), local.getAbsolutePath())){
//is same path
Log.i("ygo", "is same file " + remoteFile.getAbsolutePath() + "==" + local.getAbsolutePath());
return local;
}
//copy
ParcelFileDescriptor pfd = null;
FileInputStream input = null;
try {
File dir = local.getParentFile();
if(!dir.exists()){
dir.mkdirs();
}
if(remoteFile != null){
FileUtils.copyFile(remoteFile, local);
} else {
pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
input = new FileInputStream(pfd.getFileDescriptor());
FileUtils.copyFile(input, local);
}
} catch (Throwable e) {
Log.w("ygo", "copy file " + path + "->" + local.getAbsolutePath(), e);
return null;
} finally {
IOUtils.close(input);
IOUtils.close(pfd);
}
return local;
}
private void doUri(Uri uri) {
Intent startSeting = new Intent(activity, SettingsActivity.class);
if ("file".equals(uri.getScheme()) || "content".equals(uri.getScheme())) {
File file = toLocalFile(uri);
if(file == null || !file.exists()){
Toast.makeText(activity, "open file error", Toast.LENGTH_LONG).show();
return;
}
boolean isYdk = file.getName().toLowerCase(Locale.US).endsWith(".ydk");
boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(".ypk");
boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(".yrp");
boolean isLua = file.getName().toLowerCase(Locale.US).endsWith(".lua");
Log.i("ygo", "open file:" + uri + "->" + file.getAbsolutePath());
if(isYdk){
Intent intent = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
intent.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
activity.startActivity(intent);
} else if(isYpk){
if (!AppsSettings.get().isReadExpansions()) { if (!AppsSettings.get().isReadExpansions()) {
activity.startActivity(startSeting); activity.startActivity(startSeting);
Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
...@@ -153,102 +226,17 @@ public class GameUriManager { ...@@ -153,102 +226,17 @@ public class GameUriManager {
DataManager.get().load(true); DataManager.get().load(true);
Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show();
} }
} else if (file.getName().toLowerCase(Locale.US).endsWith(".yrp")) { } else if(isYrp){
File yrp = new File(AppsSettings.get().getResourcePath() + "/" + CORE_REPLAY_PATH + "/" + file.getName());
if (yrp.exists()) {
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_LONG).show();
} else {
try {
FileUtils.copyFile(file, yrp);
} catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show();
}
}
if (!YGOStarter.isGameRunning(getActivity())) { if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(getActivity(), null, "-r", yrp.getName()); YGOStarter.startGame(getActivity(), null, "-r", file.getName());
Toast.makeText(activity, ""+yrp.getName(), Toast.LENGTH_LONG).show(); Toast.makeText(activity, activity.getString(R.string.yrp_installed), Toast.LENGTH_LONG).show();
} else { } else {
Log.w("ygo", "game is running"); Log.w("ygo", "game is running");
} }
} } else if(isLua){
} else if ("content".equals(uri.getScheme())) {
File urifile = new File(uri.getPath());
if (urifile.getName().toLowerCase(Locale.US).endsWith(".ydk")) {
try {
File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache");
File ydk = getDeckFile(dir, getDeckName(uri));
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), ydk);
} catch (Throwable e) {
e.printStackTrace();
} finally {
pfd.close();
}
}
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath());
activity.startActivity(startdeck);
} catch (Throwable e) {
e.printStackTrace();
}
} else if (urifile.getName().toLowerCase(Locale.US).endsWith(".ypk")) {
try {
File ypk = new File(AppsSettings.get().getExpansionsPath() + "/" + urifile.getName().toLowerCase(Locale.US));
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (ypk.exists() && urifile.lastModified() == ypk.lastModified()) {
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_SHORT).show();
} else {
if (pfd == null) {
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), ypk);
} catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show();
} finally {
pfd.close();
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
if (!AppsSettings.get().isReadExpansions()) {
activity.startActivity(startSeting);
Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
} else {
DataManager.get().load(true);
Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show();
}
} else if (urifile.getName().toLowerCase(Locale.US).endsWith(".yrp")) {
File yrp = new File(AppsSettings.get().getResourcePath() + "/" + CORE_REPLAY_PATH + "/" + urifile.getName().toLowerCase(Locale.US));
try {
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (yrp.exists()) {
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_SHORT).show();
} else {
if (pfd == null) {
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), yrp);
} catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show();
} finally {
pfd.close();
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
if (!YGOStarter.isGameRunning(getActivity())) { if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(getActivity(), null, "-r", yrp.getName()); YGOStarter.startGame(getActivity(), null, "-s", file.getName());
Toast.makeText(activity, activity.getString(R.string.yrp_installed), Toast.LENGTH_LONG).show(); Toast.makeText(activity, "load single lua file", Toast.LENGTH_LONG).show();
} else { } else {
Log.w("ygo", "game is running"); Log.w("ygo", "game is running");
} }
...@@ -258,7 +246,6 @@ public class GameUriManager { ...@@ -258,7 +246,6 @@ public class GameUriManager {
// if (!Constants.URI_HOST.equalsIgnoreCase(host)) { // if (!Constants.URI_HOST.equalsIgnoreCase(host)) {
// return; // return;
// } // }
String path = uri.getPath();
if (Constants.URI_HOST.equals(host)) { if (Constants.URI_HOST.equals(host)) {
String name = uri.getQueryParameter(QUERY_NAME); String name = uri.getQueryParameter(QUERY_NAME);
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
......
...@@ -176,9 +176,7 @@ public class YGOStarter { ...@@ -176,9 +176,7 @@ public class YGOStarter {
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY, options); intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY, options);
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_TIME, System.currentTimeMillis()); intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_TIME, System.currentTimeMillis());
} }
if(args != null) { IrrlichtBridge.setArgs(intent, args);
intent.putExtra(IrrlichtBridge.EXTRA_ARGV,args);
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.e("YGOStarter", "跳转前" + System.currentTimeMillis()); Log.e("YGOStarter", "跳转前" + System.currentTimeMillis());
activity.startActivity(intent); activity.startActivity(intent);
......
...@@ -306,6 +306,15 @@ public class MainActivity extends HomeActivity { ...@@ -306,6 +306,15 @@ public class MainActivity extends HomeActivity {
}); });
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == Constants.REQUEST_SETTINGS_CODE){
//TODO
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
/* checkResourceDownload((result, isNewVersion) -> { /* checkResourceDownload((result, isNewVersion) -> {
Toast.makeText(this, R.string.tip_reset_game_res, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.tip_reset_game_res, Toast.LENGTH_SHORT).show();
});*/ });*/
......
package cn.garymb.ygomobile.utils; package cn.garymb.ygomobile.utils;
import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -79,24 +81,21 @@ public class FileUtils { ...@@ -79,24 +81,21 @@ public class FileUtils {
return true; return true;
} }
public static void copyFile(InputStream in, File out) { public static void copyFile(InputStream in, File out) throws IOException {
FileOutputStream outputStream = null; FileOutputStream outputStream = null;
File dir = out.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
try { try {
File dir = out.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
outputStream = new FileOutputStream(out); outputStream = new FileOutputStream(out);
copy(in, outputStream); copy(in, outputStream);
} catch (Throwable e) {
e.printStackTrace();
} finally { } finally {
IOUtils.close(outputStream); IOUtils.close(outputStream);
IOUtils.close(in);
} }
} }
public static void copyFile(File in, File out) { public static boolean copyFile(File in, File out) {
FileOutputStream outputStream = null; FileOutputStream outputStream = null;
FileInputStream inputStream = null; FileInputStream inputStream = null;
try { try {
...@@ -108,11 +107,13 @@ public class FileUtils { ...@@ -108,11 +107,13 @@ public class FileUtils {
outputStream = new FileOutputStream(out); outputStream = new FileOutputStream(out);
copy(inputStream, outputStream); copy(inputStream, outputStream);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); Log.e("ygo", "copy file", e);
return false;
} finally { } finally {
IOUtils.close(outputStream); IOUtils.close(outputStream);
IOUtils.close(inputStream); IOUtils.close(inputStream);
} }
return true;
} }
public static void copyFile(String oldPath, String newPath, boolean isName) throws FileNotFoundException, IOException { public static void copyFile(String oldPath, String newPath, boolean isName) throws FileNotFoundException, IOException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment