Commit c0751e14 authored by feihuaduo's avatar feihuaduo

修复资源文件不复制的问题

parent 97c88374
......@@ -450,10 +450,16 @@ public class AppsSettings {
mSharedPreferences.putString(Constants.PREF_GAME_PATH, path);
}
//获取卡组文件夹
public String getDeckDir() {
return new File(getResourcePath(), Constants.CORE_DECK_PATH).getAbsolutePath();
}
//获取残局文件夹
public String getSingleDir() {
return new File(getResourcePath(), Constants.CORE_SINGLE_PATH).getAbsolutePath();
}
/**
* 隐藏底部导航栏
*/
......
......@@ -15,6 +15,7 @@ import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import java.io.IOException;
......@@ -176,24 +177,34 @@ public class MainActivity extends HomeActivity{
@Override
public void updateImages() {
Log.e("MainActivity","重置资源");
DialogPlus dialog = DialogPlus.show(this, null, getString(R.string.message));
dialog.show();
VUiKit.defer().when(() -> {
if (IOUtils.hasAssets(this, getDatapath(Constants.CORE_PICS_ZIP))) {
Log.e("MainActivity","开始复制");
try {
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.CORE_PICS_ZIP),
AppsSettings.get().getResourcePath(), true);
IOUtils.createNoMedia(AppsSettings.get().getResourcePath());
if (IOUtils.hasAssets(this, getDatapath(Constants.CORE_PICS_ZIP))) {
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.CORE_PICS_ZIP),
AppsSettings.get().getResourcePath(), true);
}
if (IOUtils.hasAssets(this, getDatapath(Constants.CORE_SCRIPTS_ZIP))) {
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.CORE_SCRIPTS_ZIP),
AppsSettings.get().getResourcePath(), true);
}
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.DATABASE_NAME),
AppsSettings.get().getResourcePath(), true);
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.CORE_SCRIPTS_ZIP),
AppsSettings.get().getResourcePath(), true);
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.CORE_STRING_PATH),
AppsSettings.get().getResourcePath(), true);
IOUtils.copyFilesFromAssets(this, getDatapath(Constants.CORE_SKIN_PATH),
AppsSettings.get().getCoreSkinPath(), true);
} catch (IOException e) {
e.printStackTrace();
Log.e("MainActivity","错误"+e);
}
}
}).done((rs) -> {
Log.e("MainActivity","复制完毕");
dialog.dismiss();
});
}
......
......@@ -21,6 +21,7 @@ import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.utils.FileLogUtil;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.SystemUtils;
......@@ -114,8 +115,11 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
//res
try {
String resPath = mSettings.getResourcePath();
//创建游戏目录
IOUtils.createNoMedia(resPath);
//检查文件夹
checkDirs();
//复制游戏配置文件
copyCoreConfig(resPath, needsUpdate);
if (AppsSettings.get().isUseExtraCards()) {
//自定义数据库无效,则用默认的
......@@ -123,61 +127,49 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
AppsSettings.get().setUseExtraCards(false);
}
}
/* if (needsUpdate) {
* if(AppsSettings.get().resetGameVersion() == 0){
* VUiKit.show(mContext, mContext.getString(R.string.reset_game_ver_fail));
* }
* }*/
//设置字体
ConfigManager systemConf = DataManager.openConfig(mSettings.getSystemConfig());
systemConf.setFontSize(mSettings.getFontSize());
systemConf.close();
// copyCoreConfig(new File(mSettings.getResourcePath(), GameSettings.CORE_CONFIG_PATH).getAbsolutePath());
//如果是新版本
if (needsUpdate) {
//复制卡组
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.tip_new_deck)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_DECK_PATH),
new File(resPath, Constants.CORE_DECK_PATH).getAbsolutePath(), needsUpdate);
}
if (needsUpdate) {
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.game_skins)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_SKIN_PATH),
mSettings.getCoreSkinPath(), false, mSettings.isPendulumScale());
}
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.font_files)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.FONT_DIRECTORY),
mSettings.getFontDirPath(), false);
if (needsUpdate) {
mSettings.getDeckDir(), needsUpdate);
//复制残局
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.single_lua)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_SINGLE_PATH),
new File(resPath, Constants.CORE_SINGLE_PATH).getAbsolutePath(), needsUpdate);
mSettings.getSingleDir(), needsUpdate);
}
//复制资源
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.game_skins)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_SKIN_PATH),
mSettings.getCoreSkinPath(), needsUpdate);
//复制字体
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.font_files)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.FONT_DIRECTORY),
mSettings.getFontDirPath(), needsUpdate);
//复制脚本压缩包
if (IOUtils.hasAssets(mContext, getDatapath(Constants.CORE_SCRIPTS_ZIP))) {
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.scripts)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_SCRIPTS_ZIP),
resPath, needsUpdate);
}
//复制数据库
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.cards_cdb)));
copyCdbFile(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);
}
//if (needsUpdate) {
File filesDir = mContext.getFilesDir();
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH),
filesDir.getPath(), needsUpdate);
// }
if (needsUpdate) {
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.ex_pack)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_EXPANSIONS),
mSettings.getExpansionsPath().getAbsolutePath(), true, needsUpdate);
}
//checkWindbot();
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH),
mContext.getFilesDir().getPath(), needsUpdate);
han.sendEmptyMessage(0);
loadData();
......@@ -189,7 +181,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
return ERROR_NONE;
}
private void loadData(){
private void loadData() {
setMessage(mContext.getString(R.string.loading));
DataManager.get().load(false);
}
......@@ -197,7 +189,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
void copyCdbFile(boolean needsUpdate) throws IOException {
File dbFile = new File(mSettings.getDataBasePath(), DATABASE_NAME);
boolean copyDb = true;
if (dbFile.exists()) {
if (dbFile.exists()&&dbFile.length()<1024*1024) {
copyDb = false;
if (needsUpdate) {
copyDb = true;
......@@ -269,14 +261,27 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
}
private void checkDirs() {
String[] dirs = {Constants.CORE_SCRIPT_PATH,
String[] dirs = {
//脚本文件夹
Constants.CORE_SCRIPT_PATH,
//残局文件夹
Constants.CORE_SINGLE_PATH,
//卡组文件夹
Constants.CORE_DECK_PATH,
//录像文件夹
Constants.CORE_REPLAY_PATH,
//字体文件夹
Constants.FONT_DIRECTORY,
//资源文件夹
Constants.CORE_SKIN_PATH,
//卡图文件夹
Constants.CORE_IMAGE_PATH,
//log文件夹
Constants.MOBILE_LOG,
Constants.MOBILE_DECK_SHARE
//卡组分享截图文件夹
Constants.MOBILE_DECK_SHARE,
//额外卡库文件夹
Constants.CORE_EXPANSIONS
};
File dirFile = null;
for (String dir : dirs) {
......
......@@ -384,8 +384,6 @@ public class SettingFragment extends PreferenceFragmentPlus {
process.waitFor();
IOUtils.delete(soFile);
Log.e("SettingFragment", "file: " + file);
Log.e("SettingFragment", "path: " + soFile.getAbsolutePath());
IOUtils.copyFile(file, soFile.getAbsolutePath(), true);
me.what = COPY_SO_OK;
} catch (Exception e) {
......
......@@ -107,10 +107,6 @@ public class IOUtils {
}
public static int copyFilesFromAssets(Context context, String assets, String toPath, boolean update) throws IOException {
return copyFilesFromAssets(context, assets, toPath, update, true);
}
public static int copyFilesFromAssets(Context context, String assets, String toPath, boolean update, boolean sub) throws IOException {
AssetManager am = context.getAssets();
String[] files = am.list(assets);
if (files == 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