Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
9dd62e50
Commit
9dd62e50
authored
Jul 22, 2021
by
kenan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
open file
parent
5383f1c9
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
188 additions
and
169 deletions
+188
-169
Classes/gframe/gframe.cpp
Classes/gframe/gframe.cpp
+34
-28
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
.../src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
+2
-1
libcore/src/main/java/cn/garymb/ygomobile/core/IrrlichtBridge.java
...rc/main/java/cn/garymb/ygomobile/core/IrrlichtBridge.java
+15
-0
mobile/build.gradle
mobile/build.gradle
+1
-0
mobile/src/main/AndroidManifest.xml
mobile/src/main/AndroidManifest.xml
+1
-1
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
+1
-0
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
+113
-126
mobile/src/main/java/cn/garymb/ygomobile/YGOStarter.java
mobile/src/main/java/cn/garymb/ygomobile/YGOStarter.java
+1
-3
mobile/src/main/java/cn/garymb/ygomobile/ui/home/MainActivity.java
...c/main/java/cn/garymb/ygomobile/ui/home/MainActivity.java
+9
-0
mobile/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
...le/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
+11
-10
No files found.
Classes/gframe/gframe.cpp
View file @
9dd62e50
...
...
@@ -19,17 +19,17 @@ 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
++
)
{
tmp
[
index
++
]
=
str
[
j
];
}
}
tmp
[
index
]
=
'\0'
;
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,46 +94,53 @@ 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
;
wchar_t
fname
[
1024
];
BufferIO
::
DecodeUTF8
(
name
,
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
);
ClickButton
(
ygo
::
mainGame
->
btnReplayMode
);
if
(
open_file
)
{
ygo
::
mainGame
->
lstReplayList
->
setSelected
(
index
);
ClickButton
(
ygo
::
mainGame
->
btnLoadReplay
);
}
break
;
//只播放一个
ygo
::
mainGame
->
HideElement
(
ygo
::
mainGame
->
wMainMenu
);
ClickButton
(
ygo
::
mainGame
->
btnReplayMode
);
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
();
#else
char
*
name
=
argv
[
i
+
1
];
#endif
wchar_t
fname
[
1024
];
BufferIO
::
DecodeUTF8
(
name
,
fname
);
open_file
=
true
;
index
=
GetListBoxIndex
(
ygo
::
mainGame
->
lstReplayList
,
fname
);
wchar_t
fname
[
1024
];
BufferIO
::
DecodeUTF8
(
name
,
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
){
ygo
::
mainGame
->
lstSinglePlayList
->
setSelected
(
index
);
if
(
index
>=
0
){
ygo
::
mainGame
->
lstSinglePlayList
->
setSelected
(
index
);
ClickButton
(
ygo
::
mainGame
->
btnLoadSinglePlay
);
}
break
;
...
...
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
View file @
9dd62e50
...
...
@@ -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
();
}
...
...
libcore/src/main/java/cn/garymb/ygomobile/core/IrrlichtBridge.java
View file @
9dd62e50
...
...
@@ -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
{
...
...
mobile/build.gradle
View file @
9dd62e50
...
...
@@ -7,6 +7,7 @@ android {
defaultConfig
{
applicationId
"cn.garymb.ygomobile"
minSdkVersion
21
//noinspection ExpiredTargetSdkVersion
targetSdkVersion
29
versionCode
380400630
versionName
"3.8.6"
...
...
mobile/src/main/AndroidManifest.xml
View file @
9dd62e50
...
...
@@ -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
...
...
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
View file @
9dd62e50
...
...
@@ -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
;
...
...
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
View file @
9dd62e50
package
cn.garymb.ygomobile
;
import
android.app.Activity
;
import
android.content.Co
mponentName
;
import
android.content.Co
ntentUris
;
import
android.content.Intent
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.os.ParcelFileDescriptor
;
import
android.provider.DocumentsContract
;
import
android.provider.MediaStore
;
import
android.provider.Settings
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.Toast
;
import
androidx.documentfile.provider.DocumentFile
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.util.Locale
;
...
...
@@ -18,14 +26,16 @@ import cn.garymb.ygomobile.bean.Deck;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.cards.DeckManagerActivity
;
import
cn.garymb.ygomobile.ui.preference.SettingsActivity
;
import
cn.garymb.ygomobile.utils.ComponentUtils
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
ocgcore.DataManager
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
ACTION_OPEN_DECK
;
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_SINGLE_PATH
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
QUERY_NAME
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
REQUEST_SETTINGS_CODE
;
public
class
GameUriManager
{
...
...
@@ -74,17 +84,18 @@ public class GameUriManager {
}
private
String
getDeckName
(
Uri
uri
)
{
String
path
=
uri
.
getPath
();
Log
.
i
(
"kk"
,
"path="
+
path
);
private
String
getPathName
(
String
path
,
boolean
withOutEx
)
{
Log
.
d
(
"ygo"
,
"path="
+
path
);
if
(
path
!=
null
)
{
int
index
=
path
.
lastIndexOf
(
"/"
);
if
(
index
>
0
)
{
String
name
=
path
.
substring
(
index
+
1
);
index
=
name
.
lastIndexOf
(
"."
);
if
(
index
>
0
)
{
//1.ydk
name
=
name
.
substring
(
0
,
index
);
if
(
withOutEx
)
{
index
=
name
.
lastIndexOf
(
"."
);
if
(
index
>
0
)
{
//1.ydk
name
=
name
.
substring
(
0
,
index
);
}
}
return
name
;
}
...
...
@@ -118,34 +129,96 @@ public class GameUriManager {
return
TextUtils
.
equals
(
deck
,
file
.
getParentFile
().
getAbsolutePath
());
}
private
void
doUri
(
Uri
uri
)
{
Intent
startSeting
=
new
Intent
(
activity
,
SettingsActivity
.
class
);
Log
.
i
(
"ygo"
,
"doUri:"
+
uri
)
;
private
File
toLocalFile
(
Uri
uri
)
{
String
path
=
uri
.
getPath
(
);
File
remoteFile
=
null
;
if
(
"file"
.
equals
(
uri
.
getScheme
()))
{
File
file
=
new
File
(
uri
.
getPath
());
if
(
file
.
getName
().
toLowerCase
(
Locale
.
US
).
endsWith
(
".ydk"
))
{
Intent
startdeck
=
new
Intent
(
getActivity
(),
DeckManagerActivity
.
getDeckManager
());
if
(
isDeckDir
(
file
))
{
//deck目录
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
file
.
getAbsolutePath
());
}
else
{
//非deck目录
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
();
remoteFile
=
new
File
(
uri
.
getPath
());
if
(
getActivity
().
getApplicationInfo
().
targetSdkVersion
>
28
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
if
(
Environment
.
isExternalStorageManager
())
{
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
);
intent
.
setData
(
Uri
.
parse
(
"package:$packageName"
));
getActivity
().
startActivityForResult
(
intent
,
REQUEST_SETTINGS_CODE
);
return
null
;
}
}
}
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
())
{
activity
.
startActivity
(
startSeting
);
Toast
.
makeText
(
activity
,
R
.
string
.
ypk_go_setting
,
Toast
.
LENGTH_LONG
).
show
();
...
...
@@ -153,102 +226,17 @@ public class GameUriManager {
DataManager
.
get
().
load
(
true
);
Toast
.
makeText
(
activity
,
R
.
string
.
ypk_installed
,
Toast
.
LENGTH_LONG
).
show
();
}
}
else
if
(
file
.
getName
().
toLowerCase
(
Locale
.
US
).
endsWith
(
".yrp"
))
{
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
();
}
}
}
else
if
(
isYrp
){
if
(!
YGOStarter
.
isGameRunning
(
getActivity
()))
{
YGOStarter
.
startGame
(
getActivity
(),
null
,
"-r"
,
yrp
.
getName
());
Toast
.
makeText
(
activity
,
""
+
yrp
.
getName
(
),
Toast
.
LENGTH_LONG
).
show
();
YGOStarter
.
startGame
(
getActivity
(),
null
,
"-r"
,
file
.
getName
());
Toast
.
makeText
(
activity
,
activity
.
getString
(
R
.
string
.
yrp_installed
),
Toast
.
LENGTH_LONG
).
show
();
}
else
{
Log
.
w
(
"ygo"
,
"game is running"
);
}
}
}
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
();
}
}
else
if
(
isLua
){
if
(!
YGOStarter
.
isGameRunning
(
getActivity
()))
{
YGOStarter
.
startGame
(
getActivity
(),
null
,
"-
r"
,
yrp
.
getName
());
Toast
.
makeText
(
activity
,
activity
.
getString
(
R
.
string
.
yrp_installed
)
,
Toast
.
LENGTH_LONG
).
show
();
YGOStarter
.
startGame
(
getActivity
(),
null
,
"-
s"
,
file
.
getName
());
Toast
.
makeText
(
activity
,
"load single lua file"
,
Toast
.
LENGTH_LONG
).
show
();
}
else
{
Log
.
w
(
"ygo"
,
"game is running"
);
}
...
...
@@ -258,7 +246,6 @@ public class GameUriManager {
// if (!Constants.URI_HOST.equalsIgnoreCase(host)) {
// return;
// }
String
path
=
uri
.
getPath
();
if
(
Constants
.
URI_HOST
.
equals
(
host
))
{
String
name
=
uri
.
getQueryParameter
(
QUERY_NAME
);
if
(!
TextUtils
.
isEmpty
(
name
))
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/YGOStarter.java
View file @
9dd62e50
...
...
@@ -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
);
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/home/MainActivity.java
View file @
9dd62e50
...
...
@@ -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();
});*/
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
View file @
9dd62e50
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
;
File
dir
=
out
.
getParentFile
();
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
try
{
File
dir
=
out
.
getParentFile
();
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment