| import { TreeNode } from "@/TreeNodes/TreeNode/TreeNode"; |
| import { |
| getFormatInfoGivenType, |
| IFormatInfo, |
| molFormatInformation, |
| } from "./LoadSaveMolModels/Types/MolFormats"; |
| import { IFileInfo } from "./Types"; |
| import { getFileType } from "./FileUtils2"; |
|
|
| |
| |
| |
| export class FileInfo { |
| name: string; |
| contents: any; |
| compressedName?: string; |
| treeNode?: TreeNode; |
| cachedConvertText: { [key: string]: string } = {}; |
| auxData: any; |
|
|
| |
| |
| |
| |
| |
| constructor(fileInfo: IFileInfo) { |
| this.name = fileInfo.name; |
| this.contents = fileInfo.contents; |
| this.compressedName = fileInfo.compressedName; |
| this.treeNode = fileInfo.treeNode; |
| } |
|
|
| |
| |
| |
| |
| |
| public serialize(): IFileInfo { |
| return { |
| name: this.name, |
| contents: this.contents, |
| compressedName: this.compressedName, |
| treeNode: this.treeNode, |
| auxData: this.auxData, |
| } as IFileInfo; |
| } |
|
|
| |
| |
| |
| |
| |
| public getFileType(): string | undefined { |
| return getFileType(this); |
| } |
|
|
| |
| |
| |
| |
| |
| public getFormatInfo(): IFormatInfo | undefined { |
| const typ = this.getFileType(); |
| if (typ === undefined) return; |
| return getFormatInfoGivenType(typ); |
| } |
|
|
| |
| |
| |
| public assignExtByContents() { |
| const format = this.guessFormat(); |
| if (format) { |
| this.name = this.name + "." + format.primaryExt; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| public guessFormat(): IFormatInfo | undefined { |
| const contents = this.contents.trim(); |
|
|
| for (const formatID in molFormatInformation) { |
| const format = molFormatInformation[formatID]; |
| if (format.validateContents === undefined) { |
| |
| continue; |
| } |
|
|
| if (format === molFormatInformation.SMI) { |
| |
| continue; |
| } |
|
|
| if (format.validateContents(contents)) { |
| return format; |
| } |
| } |
|
|
| |
| if ( |
| molFormatInformation.SMI.validateContents && |
| molFormatInformation.SMI.validateContents(contents) |
| ) { |
| return molFormatInformation.SMI; |
| } |
|
|
| |
| return; |
| } |
| } |
|
|