import * as electron from 'electron' ; const fs = electron . remote . require ( 'fs' ) ; const path = electron . remote . require ( 'path' ) ; const __dirname = electron . ipcRenderer . sendSync ( 'sandbox-dirname-request' ) ; const __appdata = electron . ipcRenderer . sendSync ( 'sandbox-appdata-request' ) ; const MajsoulPlus = { } ; function isSubFolder ( parent , dir ) { const relative = path . relative ( parent , dir ) ; return relative && ! relative . startsWith ( '..' ) && ! path . isAbsolute ( relative ) ; } function isMajsoulPlusSubFolder ( dir ) { return ( isSubFolder ( MajsoulPlus . __dirname , dir ) || isSubFolder ( MajsoulPlus . __appdata , dir ) ) ; } MajsoulPlus . __dirname = __dirname ; MajsoulPlus . __appdata = __appdata ; MajsoulPlus . globalPath = { LocalDir : '/static' , ResourcePackDir : 'resourcepack' , ExtensionDir : 'extension' , ToolsDir : 'tool' } ; MajsoulPlus . fs = { } ; MajsoulPlus . fs . readFileSync = ( dir ) => { if ( ! isMajsoulPlusSubFolder ( path . resolve ( dir ) ) ) { console . error ( `invalid dir: ${ dir }` ) ; throw new Error ( `invalid dir: ${ dir }` ) ; } return fs . readFileSync ( dir , { encoding : 'utf-8' } ) ; } ; MajsoulPlus . fs . writeFile = ( dir , data , callback ) => { if ( ! isMajsoulPlusSubFolder ( path . resolve ( dir ) ) ) { console . error ( `invalid dir: ${ dir }` ) ; callback ( new Error ( `invalid dir: ${ dir }` ) ) ; return ; } fs . writeFile ( dir , data , callback ) ; } ; MajsoulPlus . fs . writeFileSync = ( dir , data , options ) => { if ( ! isMajsoulPlusSubFolder ( path . resolve ( dir ) ) ) { console . error ( `invalid dir: ${ dir }` ) ; return ; } fs . writeFileSync ( dir , data , options ) ; } ; MajsoulPlus . fs . mkdirSync = ( dir ) => { if ( ! isMajsoulPlusSubFolder ( path . resolve ( dir ) ) ) { console . error ( `invalid dir: ${ dir }` ) ; throw new Error ( `invalid dir: ${ dir }` ) ; return ; } fs . mkdirSync ( dir ) ; } ; MajsoulPlus . fs . statSync = ( dir ) => { if ( ! isMajsoulPlusSubFolder ( path . resolve ( dir ) ) ) { console . error ( `invalid dir: ${ dir }` ) ; throw new Error ( `invalid dir: ${ dir }` ) ; } return fs . statSync ( dir ) ; } ; MajsoulPlus . path = path ; Object . freeze ( MajsoulPlus ) ; window [ 'MajsoulPlus' ] = MajsoulPlus ; window [ 'Buffer' ] = Buffer ;