Commit 0926ca5a authored by fallenstardust's avatar fallenstardust

根据语言复制配置文件

parent 0bdbc6b5
......@@ -54,6 +54,8 @@ public interface Constants {
String SETTINGS_COVER = "settings_game_diy_card_cover";
String SETTINGS_AVATAR = "settings_game_avatar";
String SETTINGS_CARD_BG = "settings_game_diy_card_bg";
String ASSETS_EN = "en/";
String ASSETS_KOR = "kor/";
String ASSETS_PATH = "data/";
String ASSET_SERVER_LIST = "serverlist.xml";
String ASSET_LIMIT_PNG = ASSETS_PATH + "textures/lim.png";
......
package cn.garymb.ygomobile.ui.home;
import static cn.garymb.ygomobile.Constants.ASSETS_EN;
import static cn.garymb.ygomobile.Constants.ASSETS_KOR;
import static cn.garymb.ygomobile.Constants.ASSETS_PATH;
import static cn.garymb.ygomobile.Constants.BOT_CONF;
import static cn.garymb.ygomobile.Constants.CORE_BOT_CONF_PATH;
import static cn.garymb.ygomobile.Constants.CORE_LIMIT_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SINGLE_PATH;
import static cn.garymb.ygomobile.Constants.CORE_STRING_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SYSTEM_PATH;
import static cn.garymb.ygomobile.Constants.DATABASE_NAME;
import static cn.garymb.ygomobile.Constants.WINDBOT_PATH;
import android.content.BroadcastReceiver;
import android.content.Context;
......@@ -28,6 +32,7 @@ import java.util.List;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.utils.FileUtils;
......@@ -263,14 +268,23 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_SCRIPTS_ZIP),
resPath, needsUpdate);
}
//复制卡图压缩包
if (IOUtils.hasAssets(mContext, getDatapath(Constants.CORE_PICS_ZIP))) {
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.images)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_PICS_ZIP),
resPath, needsUpdate);
}
String language = mContext.getResources().getConfiguration().locale.getDisplayLanguage();
Log.i(BuildConfig.VERSION_NAME,language);
if(!language.isEmpty()){
if(language.equals("中文")) {
copyCnData(needsUpdate);
}else if (language.equals("Korean")){
copyKorData(needsUpdate);
} else {
copyEnData(needsUpdate);
}
}
han.sendEmptyMessage(0);
loadData();
......@@ -288,37 +302,49 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
copyCdbFile(getDatapath(DATABASE_NAME), needsUpdate);
//复制残局
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.single_lua)));
File single = new File(mSettings.getSingleDir());
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_SINGLE_PATH),
mSettings.getSingleDir(), needsUpdate);
IOUtils.copyFilesFromAssets(mContext, getDatapath(CORE_SINGLE_PATH), mSettings.getSingleDir(), needsUpdate);
//复制人机资源
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH),
mSettings.getResourcePath(), needsUpdate);
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH), mSettings.getResourcePath(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(mSettings.getResourcePath(), needsUpdate);
copyCoreConfig(getDatapath("conf") + "/" + CORE_STRING_PATH,
getDatapath("conf") + "/" + BOT_CONF,
mSettings.getResourcePath(), needsUpdate);
return ERROR_NONE;
}
private int copyEnData(File stringfile, File botfile) {
String enStringConf = ASSETS_PATH + "en/conf/" + CORE_STRING_PATH;
String enBotConf = ASSETS_PATH + "en/conf/" + CORE_BOT_CONF_PATH;
String enCdb = ASSETS_PATH + "en/" + DATABASE_NAME;
try {
IOUtils.copyFilesFromAssets(mContext, enStringConf, stringfile.getPath(), true);
IOUtils.copyFilesFromAssets(mContext, enBotConf, botfile.getPath(), true);
copyCdbFile(enCdb, true);
//替换换行符
fixString(stringfile.getAbsolutePath());
fixString(botfile.getAbsolutePath());
return ERROR_NONE;
} catch (IOException e) {
mError = ERROR_COPY;
return ERROR_COPY;
}
}
private int copyEnData(Boolean needsUpdate) throws IOException {
String enStringConf = ASSETS_EN + getDatapath("conf") + "/" + CORE_STRING_PATH;
String enBotConf = ASSETS_EN + getDatapath("conf") + "/" + CORE_BOT_CONF_PATH;
String enCdb = ASSETS_EN + getDatapath(DATABASE_NAME);
String enSingle = ASSETS_EN + getDatapath(CORE_SINGLE_PATH);
//复制数据库
copyCdbFile(enCdb, true);
//复制残局
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.single_lua)));
IOUtils.copyFilesFromAssets(mContext, enSingle, mSettings.getSingleDir(), needsUpdate);
//复制人机资源
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH), mSettings.getResourcePath(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(enStringConf, enBotConf, mSettings.getResourcePath(), needsUpdate);
private int copyKorData(File systemfile, File stringfile, File botfile) {
return ERROR_NONE;
}
private int copyKorData(Boolean needsUpdate) throws IOException {
String korStringConf = ASSETS_KOR + getDatapath("conf") + "/" + CORE_STRING_PATH;
String korBotConf = ASSETS_KOR + getDatapath("conf") + "/" + CORE_BOT_CONF_PATH;
String korCdb = ASSETS_KOR + getDatapath(DATABASE_NAME);
String korWindbotPath = ASSETS_KOR + getDatapath(WINDBOT_PATH);
String korSingle = ASSETS_EN + getDatapath(CORE_SINGLE_PATH);
//复制数据库
copyCdbFile(korCdb, true);
//复制残局
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.single_lua)));
IOUtils.copyFilesFromAssets(mContext, korSingle, mSettings.getSingleDir(), needsUpdate);
//复制人机资源
IOUtils.copyFilesFromAssets(mContext, korWindbotPath, mSettings.getResourcePath(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(korStringConf, korBotConf, mSettings.getResourcePath(), needsUpdate);
return ERROR_NONE;
}
......@@ -346,7 +372,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
//脚本文件夹
Constants.CORE_SCRIPT_PATH,
//残局文件夹
Constants.CORE_SINGLE_PATH,
CORE_SINGLE_PATH,
//卡组文件夹
Constants.CORE_DECK_PATH,
//pack文件夹
......@@ -395,31 +421,22 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
return null;
}
private int copyCoreConfig(String toPath, boolean needsUpdate) {
File systemfile, stringfile, botfile;
systemfile = new File(AppsSettings.get().getResourcePath(), CORE_SYSTEM_PATH);
stringfile = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH);
botfile = new File(AppsSettings.get().getResourcePath(), BOT_CONF);
try {
if (!systemfile.exists()) {
IOUtils.copyFilesFromAssets(mContext, getDatapath("conf") + "/" + CORE_SYSTEM_PATH, toPath, false);
}
IOUtils.copyFilesFromAssets(mContext, getDatapath("conf") + "/" + CORE_LIMIT_PATH, toPath, needsUpdate);
if (!stringfile.exists() || stringfile.length() < new File(getDatapath("conf") + "/" + CORE_STRING_PATH).length()) {
IOUtils.copyFilesFromAssets(mContext, getDatapath("conf") + "/" + CORE_STRING_PATH, toPath, needsUpdate);
}
IOUtils.copyFilesFromAssets(mContext, getDatapath("conf") + "/" + CORE_BOT_CONF_PATH, toPath, needsUpdate);
//替换换行符
fixString(stringfile.getAbsolutePath());
fixString(botfile.getAbsolutePath());
return ERROR_NONE;
} catch (IOException e) {
if (Constants.DEBUG)
Log.e(TAG, "copy", e);
mError = ERROR_COPY;
return ERROR_COPY;
private int copyCoreConfig(String assetStringPath, String assetBotPath, String toPath, boolean needsUpdate) throws IOException {
File systemfile = new File(AppsSettings.get().getResourcePath(), CORE_SYSTEM_PATH);
File stringfile = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH);
File botfile = new File(AppsSettings.get().getResourcePath(), BOT_CONF);
if (!systemfile.exists()) {
IOUtils.copyFilesFromAssets(mContext, getDatapath("conf") + "/" + CORE_SYSTEM_PATH, toPath, false);
}
IOUtils.copyFilesFromAssets(mContext, getDatapath("conf") + "/" + CORE_LIMIT_PATH, toPath, needsUpdate);
if (!stringfile.exists() || stringfile.length() < new File(getDatapath("conf") + "/" + CORE_STRING_PATH).length()) {
IOUtils.copyFilesFromAssets(mContext, assetStringPath, toPath, needsUpdate);
}
IOUtils.copyFilesFromAssets(mContext, assetBotPath, toPath, needsUpdate);
//替换换行符
fixString(stringfile.getAbsolutePath());
fixString(botfile.getAbsolutePath());
return ERROR_NONE;
}
private void fixString(String stringfile) {
......
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