From a79c41a0e7499a68ad88c8ee9621282dd613e485 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 15 Oct 2019 10:05:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kunfei/bookshelf/help/DataRestore.java | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java b/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java index 22792d0a63..8a3055ed04 100644 --- a/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java +++ b/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java @@ -86,49 +86,69 @@ private void restoreConfig(String dirPath) { } private void restoreBookShelf(String file) { - String json = DocumentHelper.readString("myBookShelf.json", file); - if (json == null) return; - List bookShelfList = GsonUtils.parseJArray(json, BookShelfBean.class); - if (bookShelfList == null) return; - for (BookShelfBean bookshelf : bookShelfList) { - if (bookshelf.getNoteUrl() != null) { - DbHelper.getDaoSession().getBookShelfBeanDao().insertOrReplace(bookshelf); - } - if (bookshelf.getBookInfoBean().getNoteUrl() != null) { - DbHelper.getDaoSession().getBookInfoBeanDao().insertOrReplace(bookshelf.getBookInfoBean()); + try { + String json = DocumentHelper.readString("myBookShelf.json", file); + if (json == null) return; + List bookShelfList = GsonUtils.parseJArray(json, BookShelfBean.class); + if (bookShelfList == null) return; + for (BookShelfBean bookshelf : bookShelfList) { + if (bookshelf.getNoteUrl() != null) { + DbHelper.getDaoSession().getBookShelfBeanDao().insertOrReplace(bookshelf); + } + if (bookshelf.getBookInfoBean().getNoteUrl() != null) { + DbHelper.getDaoSession().getBookInfoBeanDao().insertOrReplace(bookshelf.getBookInfoBean()); + } } + } catch (Exception e) { + e.printStackTrace(); } } private void restoreBookSource(String file) { - String json = DocumentHelper.readString("myBookSource.json", file); - if (json == null) return; - List bookSourceBeans = GsonUtils.parseJArray(json, BookSourceBean.class); - if (bookSourceBeans == null) return; - BookSourceManager.addBookSource(bookSourceBeans); + try { + String json = DocumentHelper.readString("myBookSource.json", file); + if (json == null) return; + List bookSourceBeans = GsonUtils.parseJArray(json, BookSourceBean.class); + if (bookSourceBeans == null) return; + BookSourceManager.addBookSource(bookSourceBeans); + } catch (Exception e) { + e.printStackTrace(); + } } private void restoreSearchHistory(String file) { - String json = DocumentHelper.readString("myBookSearchHistory.json", file); - if (json == null) return; - List searchHistoryBeans = GsonUtils.parseJArray(json, SearchHistoryBean.class); - if (searchHistoryBeans == null) return; - DbHelper.getDaoSession().getSearchHistoryBeanDao().insertOrReplaceInTx(searchHistoryBeans); + try { + String json = DocumentHelper.readString("myBookSearchHistory.json", file); + if (json == null) return; + List searchHistoryBeans = GsonUtils.parseJArray(json, SearchHistoryBean.class); + if (searchHistoryBeans == null) return; + DbHelper.getDaoSession().getSearchHistoryBeanDao().insertOrReplaceInTx(searchHistoryBeans); + } catch (Exception e) { + e.printStackTrace(); + } } private void restoreReplaceRule(String file) { - String json = DocumentHelper.readString("myBookReplaceRule.json", file); - if (json == null) return; - List replaceRuleBeans = GsonUtils.parseJArray(json, ReplaceRuleBean.class); - if (replaceRuleBeans == null) return; - ReplaceRuleManager.addDataS(replaceRuleBeans); + try { + String json = DocumentHelper.readString("myBookReplaceRule.json", file); + if (json == null) return; + List replaceRuleBeans = GsonUtils.parseJArray(json, ReplaceRuleBean.class); + if (replaceRuleBeans == null) return; + ReplaceRuleManager.addDataS(replaceRuleBeans); + } catch (Exception e) { + e.printStackTrace(); + } } private void restoreTxtChapterRule(String file) { - String json = DocumentHelper.readString("myTxtChapterRule.json", file); - if (json == null) return; - List ruleBeanList = GsonUtils.parseJArray(json, TxtChapterRuleBean.class); - if (ruleBeanList == null) return; - TxtChapterRuleManager.save(ruleBeanList); + try { + String json = DocumentHelper.readString("myTxtChapterRule.json", file); + if (json == null) return; + List ruleBeanList = GsonUtils.parseJArray(json, TxtChapterRuleBean.class); + if (ruleBeanList == null) return; + TxtChapterRuleManager.save(ruleBeanList); + } catch (Exception e) { + e.printStackTrace(); + } } }