poi-plugin-kcsave-exporter 1.0.1 → 1.0.3

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/index.es CHANGED
@@ -13,12 +13,22 @@ import {
13
13
  } from '@blueprintjs/core'
14
14
  import { dialog } from '@electron/remote'
15
15
  import { ApiCaptureStore } from './lib/capture'
16
- import { exportToKcsaveBuffer } from './lib/exporter'
16
+ import { exportPatchedKcsaveBuffer } from './lib/exporter'
17
17
 
18
+ const BASE_PATH_STORAGE_KEY = 'poi_plugin_kcsave_exporter_base_path_v1'
18
19
  const captureStore = new ApiCaptureStore()
19
20
 
20
21
  const formatTime = (ts) => (ts ? new Date(ts).toLocaleTimeString() : '未捕获')
21
22
 
23
+ const loadSavedBasePath = () => {
24
+ try {
25
+ const p = window.localStorage?.getItem(BASE_PATH_STORAGE_KEY) || ''
26
+ return p && fs.existsSync(p) ? p : ''
27
+ } catch (_) {
28
+ return ''
29
+ }
30
+ }
31
+
22
32
  const KcsaveExporter = () => {
23
33
  const basic = useSelector((state) => state.info?.basic || {})
24
34
  const shipsCount = useSelector((state) => Object.keys(state.info?.ships || {}).length)
@@ -27,9 +37,9 @@ const KcsaveExporter = () => {
27
37
  const airbaseCount = useSelector((state) => (Array.isArray(state.info?.airbase) ? state.info.airbase.length : 0))
28
38
 
29
39
  const [captured, setCaptured] = useState(() => ({ ...captureStore.data }))
30
- const [baseFilePath, setBaseFilePath] = useState('')
40
+ const [baseFilePath, setBaseFilePath] = useState(loadSavedBasePath)
31
41
  const [exporting, setExporting] = useState(false)
32
- const [status, setStatus] = useState(null) // { text, intent }
42
+ const [status, setStatus] = useState(null)
33
43
  const [lastStats, setLastStats] = useState(null)
34
44
 
35
45
  useEffect(() => {
@@ -43,46 +53,50 @@ const KcsaveExporter = () => {
43
53
  const handlePickBase = useCallback(async () => {
44
54
  try {
45
55
  const res = await dialog.showOpenDialog({
46
- title: '选择已有单机版 .kcsave 模板(可选)',
56
+ title: '选择原单机版 .kcsave 存档(必选)',
47
57
  filters: [{ name: 'KanColle Offline Save', extensions: ['kcsave'] }],
48
58
  properties: ['openFile'],
49
59
  })
50
60
  const filePath = !res.canceled && res.filePaths?.[0]
51
61
  if (filePath) {
52
62
  setBaseFilePath(filePath)
53
- setStatus({ text: `已选择模板:${path.basename(filePath)}`, intent: Intent.PRIMARY })
63
+ try {
64
+ window.localStorage?.setItem(BASE_PATH_STORAGE_KEY, filePath)
65
+ } catch (_) {}
66
+ const sizeMb = (fs.statSync(filePath).size / 1024 / 1024).toFixed(2)
67
+ setStatus({
68
+ text: `已选定基底存档:${path.basename(filePath)}(${sizeMb} MB)`,
69
+ intent: Intent.PRIMARY,
70
+ })
54
71
  }
55
72
  } catch (err) {
56
- setStatus({ text: `选择模板失败:${err.message}`, intent: Intent.DANGER })
73
+ setStatus({ text: `选择原存档失败:${err.message}`, intent: Intent.DANGER })
57
74
  }
58
75
  }, [])
59
76
 
60
- const handleClearBase = useCallback(() => {
61
- setBaseFilePath('')
62
- setStatus({ text: '已清除模板,将使用内置默认模板独立导出。', intent: Intent.NONE })
63
- }, [])
64
-
65
77
  const handleClearCache = useCallback(() => {
66
78
  captureStore.clearCache()
67
79
  setStatus({ text: '已清空本地捕获缓存,重新打开对应游戏界面后会自动记录。', intent: Intent.NONE })
68
80
  }, [])
69
81
 
70
82
  const handleExport = useCallback(async () => {
83
+ if (!baseFilePath || !fs.existsSync(baseFilePath)) {
84
+ setStatus({ text: '必须先选择一份原单机版 .kcsave 存档作为基底。', intent: Intent.WARNING })
85
+ return
86
+ }
71
87
  setExporting(true)
72
- setStatus({ text: '正在汇总数据并生成 .kcsave 存档...', intent: Intent.PRIMARY })
88
+ setStatus({ text: '正在原存档基础上替换舰队数据并重算校验和...', intent: Intent.PRIMARY })
73
89
  try {
74
90
  const reduxState = typeof window.getStore === 'function' ? window.getStore() : {}
75
- const baseBuf =
76
- baseFilePath && fs.existsSync(baseFilePath) ? fs.readFileSync(baseFilePath) : null
77
-
78
- const { buffer, stats } = exportToKcsaveBuffer(reduxState, captureStore.data, baseBuf)
91
+ const baseBuf = fs.readFileSync(baseFilePath)
92
+ const { buffer, stats } = exportPatchedKcsaveBuffer(reduxState, captureStore.data, baseBuf)
79
93
 
80
94
  const safeName = (stats.nickname || 'admiral').replace(/[\\/:*?"<>|]/g, '_')
81
95
  const stamp = new Date().toISOString().slice(0, 10).replace(/-/g, '')
82
96
  const defaultPath = `kancolle-${safeName}-${stamp}.kcsave`
83
97
 
84
98
  const res = await dialog.showSaveDialog({
85
- title: '导出单机版 .kcsave 存档',
99
+ title: '保存替换后的单机版 .kcsave 存档',
86
100
  defaultPath,
87
101
  filters: [{ name: 'KanColle Offline Save', extensions: ['kcsave'] }],
88
102
  })
@@ -95,7 +109,7 @@ const KcsaveExporter = () => {
95
109
  fs.writeFileSync(res.filePath, buffer)
96
110
  setLastStats(stats)
97
111
  setStatus({
98
- text: `导出成功!已保存至 ${res.filePath}(${(buffer.length / 1024 / 1024).toFixed(2)} MB)`,
112
+ text: `导出成功!已基于原存档原地替换并保存至 ${res.filePath}(${(buffer.length / 1024 / 1024).toFixed(2)} MB)`,
99
113
  intent: Intent.SUCCESS,
100
114
  })
101
115
  } catch (err) {
@@ -144,32 +158,36 @@ const KcsaveExporter = () => {
144
158
  </div>
145
159
  <Divider style={{ margin: '10px 0' }} />
146
160
  <div style={{ fontSize: 12, opacity: 0.78 }}>
147
- 提示:舰娘、装备、资源、舰队、渠位、道具、海域与陆航可直接导出;如需连带家具、远征、编成记录、图鉴与任务一起导出,请先在游戏内打开对应界面一次即可自动捕获。
161
+ 提示:导出会在你提供的原单机版 .kcsave 基础上原地替换舰娘、装备、资源、舰队与家具数据,完整保留原存档数据库的所有历史表、版本链、立绘外观与单机进度。
148
162
  </div>
149
163
  </Card>
150
164
 
151
165
  <Card elevation={Elevation.ONE}>
152
166
  <div style={{ fontSize: 12, marginBottom: 10 }}>
153
- <strong>可选基础模板:</strong>
154
- {baseFilePath ? path.basename(baseFilePath) : '无(使用内置默认模板独立导出)'}
167
+ <strong>原单机版基底存档(必选):</strong>
168
+ {baseFilePath ? (
169
+ <Tag intent={Intent.SUCCESS} minimal style={{ marginLeft: 4 }}>
170
+ {path.basename(baseFilePath)}
171
+ </Tag>
172
+ ) : (
173
+ <Tag intent={Intent.WARNING} minimal style={{ marginLeft: 4 }}>
174
+ 未选择(请先选择原 .kcsave 文件)
175
+ </Tag>
176
+ )}
155
177
  </div>
156
178
  <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
179
+ <Button icon="document-open" intent={!baseFilePath ? Intent.PRIMARY : Intent.NONE} onClick={handlePickBase}>
180
+ {baseFilePath ? '更换原存档 .kcsave' : '选择原存档 .kcsave(必选)'}
181
+ </Button>
157
182
  <Button
158
183
  intent={Intent.PRIMARY}
159
184
  icon="export"
185
+ disabled={!baseFilePath}
160
186
  loading={exporting}
161
187
  onClick={handleExport}
162
188
  >
163
- 一键完全导出 .kcsave
189
+ 基于原存档完全导出 .kcsave
164
190
  </Button>
165
- <Button icon="document-open" onClick={handlePickBase}>
166
- 选择模板 .kcsave(可选)
167
- </Button>
168
- {baseFilePath && (
169
- <Button icon="cross" onClick={handleClearBase}>
170
- 清除模板
171
- </Button>
172
- )}
173
191
  <Button icon="trash" minimal onClick={handleClearCache}>
174
192
  清空捕获缓存
175
193
  </Button>
@@ -183,12 +201,16 @@ const KcsaveExporter = () => {
183
201
  )}
184
202
 
185
203
  {lastStats && (
186
- <Callout title="本次导出明细" intent={Intent.SUCCESS}>
204
+ <Callout title="本次导出明细(基于原存档原地替换)" intent={Intent.SUCCESS}>
187
205
  <div style={{ fontSize: 12, lineHeight: 1.7 }}>
188
- 提督 {lastStats.nickname} (Lv.{lastStats.level}) | 舰娘 {lastStats.ships} | 装备 {lastStats.equipment} |
189
- 舰队 {lastStats.decks} | 道具 {lastStats.inventory} | 家具 {lastStats.furniture} |
190
- 海域 {lastStats.maps} | 陆航 {lastStats.airBases} | 编成记录 {lastStats.presets} |
191
- 图鉴 {lastStats.albumShips}/{lastStats.albumEquips}
206
+ <div>
207
+ 提督 {lastStats.nickname} (Lv.{lastStats.level}) | Revision {lastStats.revision} | 舰娘 {lastStats.ships} |
208
+ 装备 {lastStats.equipment} | 舰队 {lastStats.decks} | 道具 {lastStats.inventory} | 家具 {lastStats.furniture}
209
+ </div>
210
+ <div style={{ marginTop: 4 }}>
211
+ 保留单机进度:军费 {lastStats.treasuryBalance} | 任务 {lastStats.quests}(历史 {lastStats.questHistoryCount}) |
212
+ 海域 {lastStats.maps} | 活动 {lastStats.eventsCount} | 图鉴 {lastStats.albumShips}/{lastStats.albumEquips}
213
+ </div>
192
214
  </div>
193
215
  </Callout>
194
216
  )}