Commit fe75d12e authored by fallenstardust's avatar fallenstardust

仅在没有卡组时复制sample卡组

parent 2bd454ba
...@@ -12,9 +12,11 @@ import android.os.Handler; ...@@ -12,9 +12,11 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import cn.garymb.ygomobile.AppsSettings; import cn.garymb.ygomobile.AppsSettings;
...@@ -207,10 +209,12 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> { ...@@ -207,10 +209,12 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
//如果是新版本 //如果是新版本
if (needsUpdate) { if (needsUpdate) {
//复制卡组 //复制卡组
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.tip_new_deck))); File deckFiles = new File(mSettings.getDeckDir());
if (deckFiles.list().length == 0) {
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_DECK_PATH), setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.tip_new_deck)));
mSettings.getDeckDir(), needsUpdate); IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_DECK_PATH),
mSettings.getDeckDir(), needsUpdate);
}
//复制卡包 //复制卡包
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_PACK_PATH), IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_PACK_PATH),
mSettings.get().getPackDeckDir(), needsUpdate); mSettings.get().getPackDeckDir(), needsUpdate);
...@@ -263,7 +267,8 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> { ...@@ -263,7 +267,8 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
han.sendEmptyMessage(0); han.sendEmptyMessage(0);
loadData(); loadData();
} catch (Exception e) { } catch (
Exception e) {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.e(TAG, "check", e); Log.e(TAG, "check", e);
return ERROR_COPY; return ERROR_COPY;
......
...@@ -6,6 +6,7 @@ import android.content.res.AssetManager; ...@@ -6,6 +6,7 @@ import android.content.res.AssetManager;
import android.os.Build; import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
...@@ -48,7 +49,7 @@ public class IOUtils { ...@@ -48,7 +49,7 @@ public class IOUtils {
if (file == null || !file.exists()) return; if (file == null || !file.exists()) return;
if (file.isFile()) { if (file.isFile()) {
file.delete(); file.delete();
} else if(file.isDirectory()){ } else if (file.isDirectory()) {
File[] files = file.listFiles(); File[] files = file.listFiles();
if (files != null) { if (files != null) {
for (File f : files) { for (File f : files) {
...@@ -123,12 +124,12 @@ public class IOUtils { ...@@ -123,12 +124,12 @@ public class IOUtils {
InputStream inputStream = null; InputStream inputStream = null;
try { try {
inputStream = am.open(assets); inputStream = am.open(assets);
}catch (Exception e){ } catch (Exception e) {
Toast.makeText(context, "copyFilesFromAssets error" + e, Toast.LENGTH_SHORT).show();
} }
if(inputStream != null) { if (inputStream != null) {
copyToFile(inputStream, tofile.getAbsolutePath()); copyToFile(inputStream, tofile.getAbsolutePath());
}else{ } else {
return 0; return 0;
} }
} }
...@@ -161,15 +162,17 @@ public class IOUtils { ...@@ -161,15 +162,17 @@ public class IOUtils {
return count; return count;
} }
} }
public static void createFolderByFile(File file) { public static void createFolderByFile(File file) {
File dir = file.getParentFile(); File dir = file.getParentFile();
if (dir != null && !dir.exists()) { if (dir != null && !dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
} }
public static boolean createFolder(File file) { public static boolean createFolder(File file) {
if (!file.exists()) { if (!file.exists()) {
return file.mkdirs(); return file.mkdirs();
} }
return false; return false;
} }
...@@ -238,13 +241,12 @@ public class IOUtils { ...@@ -238,13 +241,12 @@ public class IOUtils {
os.write(buffer, 0, len); os.write(buffer, 0, len);
} }
} finally { } finally {
if (os!=null) if (os != null)
os.close(); os.close();
is.close(); is.close();
} }
return new File(outPath); return new File(outPath);
} }
} }
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