Commit 9c9b509c authored by wangfugui's avatar wangfugui

修复上版本在添加先行卡服务器时存在的问题

parent 0f418747
......@@ -162,16 +162,16 @@ public interface Constants {
String ID1 = "[versionname]";
String ID2 = "[download_link]";
String ID3 = "#pre_release_code";
String URL_YGO233_DOWNLOAD_LINK = "https://ygo233.com/download/ygomobile";
//String URL_YGO233_DOWNLOAD_LINK = "https://ygo233.com/download/ygomobile";
String URL_YGO233_ADVANCE = "";//"https://ygo233.com/pre#pre_release_cards";//关闭233先行卡服务器,但不要删除该字段,许多未调用的遗留代码使用该contant
String URL_YGO233_DATAVER = "https://cdn02.moecube.com:444/ygopro-super-pre/data/version.txt";
String URL_PRE_CARD = "https://cdn02.moecube.com:444/ygopro-super-pre/data/test-release.json";
String URL_YGO233_FILE = "https://cdn02.moecube.com:444/ygopro-super-pre/archive/ygopro-super-pre.ypk";
String URL_YGO233_FILE_ALT = "https://cdn02.moecube.com:444/ygopro-super-pre/archive/ygopro-super-pre.ypk";
String URL_YGO233_BUG_REPORT = "https://ygo233.com/pre#faq";
int PORT_YGO233 = 23333;
String URL_YGO233_1 = "s1.ygo233.com";
String URL_YGO233_2 = "s2.ygo233.com";
int PORT_Mycard_Super_Pre_Server = 888;
String URL_Mycard_Super_Pre_Server = "mygo.superpre.pro";
//String URL_YGO233_2 = "s2.ygo233.com";
String SERVER_FILE = "server_list.xml";
String SHARE_FILE = ".share_deck.png";
......
......@@ -4,6 +4,9 @@ import net.kk.xml.annotations.XmlElement;
import java.util.List;
/**
* 将服务器列表写入xml文件时利用的PO类
*/
@XmlElement("servers")
public class ServerList {
@XmlElement("version")
......@@ -20,7 +23,7 @@ public class ServerList {
}
public ServerList(int version, List<ServerInfo> serverInfoList) {
mServerInfoList = serverInfoList;
this.mServerInfoList = serverInfoList;
this.vercode = version;
}
......
package cn.garymb.ygomobile.bean.events;
/**
* 用于EventBus的事件类型。
*/
public class CardInfoEvent {
public int position;
public boolean toMain;
......
package cn.garymb.ygomobile.bean.events;
/**
* 用于EventBus发布的时间类型。
* 用于EventBus的事件类型。
*/
public class ExCardEvent {
public enum EventType {
......
package cn.garymb.ygomobile.bean.events;
import cn.garymb.ygomobile.bean.ServerInfo;
/**
* 用于EventBus的事件类型。
*/
public class ServerInfoEvent {
public int position;
public ServerInfo serverInfo;//为了让接受event的HomeFragment能获取到当前server的端口号等信息,加入该属性
......
......@@ -152,7 +152,7 @@ public class ExCardListFragment extends Fragment {
Toast.makeText(getActivity(), R.string.Ask_to_Change_Other_Way, Toast.LENGTH_SHORT).show();
downloadfromWeb(URL_YGO233_FILE_ALT);
}
YGOUtil.showTextToast("error" + getString(R.string.Download_precard_failed));
YGOUtil.showTextToast("error" + getString(R.string.Download_Precard_Failed));
break;
// case UnzipUtils.ZIP_READY:
// textDownload.setText(R.string.title_use_ex);
......@@ -161,15 +161,16 @@ public class ExCardListFragment extends Fragment {
downloadState = DownloadState.NO_DOWNLOAD;
/* 将先行服务器信息添加到服务器列表中 */
String servername = "";
//todo 改成用安卓的localization机制strings.xml
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Chinese.code)
servername = "23333先行服务器";
servername = "萌卡超先行服";
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Korean.code)
servername = "YGOPRO ?? ?? ????";
servername = "Mycard Super-pre Server";
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.English.code)
servername = "Mercury23333 OCG/TCG Pre-release";
servername = "Mycard Super-pre Server";
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Spanish.code)
servername = "Mercury23333 OCG/TCG Pre-release";
AddServer(getActivity(), servername, "s1.ygo233.com", 23333, "Knight of Hanoi");
servername = "Mycard Super-pre Server";
AddServer(getActivity(), servername, Constants.URL_Mycard_Super_Pre_Server, Constants.PORT_Mycard_Super_Pre_Server, "Knight of Hanoi");
//changeDownloadButton();在下载完成后,通过EventBus通知下载完成(加入用户点击下载后临时切出本fragment,又在下载完成后切回,通过eventbus能保证按钮样式正确更新
/* 注意,要先更新版本号 */
......
......@@ -169,6 +169,32 @@ public class ServerUtil {
}
}
/**
* 读取xmlFile指定的本地文件server_list.xml和apk资源文件(assets)下的serverlist.xml,返回其中版本最新的
*
* @param context
* @param xmlFile 指定的本地文件server_list.xml
* @return
* @throws IOException
*/
private static ServerList mergeServerList(Context context, File xmlFile) throws IOException {
/* 读取apk中assets文件夹下的serverlist.xml文件 */
ServerList assetList = ServerListManager.readList(context.getAssets().open(ASSET_SERVER_LIST));
ServerList fileList = xmlFile.exists() ? ServerListManager.readList(new FileInputStream(xmlFile)) : null;
if (fileList == null) {
return assetList;
}
/* 如果apk下assets中的版本号更大,则返回assets下的server列表 */
if (fileList.getVercode() < assetList.getVercode()) {
xmlFile.delete();
return assetList;
}
return fileList;
}
/**
* 从资源文件serverlist.xml(或本地文件server_list.xml)解析服务器列表,并将新添加的服务器信息(name,addr,port)合并到服务器列表中。
*
......@@ -178,26 +204,21 @@ public class ServerUtil {
* @param playerName
*/
public static void AddServer(Context context, String name, String Addr, int port, String playerName) {
/* 读取本地文件server_list.xml */
File xmlFile = new File(context.getFilesDir(), Constants.SERVER_FILE);//读取文件路径下的server_list.xml
List<ServerInfo> serverInfos = new ArrayList<>();
ServerInfo mServerInfo = new ServerInfo();
mServerInfo.setName(name);
mServerInfo.setServerAddr(Addr);
mServerInfo.setPort(port);
mServerInfo.setPlayerName(playerName);
VUiKit.defer().when(() -> {
/* 读取本地文件server_list.xml和资源文件(assets)下的serverlist.xml,返回其中版本最新的 */
ServerList assetList = ServerListManager.readList(context.getAssets().open(ASSET_SERVER_LIST));//读取serverlist.xml文件
ServerList fileList = xmlFile.exists() ? ServerListManager.readList(new FileInputStream(xmlFile)) : null;
if (fileList == null) {
return assetList;
}
if (fileList.getVercode() < assetList.getVercode()) {
xmlFile.delete();
return assetList;
}
return fileList;
return mergeServerList(context, xmlFile);
}).done((list) -> {
List<ServerInfo> serverInfos = new ArrayList<>();
ServerInfo mServerInfo = new ServerInfo();
mServerInfo.setName(name);
mServerInfo.setServerAddr(Addr);
mServerInfo.setPort(port);
mServerInfo.setPlayerName(playerName);
boolean hasServer = false;
if (list != null) {
serverInfos.clear();
......@@ -210,7 +231,7 @@ public class ServerUtil {
hasServer = false;
}
}
if (!hasServer && !serverInfos.contains(mServerInfo)) {
if (!hasServer && !serverInfos.contains(mServerInfo)) {//todo serverInfos.contains(mServerInfo)好像没必要
serverInfos.add(mServerInfo);
}
}
......@@ -234,9 +255,7 @@ public class ServerUtil {
}
public static boolean isPreServer(int port, String addr) {
return (port == Constants.PORT_YGO233 && addr.equals(Constants.URL_YGO233_1)) ||
(port == Constants.PORT_YGO233 && addr.equals(Constants.URL_YGO233_2));
return (port == Constants.PORT_Mycard_Super_Pre_Server && addr.equals(Constants.URL_Mycard_Super_Pre_Server));
}
}
......@@ -269,7 +269,8 @@
<string name="Checking_Update">检查更新中,请稍候</string>
<string name="Found_Update">发现新版本,前往下载?</string>
<string name="Checking_Update_Failed">检查更新失败</string>
<string name="Download_precard_failed">先行卡下载失败</string>
<string name="Download_Precard_Failed">先行卡下载失败</string>
<string name="Pre_Server_Name">萌卡超先行服</string>
<string name="Ask_to_Change_Other_Way">主线获取失败,尝试备选线路中...</string>
<string name="DuelAssistant">决斗助手启用中</string>
<string name="masterrule">学习大师规则</string>
......
......@@ -266,7 +266,8 @@
<string name="Checking_Update">Now Checking Update</string>
<string name="Found_Update">New upGrade is Founded, Download?</string>
<string name="Checking_Update_Failed">Checking Update Failed</string>
<string name="Download_precard_failed">Download pre-cards failed</string>
<string name="Download_Precard_Failed">Download pre-cards failed</string>
<string name="Pre_Server_Name">Mycard Super-pre Server</string>
<string name="Ask_to_Change_Other_Way">trying other way...</string>
<string name="DuelAssistant">DuelAssiatant is On</string>
<string name="masterrule">Master Rule</string>
......
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