Commit 7253dcd1 authored by fallenstardust's avatar fallenstardust

重置资源时也按照设定语言进行复制资料

parent b9294916
......@@ -6,10 +6,8 @@ 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_DECK_PATH;
import static cn.garymb.ygomobile.Constants.CORE_EXPANSIONS;
import static cn.garymb.ygomobile.Constants.CORE_LIMIT_PATH;
import static cn.garymb.ygomobile.Constants.CORE_PACK_PATH;
import static cn.garymb.ygomobile.Constants.CORE_REPLAY_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;
......@@ -238,7 +236,7 @@ public class AppsSettings {
public File[] getExpansionFiles() {
return new File(AppsSettings.get().getResourcePath(), Constants.CORE_EXPANSIONS)
return new File(getResourcePath(), Constants.CORE_EXPANSIONS)
.listFiles((file) -> {
if (!file.isFile()) {
return false;
......@@ -726,8 +724,8 @@ public class AppsSettings {
IOUtils.copyFilesFromAssets(context, getDatapath("conf") + "/" + CORE_STRING_PATH, getResourcePath(), true);
IOUtils.copyFilesFromAssets(context, getDatapath("conf") + "/" + BOT_CONF, getResourcePath(), true);
//替换换行符
String stringConfPath = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(AppsSettings.get().getResourcePath(), BOT_CONF).getAbsolutePath();
String stringConfPath = new File(getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(getResourcePath(), BOT_CONF).getAbsolutePath();
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为0=中文
......@@ -744,8 +742,8 @@ public class AppsSettings {
IOUtils.copyFilesFromAssets(context, korStringConf, getResourcePath(), true);
IOUtils.copyFilesFromAssets(context, korBotConf, getResourcePath(), true);
//替换换行符
String stringConfPath = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(AppsSettings.get().getResourcePath(), BOT_CONF).getAbsolutePath();
String stringConfPath = new File(getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(getResourcePath(), BOT_CONF).getAbsolutePath();
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为1=조선말
......@@ -764,20 +762,20 @@ public class AppsSettings {
IOUtils.copyFilesFromAssets(context, enStringConf, getResourcePath(), true);
IOUtils.copyFilesFromAssets(context, enBotConf, getResourcePath(), true);
//替换换行符
String stringConfPath = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(AppsSettings.get().getResourcePath(), BOT_CONF).getAbsolutePath();
String stringConfPath = new File(getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(getResourcePath(), BOT_CONF).getAbsolutePath();
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为2=English
setDataLanguage(2);
}
private void fixString(String stringPath) {
public void fixString(String stringPath) {
List<String> lines = FileUtils.readLines(stringPath, Constants.DEF_ENCODING);
FileUtils.writeLines(stringPath, lines, Constants.DEF_ENCODING, "\n");
}
private void copyCdbFile(String cdbPath) throws IOException {
public void copyCdbFile(String cdbPath) throws IOException {
File dbFile = new File(getDataBasePath(), DATABASE_NAME);
if (dbFile.exists()) dbFile.delete();//如果数据库存在先删除
IOUtils.copyFilesFromAssets(context, cdbPath, getDataBasePath(), true);
......
......@@ -10,7 +10,6 @@ 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;
......@@ -194,7 +193,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
Log.d(TAG, "check start");
boolean needsUpdate = isNewVersion;
//清空下载缓存
File imgDir = new File(AppsSettings.get().getCardImagePath());
File imgDir = new File(mSettings.getCardImagePath());
File[] files = imgDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
......@@ -215,10 +214,10 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.createNoMedia(resPath);
//检查文件夹
checkDirs();
if (AppsSettings.get().isUseExtraCards()) {
if (mSettings.isUseExtraCards()) {
//自定义数据库无效,则用默认的
if (!CardManager.checkDataBase(AppsSettings.get().getDataBaseFile())) {
AppsSettings.get().setUseExtraCards(false);
if (!CardManager.checkDataBase(mSettings.getDataBaseFile())) {
mSettings.setUseExtraCards(false);
}
}
//如果是新版本
......@@ -316,7 +315,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
copyCoreConfig(getDatapath("conf") + "/" + CORE_STRING_PATH,
getDatapath("conf") + "/" + BOT_CONF,
mSettings.getResourcePath(), needsUpdate);
AppsSettings.get().setDataLanguage(0);
mSettings.setDataLanguage(0);
return ERROR_NONE;
}
......@@ -332,7 +331,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.copyFilesFromAssets(mContext, enSingle, mSettings.getSingleDir(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(enStringConf, enBotConf, mSettings.getResourcePath(), needsUpdate);
AppsSettings.get().setDataLanguage(2);
mSettings.setDataLanguage(2);
return ERROR_NONE;
}
......@@ -348,7 +347,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.copyFilesFromAssets(mContext, korSingle, mSettings.getSingleDir(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(korStringConf, korBotConf, mSettings.getResourcePath(), needsUpdate);
//AppsSettings.get().setDataLanguage(1);
mSettings.setDataLanguage(1);
return ERROR_NONE;
}
......@@ -426,9 +425,9 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
}
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);
File systemfile = new File(mSettings.getResourcePath(), CORE_SYSTEM_PATH);
File stringfile = new File(mSettings.getResourcePath(), CORE_STRING_PATH);
File botfile = new File(mSettings.getResourcePath(), BOT_CONF);
if (!systemfile.exists()) {
IOUtils.copyFilesFromAssets(mContext, getDatapath("conf") + "/" + CORE_SYSTEM_PATH, toPath, false);
}
......
......@@ -35,12 +35,10 @@ import static cn.garymb.ygomobile.Constants.SETTINGS_AVATAR;
import static cn.garymb.ygomobile.Constants.SETTINGS_CARD_BG;
import static cn.garymb.ygomobile.Constants.SETTINGS_COVER;
import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION;
import static cn.garymb.ygomobile.Constants.URL_YGO233_DOWNLOAD_LINK;
import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
......@@ -65,8 +63,6 @@ import android.widget.Toast;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.signature.MediaStoreSignature;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
......@@ -80,16 +76,13 @@ import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter;
import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.ui.home.ResCheckTask;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.OkhttpUtil;
import cn.garymb.ygomobile.utils.SharedPreferenceUtil;
import cn.garymb.ygomobile.utils.SystemUtils;
import cn.garymb.ygomobile.utils.glide.GlideCompat;
import kotlin.collections.IndexedValue;
import ocgcore.DataManager;
import okhttp3.Call;
import okhttp3.Callback;
......@@ -141,7 +134,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
@Override
protected SharedPreferences getSharedPreferences() {
return AppsSettings.get().getSharedPreferences();
return mSettings.getSharedPreferences();
}
@Override
......@@ -191,10 +184,10 @@ public class SettingFragment extends PreferenceFragmentPlus {
super.onPreferenceChange(preference, value);
if (!isInit) {
/*if (PREF_GAME_VERSION.equals(preference.getKey())) {
int v = AppsSettings.get().getVersionValue(value.toString());
if (v > 0 && v <= AppsSettings.get().getVersionValue("0xF99F")) {
int v = mSettings.getVersionValue(value.toString());
if (v > 0 && v <= mSettings.getVersionValue("0xF99F")) {
mSettings.setGameVersion(v);
super.onPreferenceChange(preference, AppsSettings.get().getVersionString(v));
super.onPreferenceChange(preference, mSettings.getVersionString(v));
return true;
} else {
if (BuildConfig.DEBUG) {
......@@ -308,7 +301,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
});
}
if (PREF_DEL_EX.equals(key)) {
File[] ypks = new File(AppsSettings.get().getExpansionsPath().getAbsolutePath()).listFiles();
File[] ypks = new File(mSettings.getExpansionsPath().getAbsolutePath()).listFiles();
List<String> list = new ArrayList<>();
for (int i = 0; i < ypks.length; i++) {
list.add(ypks[i].getName());
......@@ -585,46 +578,60 @@ public class SettingFragment extends PreferenceFragmentPlus {
}
public void updateImages() {
Log.e("MainActivity", "重置资源");
DialogPlus dialog = DialogPlus.show(getContext(), null, getString(R.string.message));
dialog.show();
VUiKit.defer().when(() -> {
Log.e("MainActivity", "开始复制");
try {
IOUtils.createNoMedia(AppsSettings.get().getResourcePath());
FileUtils.delFile(AppsSettings.get().getResourcePath() + "/" + Constants.CORE_SCRIPT_PATH);
//.nomedia
IOUtils.createNoMedia(mSettings.getResourcePath());
//删除script文件夹,因为已经直接从scripts.zip读取script
FileUtils.delFile(mSettings.getResourcePath() + "/" + Constants.CORE_SCRIPT_PATH);
//复制卡图包
if (IOUtils.hasAssets(getContext(), getDatapath(Constants.CORE_PICS_ZIP))) {
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.CORE_PICS_ZIP),
AppsSettings.get().getResourcePath(), true);
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.CORE_PICS_ZIP), mSettings.getResourcePath(), true);
}
//复制脚本包
if (IOUtils.hasAssets(getContext(), getDatapath(Constants.CORE_SCRIPTS_ZIP))) {
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.CORE_SCRIPTS_ZIP),
AppsSettings.get().getResourcePath(), true);
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.CORE_SCRIPTS_ZIP), mSettings.getResourcePath(), true);
}
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.CORE_SKIN_PATH),
AppsSettings.get().getCoreSkinPath(), false);
String fonts = AppsSettings.get().getResourcePath() + "/" + Constants.FONT_DIRECTORY;
//复制textures下的贴图文件
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.CORE_SKIN_PATH), mSettings.getCoreSkinPath(), false);
//先删除已存在的字体再复制字体
String fonts = mSettings.getResourcePath() + "/" + Constants.FONT_DIRECTORY;
if (new File(fonts).list() != null)
FileUtils.delFile(fonts);
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.FONT_DIRECTORY),
AppsSettings.get().getFontDirPath(), true);
IOUtils.copyFilesFromAssets(getContext(), getDatapath(Constants.FONT_DIRECTORY), mSettings.getFontDirPath(), true);
//根据系统语言复制特定资料文件
String language = getContext().getResources().getConfiguration().locale.getLanguage();
if (!language.isEmpty()) {
if (mSettings.getDataLanguage() == -1) {
if (language.equals("zh")) {
mSettings.copyCnData();
} else if (language.equals("ko")) {
mSettings.copyKorData();
} else {
mSettings.copyEnData();
}
} else {
if (mSettings.getDataLanguage() == 0) mSettings.copyCnData();
if (mSettings.getDataLanguage() == 1) mSettings.copyKorData();
if (mSettings.getDataLanguage() == 2) mSettings.copyEnData();
}
}
/*
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.CORE_SOUND_PATH),
AppsSettings.get().getSoundPath(), false);*/
mSettings.getSoundPath(), false);*/
//复制原目录文件
if (new File(ORI_DECK).list() != null)
FileUtils.copyDir(ORI_DECK, AppsSettings.get().getDeckDir(), false);
FileUtils.copyDir(ORI_DECK, mSettings.getDeckDir(), false);
if (new File(ORI_REPLAY).list() != null)
FileUtils.copyDir(ORI_REPLAY, AppsSettings.get().getResourcePath() + "/" + Constants.CORE_REPLAY_PATH, false);
FileUtils.copyDir(ORI_REPLAY, mSettings.getResourcePath() + "/" + Constants.CORE_REPLAY_PATH, false);
if (new File(ORI_PICS).list() != null)
FileUtils.copyDir(ORI_PICS, AppsSettings.get().getCardImagePath(), false);
FileUtils.copyDir(ORI_PICS, mSettings.getCardImagePath(), false);
} catch (IOException e) {
e.printStackTrace();
Log.e("MainActivity", "错误" + e);
Log.e("SettingFragment", "错误" + e);
}
}).done((rs) -> {
Toast.makeText(getContext(), R.string.done, Toast.LENGTH_SHORT).show();
......
......@@ -50,9 +50,11 @@ public class SharedPreferenceUtil {
return getShareRecord().getInt("StartTimes", 0);
}
public static void setExpansionDataVer(String json){
public static void setExpansionDataVer(String json) {
getShareRecord().edit().putString("ExpansionsDataVer", json).commit();
};
}
;
public static String getExpansionDataVer() {
return getShareRecord().getString("ExpansionsDataVer", null);
......
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