Commit 0926ca5a authored by fallenstardust's avatar fallenstardust

根据语言复制配置文件

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