poi-plugin-kcsave-exporter 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/default-base.kcsave +0 -0
- package/index.es +64 -47
- package/lib/exporter.js +222 -323
- package/lib/kcsave-packer.js +155 -129
- package/lib/sqlite-writer.js +221 -284
- package/package.json +1 -1
|
Binary file
|
package/index.es
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
Button,
|
|
7
7
|
Callout,
|
|
8
8
|
Card,
|
|
9
|
-
Checkbox,
|
|
10
9
|
Divider,
|
|
11
10
|
Elevation,
|
|
12
11
|
Intent,
|
|
@@ -14,12 +13,22 @@ import {
|
|
|
14
13
|
} from '@blueprintjs/core'
|
|
15
14
|
import { dialog } from '@electron/remote'
|
|
16
15
|
import { ApiCaptureStore } from './lib/capture'
|
|
17
|
-
import {
|
|
16
|
+
import { exportPatchedKcsaveBuffer } from './lib/exporter'
|
|
18
17
|
|
|
18
|
+
const BASE_PATH_STORAGE_KEY = 'poi_plugin_kcsave_exporter_base_path_v2'
|
|
19
|
+
const DEFAULT_BASE_PATH = path.join(__dirname, 'assets', 'default-base.kcsave')
|
|
19
20
|
const captureStore = new ApiCaptureStore()
|
|
20
21
|
|
|
21
22
|
const formatTime = (ts) => (ts ? new Date(ts).toLocaleTimeString() : '未捕获')
|
|
22
23
|
|
|
24
|
+
const loadInitialBasePath = () => {
|
|
25
|
+
try {
|
|
26
|
+
const saved = window.localStorage?.getItem(BASE_PATH_STORAGE_KEY) || ''
|
|
27
|
+
if (saved && fs.existsSync(saved)) return saved
|
|
28
|
+
} catch (_) {}
|
|
29
|
+
return fs.existsSync(DEFAULT_BASE_PATH) ? DEFAULT_BASE_PATH : ''
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
const KcsaveExporter = () => {
|
|
24
33
|
const basic = useSelector((state) => state.info?.basic || {})
|
|
25
34
|
const shipsCount = useSelector((state) => Object.keys(state.info?.ships || {}).length)
|
|
@@ -28,8 +37,7 @@ const KcsaveExporter = () => {
|
|
|
28
37
|
const airbaseCount = useSelector((state) => (Array.isArray(state.info?.airbase) ? state.info.airbase.length : 0))
|
|
29
38
|
|
|
30
39
|
const [captured, setCaptured] = useState(() => ({ ...captureStore.data }))
|
|
31
|
-
const [baseFilePath, setBaseFilePath] = useState(
|
|
32
|
-
const [inheritOfflineProgress, setInheritOfflineProgress] = useState(true)
|
|
40
|
+
const [baseFilePath, setBaseFilePath] = useState(loadInitialBasePath)
|
|
33
41
|
const [exporting, setExporting] = useState(false)
|
|
34
42
|
const [status, setStatus] = useState(null)
|
|
35
43
|
const [lastStats, setLastStats] = useState(null)
|
|
@@ -42,26 +50,38 @@ const KcsaveExporter = () => {
|
|
|
42
50
|
return () => unsub()
|
|
43
51
|
}, [])
|
|
44
52
|
|
|
53
|
+
const isUsingDefault = baseFilePath === DEFAULT_BASE_PATH
|
|
54
|
+
|
|
45
55
|
const handlePickBase = useCallback(async () => {
|
|
46
56
|
try {
|
|
47
57
|
const res = await dialog.showOpenDialog({
|
|
48
|
-
title: '
|
|
58
|
+
title: '选择其他原单机版 .kcsave 存档作为基底',
|
|
49
59
|
filters: [{ name: 'KanColle Offline Save', extensions: ['kcsave'] }],
|
|
50
60
|
properties: ['openFile'],
|
|
51
61
|
})
|
|
52
62
|
const filePath = !res.canceled && res.filePaths?.[0]
|
|
53
63
|
if (filePath) {
|
|
54
64
|
setBaseFilePath(filePath)
|
|
55
|
-
|
|
65
|
+
try {
|
|
66
|
+
window.localStorage?.setItem(BASE_PATH_STORAGE_KEY, filePath)
|
|
67
|
+
} catch (_) {}
|
|
68
|
+
const sizeKb = (fs.statSync(filePath).size / 1024).toFixed(1)
|
|
69
|
+
setStatus({
|
|
70
|
+
text: `已切换基底存档:${path.basename(filePath)}(${sizeKb} KB)`,
|
|
71
|
+
intent: Intent.PRIMARY,
|
|
72
|
+
})
|
|
56
73
|
}
|
|
57
74
|
} catch (err) {
|
|
58
|
-
setStatus({ text:
|
|
75
|
+
setStatus({ text: `选择原存档失败:${err.message}`, intent: Intent.DANGER })
|
|
59
76
|
}
|
|
60
77
|
}, [])
|
|
61
78
|
|
|
62
|
-
const
|
|
63
|
-
setBaseFilePath(
|
|
64
|
-
|
|
79
|
+
const handleResetDefault = useCallback(() => {
|
|
80
|
+
setBaseFilePath(DEFAULT_BASE_PATH)
|
|
81
|
+
try {
|
|
82
|
+
window.localStorage?.removeItem(BASE_PATH_STORAGE_KEY)
|
|
83
|
+
} catch (_) {}
|
|
84
|
+
setStatus({ text: '已恢复为内置默认基底存档。', intent: Intent.NONE })
|
|
65
85
|
}, [])
|
|
66
86
|
|
|
67
87
|
const handleClearCache = useCallback(() => {
|
|
@@ -70,23 +90,24 @@ const KcsaveExporter = () => {
|
|
|
70
90
|
}, [])
|
|
71
91
|
|
|
72
92
|
const handleExport = useCallback(async () => {
|
|
93
|
+
const activeBase = baseFilePath || DEFAULT_BASE_PATH
|
|
94
|
+
if (!activeBase || !fs.existsSync(activeBase)) {
|
|
95
|
+
setStatus({ text: '未找到基底 .kcsave 存档,请先选择一个原存档。', intent: Intent.WARNING })
|
|
96
|
+
return
|
|
97
|
+
}
|
|
73
98
|
setExporting(true)
|
|
74
|
-
setStatus({ text: '
|
|
99
|
+
setStatus({ text: '正在基底存档上原地替换舰队数据并重算校验和...', intent: Intent.PRIMARY })
|
|
75
100
|
try {
|
|
76
101
|
const reduxState = typeof window.getStore === 'function' ? window.getStore() : {}
|
|
77
|
-
const baseBuf =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const { buffer, stats } = exportToKcsaveBuffer(reduxState, captureStore.data, baseBuf, {
|
|
81
|
-
inheritOfflineProgress: Boolean(baseBuf && inheritOfflineProgress),
|
|
82
|
-
})
|
|
102
|
+
const baseBuf = fs.readFileSync(activeBase)
|
|
103
|
+
const { buffer, stats } = exportPatchedKcsaveBuffer(reduxState, captureStore.data, baseBuf)
|
|
83
104
|
|
|
84
105
|
const safeName = (stats.nickname || 'admiral').replace(/[\\/:*?"<>|]/g, '_')
|
|
85
106
|
const stamp = new Date().toISOString().slice(0, 10).replace(/-/g, '')
|
|
86
107
|
const defaultPath = `kancolle-${safeName}-${stamp}.kcsave`
|
|
87
108
|
|
|
88
109
|
const res = await dialog.showSaveDialog({
|
|
89
|
-
title: '
|
|
110
|
+
title: '保存替换后的单机版 .kcsave 存档',
|
|
90
111
|
defaultPath,
|
|
91
112
|
filters: [{ name: 'KanColle Offline Save', extensions: ['kcsave'] }],
|
|
92
113
|
})
|
|
@@ -98,8 +119,12 @@ const KcsaveExporter = () => {
|
|
|
98
119
|
|
|
99
120
|
fs.writeFileSync(res.filePath, buffer)
|
|
100
121
|
setLastStats(stats)
|
|
122
|
+
const sizeStr =
|
|
123
|
+
buffer.length >= 1024 * 1024
|
|
124
|
+
? `${(buffer.length / 1024 / 1024).toFixed(2)} MB`
|
|
125
|
+
: `${(buffer.length / 1024).toFixed(1)} KB`
|
|
101
126
|
setStatus({
|
|
102
|
-
text:
|
|
127
|
+
text: `导出成功!已基于基底存档原地替换并保存至 ${res.filePath}(${sizeStr})`,
|
|
103
128
|
intent: Intent.SUCCESS,
|
|
104
129
|
})
|
|
105
130
|
} catch (err) {
|
|
@@ -110,7 +135,7 @@ const KcsaveExporter = () => {
|
|
|
110
135
|
} finally {
|
|
111
136
|
setExporting(false)
|
|
112
137
|
}
|
|
113
|
-
}, [baseFilePath
|
|
138
|
+
}, [baseFilePath])
|
|
114
139
|
|
|
115
140
|
const capAt = captured.capturedAt || {}
|
|
116
141
|
const furnitureCount = (captured.furnitureOwned || []).length
|
|
@@ -148,37 +173,33 @@ const KcsaveExporter = () => {
|
|
|
148
173
|
</div>
|
|
149
174
|
<Divider style={{ margin: '10px 0' }} />
|
|
150
175
|
<div style={{ fontSize: 12, opacity: 0.78 }}>
|
|
151
|
-
|
|
176
|
+
提示:默认已内置你的基准单机存档作为基底,同时兼容含 save.gz 或 slot-1.json 的单机存档;导出时会在基底 SQLite 数据库上原地替换舰队数据。
|
|
152
177
|
</div>
|
|
153
178
|
</Card>
|
|
154
179
|
|
|
155
180
|
<Card elevation={Elevation.ONE}>
|
|
156
|
-
<div style={{ fontSize: 12, marginBottom:
|
|
157
|
-
<strong
|
|
158
|
-
{
|
|
181
|
+
<div style={{ fontSize: 12, marginBottom: 10 }}>
|
|
182
|
+
<strong>当前基底存档:</strong>
|
|
183
|
+
<Tag intent={Intent.SUCCESS} minimal style={{ marginLeft: 4 }}>
|
|
184
|
+
{isUsingDefault ? '内置默认存档 (default-base.kcsave)' : path.basename(baseFilePath)}
|
|
185
|
+
</Tag>
|
|
159
186
|
</div>
|
|
160
|
-
<Checkbox
|
|
161
|
-
checked={inheritOfflineProgress}
|
|
162
|
-
disabled={!baseFilePath}
|
|
163
|
-
onChange={(e) => setInheritOfflineProgress(e.currentTarget.checked)}
|
|
164
|
-
label="继承模板中的单机进度(军费、任务进度与历史、活动海域、已探索节点、开发配方、图鉴与单机设置)"
|
|
165
|
-
style={{ fontSize: 12, marginBottom: 10 }}
|
|
166
|
-
/>
|
|
167
187
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
|
|
168
188
|
<Button
|
|
169
189
|
intent={Intent.PRIMARY}
|
|
170
190
|
icon="export"
|
|
191
|
+
disabled={!baseFilePath}
|
|
171
192
|
loading={exporting}
|
|
172
193
|
onClick={handleExport}
|
|
173
194
|
>
|
|
174
|
-
|
|
195
|
+
基于基底完全导出 .kcsave
|
|
175
196
|
</Button>
|
|
176
197
|
<Button icon="document-open" onClick={handlePickBase}>
|
|
177
|
-
|
|
198
|
+
更换其他基底 .kcsave
|
|
178
199
|
</Button>
|
|
179
|
-
{
|
|
180
|
-
<Button icon="
|
|
181
|
-
|
|
200
|
+
{!isUsingDefault && (
|
|
201
|
+
<Button icon="undo" onClick={handleResetDefault}>
|
|
202
|
+
恢复默认基底
|
|
182
203
|
</Button>
|
|
183
204
|
)}
|
|
184
205
|
<Button icon="trash" minimal onClick={handleClearCache}>
|
|
@@ -194,20 +215,16 @@ const KcsaveExporter = () => {
|
|
|
194
215
|
)}
|
|
195
216
|
|
|
196
217
|
{lastStats && (
|
|
197
|
-
<Callout title="
|
|
218
|
+
<Callout title="本次导出明细(基于基底存档原地替换)" intent={Intent.SUCCESS}>
|
|
198
219
|
<div style={{ fontSize: 12, lineHeight: 1.7 }}>
|
|
199
220
|
<div>
|
|
200
|
-
提督 {lastStats.nickname} (Lv.{lastStats.level}) |
|
|
201
|
-
舰队 {lastStats.decks} | 道具 {lastStats.inventory} | 家具 {lastStats.furniture}
|
|
202
|
-
|
|
203
|
-
|
|
221
|
+
提督 {lastStats.nickname} (Lv.{lastStats.level}) | Revision {lastStats.revision} | 舰娘 {lastStats.ships} |
|
|
222
|
+
装备 {lastStats.equipment} | 舰队 {lastStats.decks} | 道具 {lastStats.inventory} | 家具 {lastStats.furniture}
|
|
223
|
+
</div>
|
|
224
|
+
<div style={{ marginTop: 4 }}>
|
|
225
|
+
单机进度:军费 {lastStats.treasuryBalance} | 任务 {lastStats.quests}(历史 {lastStats.questHistoryCount}) |
|
|
226
|
+
海域 {lastStats.maps} | 活动 {lastStats.eventsCount} | 图鉴 {lastStats.albumShips}/{lastStats.albumEquips}
|
|
204
227
|
</div>
|
|
205
|
-
{lastStats.inheritedOffline && (
|
|
206
|
-
<div style={{ marginTop: 4 }}>
|
|
207
|
-
已继承单机进度:军费 {lastStats.inheritedOffline.treasuryBalance} | 任务 {lastStats.inheritedOffline.questsCount}(历史 {lastStats.inheritedOffline.questHistoryCount}) |
|
|
208
|
-
活动 {lastStats.inheritedOffline.eventsCount} | 探索海域 {lastStats.inheritedOffline.exploredMapsCount}
|
|
209
|
-
</div>
|
|
210
|
-
)}
|
|
211
228
|
</div>
|
|
212
229
|
</Callout>
|
|
213
230
|
)}
|