@ -1,5 +1,6 @@
let path = require ( 'path' )
let fs = require ( 'fs' ) ;
let os = require ( 'os' ) ;
const shell = require ( 'electron' ) . shell ;
let fileExtensionToImage : object ;
@ -59,6 +60,7 @@ export module FileUtils {
export function getPathToView ( templateName : string ) : string {
return path . join ( getPathToAssets ( ) , "views" , templateName + ".mustache" )
}
export function getPathToPage ( pageName : string ) : string {
return path . join ( getPathToAssets ( ) , "pages" , pageName )
}
@ -95,6 +97,34 @@ export module FileUtils {
fs . mkdirSync ( dirPath ) ;
}
}
export function showFileInDir ( resourcePath : string ) {
let localFile = copyFileToUserDocuments ( resourcePath ) ;
shell . showItemInFolder ( localFile ) ;
}
/ * *
* @param resourcePath pathlike of system resource
* @private
* @returns pathlike of local user resource
* /
function copyFileToUserDocuments ( resourcePath : string ) : string {
let fileName = path . basename ( resourcePath ) ;
let userFilePath = getPathToUserDocumentDir ( fileName ) ;
if ( ! fs . existsSync ( userFilePath ) ) {
fs . copyFileSync ( resourcePath , userFilePath ) ;
}
return userFilePath ;
}
function getPathToUserDocumentDir ( fileName : string ) : string {
let homeDir = os . homedir ( ) ;
let parent = path . join ( homeDir , "Documents" , "Employee Resources" ) ;
if ( ! fs . existsSync ( parent ) ) {
fs . mkdirSync ( parent ) ;
}
return path . join ( parent , fileName ) ;
}
}
@ -188,8 +218,7 @@ export class FileNode {
private static getImagePathFromDocumentName ( name : string ) : string {
let ext = FileUtils . getFileExtension ( name ) ;
let thumbnail = Configurator . getFileExtensionToImageMap ( ) [ ext ] ;
return thumbnail ;
return Configurator . getFileExtensionToImageMap ( ) [ ext ] ;
}
open() {