Commit 5e5c45b2 authored by fallenstardust's avatar fallenstardust

打开ypk文件自动放到expansions并加载

parent f979a88a
......@@ -10,12 +10,15 @@ import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.util.Locale;
import cn.garymb.ygodata.YGOGameOptions;
import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.preference.SettingsActivity;
import cn.garymb.ygomobile.utils.FileUtils;
import ocgcore.DataManager;
import static cn.garymb.ygomobile.Constants.ACTION_OPEN_DECK;
import static cn.garymb.ygomobile.Constants.ACTION_OPEN_GAME;
......@@ -111,40 +114,82 @@ public class GameUriManager {
}
private void doUri(Uri uri) {
Intent startSeting = new Intent(activity, SettingsActivity.class);
if ("file".equals(uri.getScheme())) {
File file = new File(uri.getPath());
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
if (isDeckDir(file)) {
//deck目录
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
} else {
//非deck目录
File ydk = getDeckFile(new File(AppsSettings.get().getDeckDir()), getDeckName(uri));
FileUtils.copyFile(file, ydk);
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath());
if (file.getName().toLowerCase(Locale.US).endsWith(".ydk")) {
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
if (isDeckDir(file)) {
//deck目录
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
} else {
//非deck目录
File ydk = getDeckFile(new File(AppsSettings.get().getDeckDir()), getDeckName(uri));
FileUtils.copyFile(file, ydk);
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath());
}
activity.startActivity(startdeck);
} else if (file.getName().toLowerCase(Locale.US).endsWith(".ypk")) {
try {
FileUtils.moveFile(file.getAbsolutePath(), AppsSettings.get().getExpansionsPath().toString(), false);
if (!AppsSettings.get().isReadExpansions()) {
activity.startActivity(startSeting);
Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
} else {
DataManager.get().load(true);
Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(activity, activity.getString(R.string.ypk_failed_bcos) + e, Toast.LENGTH_LONG).show();
}
}
activity.startActivity(startdeck);
} else if ("content".equals(uri.getScheme())) {
try {
File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache");
File ydk = getDeckFile(dir, getDeckName(uri));
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), ydk);
} catch (Throwable e) {
e.printStackTrace();
} finally {
pfd.close();
File urifile = new File(uri.getPath());
if (urifile.getName().toLowerCase(Locale.US).endsWith(".ydk")) {
try {
File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache");
File ydk = getDeckFile(dir, getDeckName(uri));
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), ydk);
} catch (Throwable e) {
e.printStackTrace();
} finally {
pfd.close();
}
}
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath());
activity.startActivity(startdeck);
} catch (Throwable e) {
e.printStackTrace();
}
} else if (urifile.getName().toLowerCase(Locale.US).endsWith(".ypk")) {
try {
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), AppsSettings.get().getExpansionsPath());
if (!AppsSettings.get().isReadExpansions()) {
activity.startActivity(startSeting);
Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
} else {
DataManager.get().load(true);
Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(activity, activity.getString(R.string.ypk_failed_bcos) + e, Toast.LENGTH_LONG).show();
} finally {
pfd.close();
}
}
} catch (Throwable e) {
}
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath());
activity.startActivity(startdeck);
} catch (Throwable e) {
e.printStackTrace();
}
} else {
String host = uri.getHost();
......
......@@ -278,4 +278,7 @@
<string name="tip_expansions_image">카드의 고화질 이미지가 없습니다.</string>
<string name="tip_return_to_duel">이미 돌아 가기 현재 게임</string>
<string name="my_favorites">즐겨 찾기★</string>
<string name="ypk_installed">expansion file installed</string>
<string name="ypk_go_setting">check \"Use Expansions\" to use it</string>
<string name="ypk_failed_bcos">expansion file install failed, because\:</string>
</resources>
......@@ -277,4 +277,7 @@
<string name="tip_expansions_image">非自带卡片没有大图</string>
<string name="tip_return_to_duel">已回到当前游戏</string>
<string name="my_favorites">我的收藏★</string>
<string name="ypk_installed">拓展卡包文件已安装</string>
<string name="ypk_go_setting">这是拓展卡包文件,要使用须启用扩展卡包</string>
<string name="ypk_failed_bcos">拓展卡包安装失败,原因:</string>
</resources>
......@@ -280,4 +280,7 @@
<string name="tip_expansions_image">no Large image for pre-released data</string>
<string name="tip_return_to_duel">Current game has been Returned</string>
<string name="my_favorites">myFav★</string>
<string name="ypk_installed">expansion file installed</string>
<string name="ypk_go_setting">check \"Use Expansions\" to use it</string>
<string name="ypk_failed_bcos">expansion file install failed, because\:</string>
</resources>
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