feat: kwm v2 key import ui

This commit is contained in:
鲁树人
2023-06-17 02:45:31 +01:00
parent 5492628b71
commit b277000c2a
13 changed files with 480 additions and 32 deletions

View File

@@ -3,7 +3,7 @@ import { SQLDatabase, SQLStatic, loadSQL } from './sqlite';
export interface QMAndroidKeyEntry {
name: string;
key: string;
ekey: string;
}
export class DatabaseKeyExtractor {
@@ -33,10 +33,10 @@ export class DatabaseKeyExtractor {
}
const keys = db.exec('select file_path, ekey from `audio_file_ekey_table`')[0].values;
return keys.map(([path, key]) => ({
return keys.map(([path, ekey]) => ({
// strip dir name
name: getFileName(String(path)),
key: String(key),
ekey: String(ekey),
}));
} finally {
db?.close();

View File

@@ -95,4 +95,8 @@ export class MMKVParser {
}
return result;
}
public static parseKuwoEKey(_view: DataView): unknown[] {
return [];
}
}

View File

@@ -0,0 +1,10 @@
import { splitN } from '../splitN';
test('some test cases', () => {
expect(splitN('1,2,3', ',', 2)).toEqual(['1', '2,3']);
expect(splitN('1,2,3', ',', 3)).toEqual(['1', '2', '3']);
expect(splitN('1,2,3', ',', 4)).toEqual(['1', '2', '3']);
expect(splitN('1,2,3', '.', 3)).toEqual(['1,2,3']);
expect(splitN('1,2,3', '?', 0)).toEqual(['1,2,3']);
});

20
src/util/splitN.ts Normal file
View File

@@ -0,0 +1,20 @@
export function splitN(str: string, sep: string, maxN: number) {
if (maxN <= 1) {
return [str];
}
const chunks: string[] = [];
const lenSep = sep.length;
let searchIdx = 0;
for (; maxN > 1; maxN--) {
const nextIdx = str.indexOf(sep, searchIdx);
if (nextIdx === -1) {
break;
}
chunks.push(str.slice(searchIdx, nextIdx));
searchIdx = nextIdx + lenSep;
}
chunks.push(str.slice(searchIdx));
return chunks;
}