Skip to content

Commit

Permalink
Show message for LPK parse failure
Browse files Browse the repository at this point in the history
Signed-off-by: xychen <xychen@listenai.com>
  • Loading branch information
xychen committed May 20, 2024
1 parent 1de5d25 commit d59b8cb
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/components/sections/PartitionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import {
NPopover,
NSpin,
NText,
useMessage,
} from 'naive-ui';
import {
Add12Regular,
Expand All @@ -121,6 +122,7 @@ import {
import { isEmpty } from 'radash';
import { open } from '@tauri-apps/plugin-dialog';
import { UserError } from '@/userError';
import { cleanUpImage, readImage, type IFlashImage } from '@/utils/images';
import { fromHex, toHex } from '@/utils/hex';
import { busyOn } from '@/composables/busyOn';
Expand Down Expand Up @@ -152,16 +154,27 @@ const props = defineProps<{
errors: (string | undefined)[];
}>();
const message = useMessage();
const parsing = ref(false);
async function handleFiles(files: string[]) {
const parsed = await busyOn(readImage(files), parsing);
if (parsed.format == 'hex' || parsed.format != image.value?.format) {
if (image.value) {
cleanUpImage(image.value);
try {
const parsed = await busyOn(readImage(files), parsing);
if (parsed.format == 'hex' || parsed.format != image.value?.format) {
if (image.value) {
cleanUpImage(image.value);
}
image.value = parsed;
} else {
image.value = { ...image.value, partitions: image.value.partitions.concat(parsed.partitions) };
}
} catch (e) {
if (e instanceof UserError) {
message.error(e.summary);
} else {
console.error(e);
message.error('解析固件失败');
}
image.value = parsed;
} else {
image.value = { ...image.value, partitions: image.value.partitions.concat(parsed.partitions) };
}
}
Expand Down

0 comments on commit d59b8cb

Please sign in to comment.