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
667c04cf
Commit
667c04cf
authored
Sep 16, 2023
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
读取zip或者ypk内.txt文件里的服务器名称、host、port信息添加到服务器列表
parent
55b92a24
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
21 deletions
+65
-21
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
+17
-1
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/WebActivity.java
...n/java/cn/garymb/ygomobile/ui/activities/WebActivity.java
+1
-19
mobile/src/main/java/cn/garymb/ygomobile/utils/ServerUtil.java
...e/src/main/java/cn/garymb/ygomobile/utils/ServerUtil.java
+47
-1
No files found.
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
View file @
667c04cf
...
...
@@ -8,6 +8,8 @@ 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
;
import
static
cn
.
garymb
.
ygomobile
.
utils
.
ServerUtil
.
AddServer
;
import
static
cn
.
garymb
.
ygomobile
.
utils
.
ServerUtil
.
loadServerInfoFromZipOrYpk
;
import
android.app.Activity
;
import
android.content.Intent
;
...
...
@@ -20,11 +22,22 @@ import android.text.TextUtils;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.app.hubert.guide.util.LogUtil
;
import
com.file.zip.ZipEntry
;
import
com.file.zip.ZipFile
;
import
com.ourygo.lib.duelassistant.util.YGODAUtil
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Enumeration
;
import
java.util.Locale
;
import
java.util.Scanner
;
import
java.util.zip.ZipException
;
import
cn.garymb.ygodata.YGOGameOptions
;
import
cn.garymb.ygomobile.bean.Deck
;
...
...
@@ -33,7 +46,9 @@ import cn.garymb.ygomobile.ui.home.HomeActivity;
import
cn.garymb.ygomobile.ui.home.MainActivity
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.ServerUtil
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
cn.hutool.core.compress.ZipReader
;
import
ocgcore.DataManager
;
import
ocgcore.LimitManager
;
import
ocgcore.StringManager
;
...
...
@@ -45,7 +60,7 @@ public class GameUriManager {
private
StringManager
stringManager
;
public
GameUriManager
(
Activity
activity
)
{
this
.
activity
=
(
HomeActivity
)
activity
;
this
.
activity
=
activity
;
limitManager
=
new
LimitManager
();
stringManager
=
new
StringManager
();
}
...
...
@@ -229,6 +244,7 @@ public class GameUriManager {
}
else
{
DataManager
.
get
().
load
(
true
);
Toast
.
makeText
(
activity
,
R
.
string
.
ypk_installed
,
Toast
.
LENGTH_LONG
).
show
();
loadServerInfoFromZipOrYpk
(
getActivity
(),
file
);
}
}
else
if
(
isYrp
)
{
if
(!
YGOStarter
.
isGameRunning
(
getActivity
()))
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/WebActivity.java
View file @
667c04cf
package
cn.garymb.ygomobile.ui.activities
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
ASSET_SERVER_LIST
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_YGO233_ADVANCE
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_YGO233_FILE
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_YGO233_FILE_ALT
;
import
static
cn
.
garymb
.
ygomobile
.
utils
.
DownloadUtil
.
TYPE_DOWNLOAD_EXCEPTION
;
import
static
cn
.
garymb
.
ygomobile
.
utils
.
DownloadUtil
.
get
;
import
static
cn
.
garymb
.
ygomobile
.
utils
.
ServerUtil
.
AddServer
;
import
android.annotation.SuppressLint
;
...
...
@@ -13,7 +11,6 @@ import android.content.Context;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.util.Log
;
...
...
@@ -37,32 +34,20 @@ import com.tencent.smtt.sdk.WebChromeClient;
import
com.tencent.smtt.sdk.WebView
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.ServerInfo
;
import
cn.garymb.ygomobile.bean.ServerList
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.file.FileActivity
;
import
cn.garymb.ygomobile.ui.file.FileOpenType
;
import
cn.garymb.ygomobile.ui.home.MainActivity
;
import
cn.garymb.ygomobile.ui.home.ServerListManager
;
import
cn.garymb.ygomobile.ui.mycard.MyCard
;
import
cn.garymb.ygomobile.ui.plus.DefWebChromeClient
;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
cn.garymb.ygomobile.ui.widget.WebViewPlus
;
import
cn.garymb.ygomobile.utils.DownloadUtil
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.SharedPreferenceUtil
;
import
cn.garymb.ygomobile.utils.SystemUtils
;
import
cn.garymb.ygomobile.utils.UnzipUtils
;
import
cn.garymb.ygomobile.utils.XmlUtils
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
ocgcore.DataManager
;
import
ocgcore.data.Card
;
...
...
@@ -81,8 +66,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener {
private
EditText
et_context_keyword
;
private
ImageButton
btn_context_search_close
,
btn_context_search_last
,
btn_context_search_next
;
private
Button
btn_download
;
private
List
<
ServerInfo
>
serverInfos
;
private
ServerInfo
mServerInfo
;
private
File
xmlFile
;
private
int
FailedCount
;
@SuppressLint
(
"HandlerLeak"
)
...
...
@@ -145,7 +128,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener {
mWebViewPlus
=
$
(
R
.
id
.
webbrowser
);
find_in_page
=
$
(
R
.
id
.
find_in_page
);
et_context_keyword
=
$
(
R
.
id
.
context_keyword
);
serverInfos
=
new
ArrayList
<>();
xmlFile
=
new
File
(
this
.
getFilesDir
(),
Constants
.
SERVER_FILE
);
initButton
();
//mWebViewPlus.enableHtml5();
...
...
@@ -327,7 +309,7 @@ public class WebActivity extends BaseActivity implements View.OnClickListener {
}
private
void
openFileChooseProcess
(
boolean
isMulti
)
{
Log
.
e
(
TAG
,
mWebViewPlus
.
getUrl
());
Log
.
e
(
TAG
,
mWebViewPlus
.
getUrl
());
if
(
mWebViewPlus
.
getUrl
().
contains
(
MyCard
.
mCommunityReportUrl
))
{
Intent
intent
=
FileActivity
.
getIntent
(
getActivity
(),
getString
(
R
.
string
.
dialog_select_file
),
null
,
AppsSettings
.
get
().
getReplayDir
(),
false
,
FileOpenType
.
SelectFile
);
startActivityForResult
(
intent
,
FILE_CHOOSER_REQUEST
);
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/ServerUtil.java
View file @
667c04cf
...
...
@@ -7,6 +7,9 @@ import android.content.Context;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.file.zip.ZipEntry
;
import
com.file.zip.ZipFile
;
import
org.greenrobot.eventbus.EventBus
;
import
java.io.File
;
...
...
@@ -15,7 +18,9 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.List
;
import
java.util.Scanner
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.ServerInfo
;
...
...
@@ -96,6 +101,47 @@ public class ServerUtil {
}
});
}
/**
* 解析zip或者ypk的file下内置的txt文件里的服务器name、host、prot
*
* @param context
* @param file
*/
public
static
void
loadServerInfoFromZipOrYpk
(
Context
context
,
File
file
)
{
if
(
file
.
getName
().
endsWith
(
".zip"
)
||
file
.
getName
().
endsWith
(
".ypk"
))
{
Log
.
e
(
"GameUriManager"
,
"读取压缩包"
);
try
{
String
serverName
=
null
,
serverHost
=
null
,
serverPort
=
null
;
ZipFile
zipFile
=
new
ZipFile
(
file
.
getAbsoluteFile
(),
"GBK"
);
Enumeration
<
ZipEntry
>
entris
=
zipFile
.
getEntries
();
ZipEntry
entry
;
StringBuilder
content
=
new
StringBuilder
();
while
(
entris
.
hasMoreElements
())
{
entry
=
entris
.
nextElement
();
if
(!
entry
.
isDirectory
())
{
if
(
entry
.
getName
().
endsWith
(
".txt"
))
{
Scanner
scanner
=
new
Scanner
(
zipFile
.
getInputStream
(
entry
));
while
(
scanner
.
hasNextLine
())
{
content
.
append
(
scanner
.
nextLine
()
+
"|"
);
}
scanner
.
close
();
serverName
=
content
.
substring
(
0
,
content
.
indexOf
(
"|"
));
serverHost
=
content
.
substring
(
content
.
indexOf
(
"|"
)
+
1
,
content
.
indexOf
(
":"
));
serverPort
=
content
.
substring
(
content
.
indexOf
(
":"
)
+
1
,
content
.
lastIndexOf
(
"|"
));
}
}
}
AddServer
(
context
,
serverName
,
serverHost
,
Integer
.
valueOf
(
serverPort
),
"Knight of Hanoi"
);
Log
.
w
(
"看看"
,
serverName
+
"/"
+
serverHost
+
"/"
+
serverPort
);
zipFile
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* 从资源文件serverlist.xml(或本地文件server_list.xml)解析服务器列表,并将新添加的服务器信息(name,addr,port)合并到服务器列表中。
...
...
@@ -131,7 +177,7 @@ public class ServerUtil {
serverInfos
.
addAll
(
list
.
getServerInfoList
());
boolean
hasServer
=
false
;
for
(
int
i
=
0
;
i
<
list
.
getServerInfoList
().
size
();
i
++)
{
if
(
mServerInfo
.
get
Port
()
!=
serverInfos
.
get
(
i
).
getPort
()
&&
mServerInfo
.
getServerAddr
()
!=
serverInfos
.
get
(
i
).
getServerAddr
())
{
if
(
mServerInfo
.
get
Name
()
!=
serverInfos
.
get
(
i
).
getName
()
&&
mServerInfo
.
getServerAddr
()
!=
serverInfos
.
get
(
i
).
getServerAddr
())
{
//判断服务器名称、域名IP不同则视为不存在
continue
;
}
else
{
hasServer
=
true
;
...
...
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