| 1 | import { parseMemoryMB, parseTimeMS, sortFiles } from '@hydrooj/utils/lib/common'; |
| 2 | |
| 3 | export function convertIniConfig(ini: string) { |
| 4 | const f = ini.split('\n'); |
| 5 | const count = Number.parseInt(f[0], 10); |
| 6 | const res = { subtasks: [] }; |
| 7 | for (let i = 1; i <= count; i++) { |
| 8 | if (!f[i]?.trim()) throw new Error('Testdata count incorrect.'); |
| 9 | const [input, output, time, score, memory] = f[i].split('|'); |
| 10 | const cur = { |
| 11 | cases: [{ input, output }], |
| 12 | score: Number.parseInt(score, 10), |
| 13 | time: `${time}s`, |
| 14 | memory: '256m', |
| 15 | }; |
| 16 | if (!Number.isNaN(Number.parseInt(memory, 10))) cur.memory = `${Math.floor(Number.parseInt(memory, 10) / 1024)}m`; |
| 17 | res.subtasks.push(cur); |
| 18 | } |
| 19 | return res; |
| 20 | } |
| 21 | |
| 22 | interface MatchRule { |
| 23 | regex: RegExp; |