@@ -24,6 +24,7 @@ const Plugins = require('./plugins.js');
2424const DBUtils = require ( './helpers/db.utils.js' ) ;
2525const Site = require ( './site.js' ) ;
2626const Utils = require ( './helpers/utils.js' ) ;
27+ const FileHelper = require ( './helpers/file.js' ) ;
2728// List of the Event classes
2829const EventClasses = require ( './events/_modules.js' ) ;
2930// Migration classes
@@ -52,7 +53,8 @@ class App {
5253 this . initPath = path . join ( this . appDir , 'config' , 'window-config.json' ) ;
5354 this . appConfigPath = path . join ( this . appDir , 'config' , 'app-config.json' ) ;
5455 this . tinymceOverridedConfigPath = path . join ( this . appDir , 'config' , 'tinymce.override.json' ) ;
55- this . versionData = JSON . parse ( fs . readFileSync ( __dirname + '/builddata.json' , 'utf8' ) ) ;
56+ this . versionData = JSON . parse ( FileHelper . readFileSync ( __dirname + '/builddata.json' , 'utf8' ) ) ;
57+ this . versionData . os = os . platform ( ) === 'darwin' ? 'mac' : os . platform ( ) === 'linux' ? 'linux' : 'win' ;
5658 this . windowBounds = null ;
5759 this . appConfig = null ;
5860 this . tinymceOverridedConfig = { } ;
@@ -165,8 +167,8 @@ class App {
165167
166168 // Check if both config.json files exists
167169 if ( fs . existsSync ( appThemeConfig ) && fs . existsSync ( userThemeConfig ) ) {
168- let appThemeData = JSON . parse ( fs . readFileSync ( appThemeConfig , 'utf8' ) ) ;
169- let userThemeData = JSON . parse ( fs . readFileSync ( userThemeConfig , 'utf8' ) ) ;
170+ let appThemeData = JSON . parse ( FileHelper . readFileSync ( appThemeConfig , 'utf8' ) ) ;
171+ let userThemeData = JSON . parse ( FileHelper . readFileSync ( userThemeConfig , 'utf8' ) ) ;
170172
171173 // If app theme is newer version than the existing one
172174 if ( compare ( appThemeData . version , userThemeData . version ) === 1 ) {
@@ -231,7 +233,7 @@ class App {
231233 let themeDir = path . join ( siteDir , 'input' , 'themes' , themes . currentTheme ( true ) ) ;
232234 let themeOverridesDir = path . join ( siteDir , 'input' , 'themes' , themes . currentTheme ( true ) + '-override' ) ;
233235 let themeConfig = Themes . loadThemeConfig ( themeConfigPath , themeDir ) ;
234- let menuStructure = fs . readFileSync ( menuConfigPath , 'utf8' ) ;
236+ let menuStructure = FileHelper . readFileSync ( menuConfigPath , 'utf8' ) ;
235237 let parsedMenuStructure = { } ;
236238
237239 try {
@@ -283,8 +285,14 @@ class App {
283285
284286 // Load the config
285287 let defaultSiteConfig = JSON . parse ( JSON . stringify ( defaultAstCurrentSiteConfig ) ) ;
286- let siteConfig = fs . readFileSync ( configFilePath ) ;
287- siteConfig = JSON . parse ( siteConfig ) ;
288+ let siteConfig = FileHelper . readFileSync ( configFilePath ) ;
289+
290+ try {
291+ siteConfig = JSON . parse ( siteConfig ) ;
292+ } catch ( e ) {
293+ dialog . showErrorBox ( 'Publii cannot read site config' , 'There is an issue with file: ' + configFilePath + "\n\nError details: " + e . message ) ;
294+ return ;
295+ }
288296
289297 if ( siteConfig . name !== siteName ) {
290298 siteConfig . name = siteName ;
@@ -437,7 +445,7 @@ class App {
437445 loadConfig ( ) {
438446 // Try to get window bounds
439447 try {
440- this . windowBounds = JSON . parse ( fs . readFileSync ( this . initPath , 'utf8' ) ) ;
448+ this . windowBounds = JSON . parse ( FileHelper . readFileSync ( this . initPath , 'utf8' ) ) ;
441449 } catch ( e ) {
442450 console . log ( 'The window-config.json file will be created' ) ;
443451 }
@@ -490,7 +498,7 @@ class App {
490498
491499 // Try to get application config
492500 try {
493- this . appConfig = JSON . parse ( fs . readFileSync ( this . appConfigPath , 'utf8' ) ) ;
501+ this . appConfig = JSON . parse ( FileHelper . readFileSync ( this . appConfigPath , 'utf8' ) ) ;
494502 this . appConfig = Utils . mergeObjects ( JSON . parse ( JSON . stringify ( defaultAstAppConfig ) ) , this . appConfig ) ;
495503 } catch ( e ) {
496504 if ( this . hasPermissionsErrors ( e ) ) {
@@ -518,7 +526,7 @@ class App {
518526 loadAdditionalConfig ( ) {
519527 // Try to get TinyMCE overrided config
520528 try {
521- this . tinymceOverridedConfig = JSON . parse ( fs . readFileSync ( this . tinymceOverridedConfigPath , 'utf8' ) ) ;
529+ this . tinymceOverridedConfig = JSON . parse ( FileHelper . readFileSync ( this . tinymceOverridedConfigPath , 'utf8' ) ) ;
522530 } catch ( e ) { }
523531
524532 if ( this . appConfig . sitesLocation ) {
0 commit comments