Commit fe75d12e authored by fallenstardust's avatar fallenstardust

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

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