Former-commit-id: 2fbb67d39db7aba0f55de5790bbb01dce3285e19
This commit is contained in:
troyeguo
2021-06-14 13:02:30 +08:00
parent d509b0a1cf
commit 77e384bb79
2 changed files with 63 additions and 34 deletions

View File

@@ -166,24 +166,44 @@ class Header extends React.Component<HeaderProps, HeaderState> {
.ipcRenderer.sendSync("storage-location", "ping");
let sourcePath = path.join(storageLocation, "config", "readerConfig.json");
let readerConfig: any;
try {
readerConfig = JSON.parse(
fs.readFileSync(sourcePath, { encoding: "utf8", flag: "r" })
);
} catch (error) {
BackupUtil.backup(
this.props.books,
this.props.notes,
this.props.bookmarks,
() => {
this.props.handleMessage("Sync Successfully");
this.props.handleMessageBox(true);
},
5,
() => {}
);
return;
}
fs.readFile(sourcePath, "utf8", (err, data) => {
if (err) {
BackupUtil.backup(
this.props.books,
this.props.notes,
this.props.bookmarks,
() => {
this.props.handleMessage("Sync Successfully");
this.props.handleMessageBox(true);
},
5,
() => {}
);
return;
}
const readerConfig = JSON.parse(data);
if (
readerConfig &&
localStorage.getItem("lastSyncTime") &&
parseInt(readerConfig.lastSyncTime) >
parseInt(localStorage.getItem("lastSyncTime")!)
) {
this.syncFromLocation();
} else {
//否则就把Koodo中数据同步到同步文件夹
BackupUtil.backup(
this.props.books,
this.props.notes,
this.props.bookmarks,
() => {
this.props.handleMessage("Sync Successfully");
this.props.handleMessageBox(true);
},
5,
() => {}
);
}
});
//如果同步文件夹的记录较新就从同步文件夹同步数据到Koodo
if (

View File

@@ -45,24 +45,33 @@ export const moveData = (
);
var zip = new AdmZip(path.join(dirPath, file.name));
zip.extractAllTo(/*target path*/ dataPath, /*overwrite*/ true);
try {
const fs = window.require("fs-extra");
fs.remove(path.join(dirPath, file.name), async (err) => {
if (err) console.log(err);
if (driveIndex === 4) {
let deleteBooks = books.map((item) => {
return localforage.removeItem(item.key);
});
await Promise.all(deleteBooks);
}
if (driveIndex === 5) {
handleFinish();
}
if (driveIndex === 4) {
let deleteBooks = books.map((item) => {
return localforage.removeItem(item.key);
});
} catch (e) {
console.error(e, "移动失败");
await Promise.all(deleteBooks);
}
if (driveIndex === 5) {
handleFinish();
}
// try {
// const fs = window.require("fs-extra");
// fs.remove(path.join(dirPath, file.name), async (err) => {
// if (err) console.log(err);
// if (driveIndex === 4) {
// let deleteBooks = books.map((item) => {
// return localforage.removeItem(item.key);
// });
// await Promise.all(deleteBooks);
// }
// if (driveIndex === 5) {
// handleFinish();
// }
// });
// } catch (e) {
// console.error(e, "移动失败");
// }
};
};
class SyncUtil {