Commit c0751e14 authored by feihuaduo's avatar feihuaduo

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

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