From 8eabcd9b37b9b8802443448242b2feb86d66f813 Mon Sep 17 00:00:00 2001 From: james-strauss-uwa Date: Tue, 22 Aug 2023 15:50:20 +0800 Subject: [PATCH] Added check for file with newer version that running EAGLE, warn user --- src/Eagle.ts | 56 ++++++++++++++++++++++++++++++---------------------- src/Utils.ts | 34 +++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/src/Eagle.ts b/src/Eagle.ts index 2c45660fd..f84de479f 100644 --- a/src/Eagle.ts +++ b/src/Eagle.ts @@ -1730,7 +1730,7 @@ export class Eagle { // determine file extension const fileExtension = Utils.getFileExtension(file.name); let fileTypeLoaded: Eagle.FileType = Eagle.FileType.Unknown; - let dataObject = null; + let dataObject: any = null; if (fileExtension !== "md"){ // attempt to parse the JSON @@ -1751,30 +1751,18 @@ export class Eagle { switch (fileTypeLoaded){ case Eagle.FileType.Graph: // attempt to determine schema version from FileInfo - const schemaVersion: Daliuge.SchemaVersion = Utils.determineSchemaVersion(dataObject); - - const errorsWarnings: Errors.ErrorsWarnings = {"errors":[], "warnings":[]}; - - // use the correct parsing function based on schema version - switch (schemaVersion){ - case Daliuge.SchemaVersion.OJS: - case Daliuge.SchemaVersion.Unknown: - this.logicalGraph(LogicalGraph.fromOJSJson(dataObject, file, errorsWarnings)); - break; + const eagleVersion: string = Utils.determineEagleVersion(dataObject); + + // warn user if file newer than EAGLE + if (Utils.newerEagleVersion(eagleVersion, (window).version)){ + Utils.requestUserConfirm("Newer EAGLE Version", "File " + file.name + " was written with EAGLE version " + eagleVersion + ", whereas the current EAGLE version is " + (window).version + ". Do you wish to load the file anyway?", "Yes", "No", "", (confirmed : boolean) : void => { + if (confirmed){ + this._loadGraph(dataObject, file); + } + }); + } else { + this._loadGraph(dataObject, file); } - - // show errors/warnings - this._handleLoadingErrors(errorsWarnings, file.name, file.repository.service); - - // center graph - this.centerGraph(); - - // check graph - this.checkGraph(); - this.undo().pushSnapshot(this, "Loaded " + file.name); - - // if the fileType is the same as the current mode, update the activeFileInfo with details of the repository the file was loaded from - this.updateLogicalGraphFileInfo(file.repository.service, file.repository.name, file.repository.branch, file.path, file.name); break; case Eagle.FileType.Palette: @@ -1793,6 +1781,26 @@ export class Eagle { }); }; + _loadGraph = (dataObject: any, file: RepositoryFile) : void => { + const errorsWarnings: Errors.ErrorsWarnings = {"errors":[], "warnings":[]}; + + // load graph + this.logicalGraph(LogicalGraph.fromOJSJson(dataObject, file, errorsWarnings)); + + // show errors/warnings + this._handleLoadingErrors(errorsWarnings, file.name, file.repository.service); + + // center graph + this.centerGraph(); + + // check graph + this.checkGraph(); + this.undo().pushSnapshot(this, "Loaded " + file.name); + + // if the fileType is the same as the current mode, update the activeFileInfo with details of the repository the file was loaded from + this.updateLogicalGraphFileInfo(file.repository.service, file.repository.name, file.repository.branch, file.path, file.name); + } + insertRemoteFile = (file : RepositoryFile) : void => { // flag file as being fetched file.isFetching(true); diff --git a/src/Utils.ts b/src/Utils.ts index 50be387e9..416bd12e5 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1336,13 +1336,39 @@ export class Utils { return Eagle.FileType.Unknown; } + static determineEagleVersion(data: any): string { + if (typeof data.modelData !== 'undefined'){ + if (typeof data.modelData.eagleVersion !== 'undefined'){ + return data.modelData.eagleVersion; + } + } + + return "v-1.-1.-1"; + } + + // return true iff version0 is newer than version1 + static newerEagleVersion(version0: string, version1: string){ + //console.log("version0", version0, "version1", version1); + + if (version0 === "Unknown" || version1 === "Unknown"){ + return false; + } + + const v0 = version0.split('v')[1].split('.').map(Number); + const v1 = version1.split('v')[1].split('.').map(Number); + + //console.log("v0", v0, "v1", v1); + + return ( + v0[0] > v1[0] || + ((v0[0] === v1[0]) && (v0[1] > v1[1])) || + ((v0[0] === v1[0]) && (v0[1] === v1[1]) && (v0[2] > v1[2])) + ) + } + static determineSchemaVersion(data: any): Daliuge.SchemaVersion { - // appref if (typeof data.modelData !== 'undefined'){ if (typeof data.modelData.schemaVersion !== 'undefined'){ - if (data.modelData.schemaVersion === Daliuge.SchemaVersion.OJS){ - return Daliuge.SchemaVersion.OJS; - } return data.modelData.schemaVersion; } }