From e360f2855c17243cdf4974e0931e772b1378d3d0 Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 19 Dec 2023 17:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=E5=B0=9D=E8=AF=95=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=94=99=E8=AF=AF=E7=9A=84=E5=9B=BE=E7=BA=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DatabaseServices/FileServer.ts | 60 +++++++++++++++++------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/DatabaseServices/FileServer.ts b/src/DatabaseServices/FileServer.ts index 88d27c215..f26ad1a82 100644 --- a/src/DatabaseServices/FileServer.ts +++ b/src/DatabaseServices/FileServer.ts @@ -150,45 +150,53 @@ export class FileServer extends Singleton } catch (error) { - if (error.message.indexOf("at position") === -1) + let pos: number; + if (error.message.indexOf("at position") !== -1) + pos = Number(/at position[ ]+(\d+)/.exec(error.message)[1]); + else if (error.message.indexOf("Unexpected token") !== -1) + { + let pos1 = error.message.indexOf("\""); + let pos2 = error.message.indexOf("\"", pos1 + 1); + let subStr = error.message.substring(pos1 + 1, pos2); + pos = info.file.indexOf(subStr); + } + + if (pos === undefined || pos === -1) { AppToaster.show({ - message: "图纸损坏!您现在可以打开历史记录修复图纸!", + message: "图纸损坏!您现在可以打开历史记录修复图纸!或者将图纸发给我们进行修复!", timeout: 3000, intent: Intent.DANGER }, 'canelfix'); break; } - else - { - let pos = Number(/at position[ ]+(\d+)/.exec(error.message)[1]); - let startPos = Math.max(0, pos - 100); - let endPos = Math.min(pos + 100, info.file.length - 1); - let newStr = prompt(`数据损坏,请修复数据,下面数据中,第${pos - startPos + 1}个字符出错了(如果您不会修复,请发送给售后工程师!)点击取消可以直接放弃修复,您可以打开历史记录还原图纸!`, info.file.substring(startPos, endPos)); - if (newStr) + let startPos = Math.max(0, pos - 100); + let endPos = Math.min(pos + 100, info.file.length - 1); + + let newStr = prompt(`数据损坏,请修复数据,下面数据中,第${pos - startPos + 1}个字符出错了(如果您不会修复,请发送给售后工程师!)点击取消可以直接放弃修复,您可以打开历史记录还原图纸!`, info.file.substring(startPos, endPos)); + if (newStr) + { + try { - try - { - info.file = info.file.substring(0, startPos) + newStr + info.file.substring(endPos); - fileData = JSON.parse(info.file); - break; - } - catch (error) - { - - } + info.file = info.file.substring(0, startPos) + newStr + info.file.substring(endPos); + fileData = JSON.parse(info.file); + break; } - else + catch (error) { - AppToaster.show({ - message: "你放弃了修复,你现在可以打开历史记录修复图纸!", - timeout: 3000, - intent: Intent.SUCCESS - }, 'canelfix'); - break; + } } + else + { + AppToaster.show({ + message: "你放弃了修复,你现在可以打开历史记录修复图纸!", + timeout: 3000, + intent: Intent.SUCCESS + }, 'canelfix'); + break; + } } }