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
9a6801c8
Commit
9a6801c8
authored
Dec 18, 2018
by
feihuaduo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更改替换内核目录
parent
5458e02f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
23 deletions
+54
-23
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
...mb/ygomobile/ui/preference/fragments/SettingFragment.java
+45
-20
mobile/src/main/java/cn/garymb/ygomobile/utils/IOUtils.java
mobile/src/main/java/cn/garymb/ygomobile/utils/IOUtils.java
+9
-3
No files found.
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
View file @
9a6801c8
...
...
@@ -5,6 +5,7 @@ import android.app.Dialog;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.graphics.Color
;
import
android.net.Uri
;
import
android.os.Bundle
;
...
...
@@ -32,6 +33,7 @@ import com.pgyersdk.update.UpdateManagerListener;
import
com.pgyersdk.update.javabean.AppBean
;
import
java.io.DataOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
...
...
@@ -82,8 +84,8 @@ import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath;
public
class
SettingFragment
extends
PreferenceFragmentPlus
{
private
static
final
int
COPY_SO_OK
=
0
;
private
static
final
int
COPY_SO_EXCEPTION
=
1
;
private
static
final
int
COPY_SO_OK
=
0
;
private
static
final
int
COPY_SO_EXCEPTION
=
1
;
public
SettingFragment
()
{
...
...
@@ -120,7 +122,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
bind
(
PREF_GAME_FONT
,
mSettings
.
getFontPath
());
bind
(
PREF_READ_EX
,
mSettings
.
isReadExpansions
());
bind
(
PREF_DECK_MANAGER_V2
,
mSettings
.
isUseDeckManagerV2
());
bind
(
PERF_TEST_REPLACE_KERNEL
,
"替换ygopro的内核
"
);
bind
(
PERF_TEST_REPLACE_KERNEL
,
"需root权限,请在开发者的指导下食用
"
);
Preference
preference
=
findPreference
(
PREF_READ_EX
);
if
(
preference
!=
null
)
{
preference
.
setSummary
(
mSettings
.
getExpansionsPath
().
getAbsolutePath
());
...
...
@@ -316,8 +318,8 @@ public class SettingFragment extends PreferenceFragmentPlus {
}
}
else
if
(
PREF_GAME_PATH
.
equals
(
key
))
{
showFolderChooser
(
preference
,
mSettings
.
getResourcePath
(),
getString
(
R
.
string
.
choose_game_path
));
}
else
if
(
PERF_TEST_REPLACE_KERNEL
.
equals
(
key
))
{
showFileChooser
(
preference
,
".so"
,
mSettings
.
getResourcePath
(),
"内核文件选择"
);
}
else
if
(
PERF_TEST_REPLACE_KERNEL
.
equals
(
key
))
{
showFileChooser
(
preference
,
".so"
,
mSettings
.
getResourcePath
(),
"内核文件选择"
);
}
return
false
;
}
...
...
@@ -355,44 +357,67 @@ public class SettingFragment extends PreferenceFragmentPlus {
((
CheckBoxPreference
)
preference
).
setChecked
(
true
);
mSettings
.
setUseExtraCards
(
true
);
copyDataBase
(
preference
,
file
);
}
else
if
(
PERF_TEST_REPLACE_KERNEL
.
equals
(
key
))
{
File
path
=
App
.
get
().
getDir
(
"lib"
,
Context
.
MODE_APPEND
);
String
name
=
"libYGOMobile.so"
;
File
soFile
=
new
File
(
path
.
getAbsolutePath
(),
name
);
}
else
if
(
PERF_TEST_REPLACE_KERNEL
.
equals
(
key
))
{
File
path
=
App
.
get
().
getFilesDir
().
getParentFile
(
);
String
name
=
"libYGOMobile.so"
;
File
soFile
=
new
File
(
path
.
getAbsolutePath
()
+
"/lib"
,
name
);
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Message
me
=
new
Message
();
Message
me
=
new
Message
();
Process
process
=
null
;
DataOutputStream
os
=
null
;
try
{
String
cmd
=
"chmod -R 777 "
+
soFile
.
getAbsolutePath
();
process
=
Runtime
.
getRuntime
().
exec
(
"su"
);
//切换到root帐号
os
=
new
DataOutputStream
(
process
.
getOutputStream
());
os
.
writeBytes
(
cmd
+
"\n"
);
os
.
writeBytes
(
"exit\n"
);
os
.
flush
();
process
.
waitFor
();
IOUtils
.
delete
(
soFile
);
IOUtils
.
copyFile
(
file
,
soFile
.
getAbsolutePath
(),
true
);
me
.
what
=
COPY_SO_OK
;
}
catch
(
FileNotFoundException
e
)
{
Log
.
e
(
"SettingFragment"
,
"file: "
+
file
);
Log
.
e
(
"SettingFragment"
,
"path: "
+
soFile
.
getAbsolutePath
());
IOUtils
.
copyFile
(
file
,
soFile
.
getAbsolutePath
(),
true
);
me
.
what
=
COPY_SO_OK
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
me
.
what
=
COPY_SO_EXCEPTION
;
me
.
obj
=
e
;
me
.
what
=
COPY_SO_EXCEPTION
;
me
.
obj
=
e
;
}
finally
{
if
(
os
!=
null
)
{
try
{
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
process
.
destroy
();
}
handler
.
sendMessage
(
me
);
}
}).
start
();
}
else
{
}
else
{
super
.
onChooseFileOk
(
preference
,
file
);
}
}
@SuppressLint
(
"HandlerLeak"
)
Handler
handler
=
new
Handler
()
{
Handler
handler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
super
.
handleMessage
(
msg
);
switch
(
msg
.
what
){
switch
(
msg
.
what
)
{
case
COPY_SO_OK:
Toast
.
makeText
(
getActivity
(),
"替换成功"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getActivity
(),
"替换成功"
,
Toast
.
LENGTH_SHORT
).
show
();
break
;
case
COPY_SO_EXCEPTION:
Toast
.
makeText
(
getActivity
(),
"替换失败,原因为"
+
msg
.
obj
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getActivity
(),
"替换失败,原因为"
+
msg
.
obj
,
Toast
.
LENGTH_SHORT
).
show
();
break
;
}
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/IOUtils.java
View file @
9a6801c8
...
...
@@ -229,7 +229,7 @@ public class IOUtils {
return
false
;
}
public
static
void
copyFile
(
String
oldPath
,
String
newPath
,
boolean
isname
)
throws
FileNotFoundException
{
public
static
void
copyFile
(
String
oldPath
,
String
newPath
,
boolean
isname
)
throws
FileNotFoundException
,
IOException
{
//判断复制后的路径是否含有文件名,如果没有则加上
if
(!
isname
)
{
...
...
@@ -239,9 +239,15 @@ public class IOUtils {
}
FileInputStream
fis
=
new
FileInputStream
(
oldPath
);
copyToFile
(
fis
,
newPath
);
FileOutputStream
fos
=
new
FileOutputStream
(
newPath
);
byte
[]
buf
=
new
byte
[
1024
];
int
len
=
0
;
while
((
len
=
fis
.
read
(
buf
))
!=
-
1
)
{
fos
.
write
(
buf
,
0
,
len
);
}
fos
.
close
();
fis
.
close
();
}
}
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