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){
char* tmp = new char[1024];
int len = strlen(str);
int index = 0;
if(count < 0){
if(count < 0) {
count = len - start;
}
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){
return tmp;
}
#ifdef _IRR_ANDROID_PLATFORM_
int GetListBoxIndex(IGUIListBox* listbox, const wchar_t* target){
int GetListBoxIndex(IGUIListBox* listbox, const wchar_t * target){
int count = listbox->getItemCount();
for(int i = 0; i < count; i++){
auto item = listbox->getListItem(i);
......@@ -37,7 +37,7 @@ int GetListBoxIndex(IGUIListBox* listbox, const wchar_t* target){
return i;
}
}
return 0;
return -1;
}
void android_main(ANDROID_APP app) {
app->inputPollSource.process = android::process_input;
......@@ -63,7 +63,6 @@ int main(int argc, char* argv[]) {
* -r: replay
*/
bool keep_on_return = false;
bool open_file = false;
#ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_WARN, "ygo", "handle args %d", argc);
//android
......@@ -95,30 +94,40 @@ int main(int argc, char* argv[]) {
break;
} else if(!strcmp(arg, "-r")) { // Replay
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){//下一个参数是录像名
#ifdef _IRR_ANDROID_PLATFORM_
const char* name = argv[i+1].c_str();
#else
char* name = argv[i+1];
#endif
wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname);
open_file = true;
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);
ClickButton(ygo::mainGame->btnReplayMode);
if(open_file){
if (index >= 0) {
ygo::mainGame->lstReplayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadReplay);
}
break;//只播放一个
} else if(!strcmp(arg, "-s")) { // Single
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){//下一个参数是文件名
#ifdef _IRR_ANDROID_PLATFORM_
const char* name = argv[i+1].c_str();
......@@ -127,13 +136,10 @@ int main(int argc, char* argv[]) {
#endif
wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname);
open_file = true;
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
index = GetListBoxIndex(ygo::mainGame->lstSinglePlayList, fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "open single file:index=%d, name=%s", index, name);
}
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnSingleMode);
if(open_file){
if(index >= 0){
ygo::mainGame->lstSinglePlayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadSinglePlay);
}
......
......@@ -118,7 +118,7 @@ public class YGOMobileActivity extends NativeActivity implements
mFullScreenUtils.fullscreen();
mFullScreenUtils.onCreate();
//argv
mArgV = getIntent().getStringArrayExtra(IrrlichtBridge.EXTRA_ARGV);
mArgV = IrrlichtBridge.getArgs(getIntent());
//
super.onCreate(savedInstanceState);
Log.e("YGOStarter","跳转完成"+System.currentTimeMillis());
......@@ -418,6 +418,7 @@ public class YGOMobileActivity extends NativeActivity implements
options.mArgvList.clear();
if (mArgV != null) {
options.mArgvList.addAll(Arrays.asList(mArgV));
mArgV = null;
}
return options.toNativeBuffer();
}
......
......@@ -6,6 +6,7 @@
*/
package cn.garymb.ygomobile.core;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.Log;
......@@ -27,6 +28,7 @@ public final class IrrlichtBridge {
public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop";
public static final String EXTRA_PID = "extras.mypid";
public static final String EXTRA_ARGV = "extras.argv";
public static final String EXTRA_ARGV_TIME_OUT = "extras.argv_timeout";
public static int gPid;
static {
try {
......@@ -65,6 +67,19 @@ public final class IrrlichtBridge {
private static final boolean DEBUG = false;
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) {
ByteArrayOutputStream outputStream = null;
try {
......
......@@ -7,6 +7,7 @@ android {
defaultConfig {
applicationId "cn.garymb.ygomobile"
minSdkVersion 21
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 29
versionCode 380400630
versionName "3.8.6"
......
......@@ -13,8 +13,8 @@
android:supportsRtl="false"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
android:extractNativeLibs="true"
android:requestLegacyExternalStorage="true"
tools:replace="android:allowBackup,android:supportsRtl"
tools:targetApi="m">
<activity
......
......@@ -124,6 +124,7 @@ public interface Constants {
int REQUEST_CHOOSE_FILE = 0x1000 + 0x20;
int REQUEST_CHOOSE_IMG = 0x1000 + 0x21;
int REQUEST_CHOOSE_FOLDER = 0x1000 + 0x22;
int REQUEST_SETTINGS_CODE = 0x1000 + 0x23;
int STRING_TYPE_START = 1050;
int STRING_ATTRIBUTE_START = 1010;
......
......@@ -176,9 +176,7 @@ public class YGOStarter {
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY, options);
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_TIME, System.currentTimeMillis());
}
if(args != null) {
intent.putExtra(IrrlichtBridge.EXTRA_ARGV,args);
}
IrrlichtBridge.setArgs(intent, args);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.e("YGOStarter", "跳转前" + System.currentTimeMillis());
activity.startActivity(intent);
......
......@@ -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) -> {
Toast.makeText(this, R.string.tip_reset_game_res, Toast.LENGTH_SHORT).show();
});*/
......
package cn.garymb.ygomobile.utils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
......@@ -79,24 +81,21 @@ public class FileUtils {
return true;
}
public static void copyFile(InputStream in, File out) {
public static void copyFile(InputStream in, File out) throws IOException {
FileOutputStream outputStream = null;
try {
File dir = out.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
try {
outputStream = new FileOutputStream(out);
copy(in, outputStream);
} catch (Throwable e) {
e.printStackTrace();
} finally {
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;
FileInputStream inputStream = null;
try {
......@@ -108,11 +107,13 @@ public class FileUtils {
outputStream = new FileOutputStream(out);
copy(inputStream, outputStream);
} catch (Throwable e) {
e.printStackTrace();
Log.e("ygo", "copy file", e);
return false;
} finally {
IOUtils.close(outputStream);
IOUtils.close(inputStream);
}
return true;
}
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