修改
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
server:
|
server:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 8849
|
port: 8849
|
||||||
path: C:\Users\MSI\AppData\Roaming\dzsp_shijingjun_offline_Y_save
|
path: C:\Users\Administrator\AppData\Roaming\dzsp_shijingjun_offline_Y_save
|
||||||
poi:
|
poi:
|
||||||
global:
|
global:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
@ -12,9 +12,10 @@ import { GetHomeDir } from './config'
|
|||||||
import { start, getServer } from "./app";
|
import { start, getServer } from "./app";
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
const yaml = require("js-yaml");
|
const yaml = require("js-yaml");
|
||||||
let Store = require('electron-store')
|
// 移除 electron-store,使用 Electron 提供的用户数据目录
|
||||||
Store.initRenderer();
|
// let Store = require('electron-store')
|
||||||
const store = new Store()
|
// Store.initRenderer();
|
||||||
|
// const store = new Store()
|
||||||
|
|
||||||
|
|
||||||
process.on('unhandledRejection', (reason) => {
|
process.on('unhandledRejection', (reason) => {
|
||||||
@ -147,7 +148,8 @@ function createWindow(): void {
|
|||||||
ymlBatPath = process.platform === 'win32' ? ymlBatPath.replace(/^(\w:)/, '/$1') : ymlBatPath
|
ymlBatPath = process.platform === 'win32' ? ymlBatPath.replace(/^(\w:)/, '/$1') : ymlBatPath
|
||||||
let ymlPath = ymlBatPath.substring(1, 200)
|
let ymlPath = ymlBatPath.substring(1, 200)
|
||||||
const ymlContent = yaml.load(fs.readFileSync(ymlPath, 'utf8'));
|
const ymlContent = yaml.load(fs.readFileSync(ymlPath, 'utf8'));
|
||||||
ymlContent.server.path = path.dirname(store.path)
|
ymlContent.server.path = app.getPath('userData')
|
||||||
|
// ymlContent.server.path = path.dirname(store.path)
|
||||||
fs.writeFileSync(ymlPath, yaml.dump(ymlContent));
|
fs.writeFileSync(ymlPath, yaml.dump(ymlContent));
|
||||||
ipcMain.on("getIniConfig", (event, option) => {
|
ipcMain.on("getIniConfig", (event, option) => {
|
||||||
let ymlPath = ymlBatPath.substring(1, 200)
|
let ymlPath = ymlBatPath.substring(1, 200)
|
||||||
@ -215,6 +217,38 @@ function createWindow(): void {
|
|||||||
event.sender.send("selectedItem", arr);
|
event.sender.send("selectedItem", arr);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
ipcMain.handle('get-user-data-path', () => {
|
||||||
|
return app.getPath('userData')
|
||||||
|
});
|
||||||
|
ipcMain.on('import-project-override', async (event, { srcZip, dst }) => {
|
||||||
|
try {
|
||||||
|
const compressing = require('compressing')
|
||||||
|
await compressing.zip.uncompress(srcZip, dst)
|
||||||
|
event.sender.send('import-project-override-res', { ok: true })
|
||||||
|
} catch (e: any) {
|
||||||
|
event.sender.send('import-project-override-res', { ok: false, error: e.message })
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ipcMain.on("export-project", (event, { dst }) => {
|
||||||
|
try {
|
||||||
|
const archiver = require('archiver');
|
||||||
|
const output = fs.createWriteStream(dst);
|
||||||
|
const archive = archiver('zip', { zlib: { level: 9 } });
|
||||||
|
output.on('close', () => {
|
||||||
|
event.sender.send('export-project-res', { ok: true });
|
||||||
|
});
|
||||||
|
archive.on('error', (err) => {
|
||||||
|
event.sender.send('export-project-res', { ok: false, error: err.message });
|
||||||
|
});
|
||||||
|
archive.pipe(output);
|
||||||
|
const dbPath = path.join(app.getPath('userData'), 'app.db');
|
||||||
|
console.log('dbPath', dbPath);
|
||||||
|
archive.file(dbPath, { name: 'app.db' });
|
||||||
|
archive.finalize();
|
||||||
|
} catch (e: any) {
|
||||||
|
event.sender.send('export-project-res', { ok: false, error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
ipcMain.on("saveFile", (event, { title, filename, filters }) => {
|
ipcMain.on("saveFile", (event, { title, filename, filters }) => {
|
||||||
dialog
|
dialog
|
||||||
.showSaveDialog({
|
.showSaveDialog({
|
||||||
|
|||||||
@ -521,35 +521,28 @@ const importProject = () => {
|
|||||||
if (paths.length > 0) {
|
if (paths.length > 0) {
|
||||||
// let loadingInstance = this.$openLoading('拼命导入中...')
|
// let loadingInstance = this.$openLoading('拼命导入中...')
|
||||||
importWin = false
|
importWin = false
|
||||||
let arr = getElectronPath().replaceAll('\\', '/').split('/')
|
const { ipcRenderer } = require('electron')
|
||||||
console.log(arr, 'arrarr')
|
ipcRenderer.invoke('get-user-data-path').then((userDataPath) => {
|
||||||
arr.pop()
|
ipcRenderer.send('import-project-override', { srcZip: paths[0], dst: userDataPath })
|
||||||
// let path: any = 'C:/Users/Administrator/AppData/Roaming/yjearth'
|
ipcRenderer.once('import-project-override-res', (ev, res) => {
|
||||||
console.log(paths[0], arr.join('/'), 'pathpath')
|
if (res && res.ok) {
|
||||||
unzip_file(paths[0], arr.join('/'))
|
setTimeout(() => {
|
||||||
.then((res) => {
|
ElMessage({
|
||||||
// loadingInstance.close()
|
message: '载入成功,将在2s后自动重启',
|
||||||
// ElMessage({
|
type: 'success'
|
||||||
// message: '导入成功',
|
})
|
||||||
// type: 'success'
|
}, 1000)
|
||||||
// })
|
setTimeout(() => {
|
||||||
setTimeout(() => {
|
$sendElectronChanel('restart')
|
||||||
|
}, 3000)
|
||||||
|
} else {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: '载入成功,将在2s后自动重启',
|
message: res?.error || '导入失败',
|
||||||
type: 'success'
|
type: 'warning'
|
||||||
})
|
})
|
||||||
}, 1000)
|
}
|
||||||
setTimeout(() => {
|
|
||||||
$sendElectronChanel('restart')
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err)
|
|
||||||
ElMessage({
|
|
||||||
message: err,
|
|
||||||
type: 'warning'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
importWin = false
|
importWin = false
|
||||||
}
|
}
|
||||||
@ -657,31 +650,41 @@ function derive() {
|
|||||||
$sendElectronChanel('saveFile', option)
|
$sendElectronChanel('saveFile', option)
|
||||||
$recvElectronChanel('selectedFileItem', (e, path) => {
|
$recvElectronChanel('selectedFileItem', (e, path) => {
|
||||||
if (path) {
|
if (path) {
|
||||||
// if (result.canceled) {
|
const { ipcRenderer } = require('electron')
|
||||||
// this.exportWin = !this.exportWin
|
ipcRenderer.send('export-project', { dst: path })
|
||||||
// return
|
ipcRenderer.once('export-project-res', (ev, res) => {
|
||||||
// }
|
if (res && res.ok) {
|
||||||
// let loadingInstance = this.$openLoading('拼命导出中...')
|
|
||||||
// exportWin = !exportWin
|
|
||||||
let arr = getElectronPath().replaceAll('\\', '/').split('/')
|
|
||||||
arr.pop()
|
|
||||||
arr[arr.length - 1] = 'yjearth/app.db'
|
|
||||||
let db_path: any = arr.join('/')
|
|
||||||
// let db_path: any = 'C:/Users/Administrator/AppData/Roaming/yjearth/app.db'
|
|
||||||
try {
|
|
||||||
zip_file([db_path], path, () => {
|
|
||||||
// loadingInstance.close()
|
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: '导出完成',
|
message: '导出完成',
|
||||||
type: 'success'
|
type: 'success'
|
||||||
})
|
})
|
||||||
})
|
} else {
|
||||||
} catch (error) {
|
ElMessage({
|
||||||
ElMessage({
|
message: res?.error || '导出失败',
|
||||||
message: error,
|
type: 'error'
|
||||||
type: 'error'
|
})
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
|
// let arr = getElectronPath().replaceAll('\\', '/').split('/')
|
||||||
|
// arr.pop()
|
||||||
|
// arr[arr.length - 1] = 'yjearth/app.db'
|
||||||
|
// let db_path: any = arr.join('/')
|
||||||
|
// console.log(db_path, 'db_pathdb_path')
|
||||||
|
// try {
|
||||||
|
// zip_file([db_path], path, () => {
|
||||||
|
// // loadingInstance.close()
|
||||||
|
// ElMessage({
|
||||||
|
// message: '导出完成',
|
||||||
|
// type: 'success'
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
// } catch (error) {
|
||||||
|
// ElMessage({
|
||||||
|
// message: error,
|
||||||
|
// type: 'error'
|
||||||
|
// })
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user