Commit 9dd62e50 authored by kenan's avatar kenan

open file

parent 5383f1c9
...@@ -19,7 +19,7 @@ char* sub_string(const char* str, int start, int count=-1){ ...@@ -19,7 +19,7 @@ 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++) {
...@@ -29,7 +29,7 @@ char* sub_string(const char* str, int start, int count=-1){ ...@@ -29,7 +29,7 @@ char* sub_string(const char* str, int start, int count=-1){
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,30 +94,40 @@ int main(int argc, char* argv[]) { ...@@ -95,30 +94,40 @@ 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]; wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname); BufferIO::DecodeUTF8(name, fname);
open_file = true;
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();
...@@ -127,13 +136,10 @@ int main(int argc, char* argv[]) { ...@@ -127,13 +136,10 @@ int main(int argc, char* argv[]) {
#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);
if(open_file){
ygo::mainGame->lstSinglePlayList->setSelected(index); ygo::mainGame->lstSinglePlayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadSinglePlay); ClickButton(ygo::mainGame->btnLoadSinglePlay);
} }
......
...@@ -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;
......
...@@ -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;
try {
File dir = out.getParentFile(); File dir = out.getParentFile();
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
try {
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