#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Mon, 16 Jul 2018 12:53:41 +0200
changeset 23211 5f3063fde804
parent 23210 953a861ee4de
child 23212 6d6e0212d313
#REFACTORING by cg class: UserPreferences class added: #readSettingsFile
UserPreferences.st
--- a/UserPreferences.st	Mon Jul 16 12:53:20 2018 +0200
+++ b/UserPreferences.st	Mon Jul 16 12:53:41 2018 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1998 by eXept Software AG
 	      All Rights Reserved
@@ -129,6 +127,78 @@
     "
 
     "Created: / 06-06-2016 / 10:42:14 / cg"
+!
+
+readSettingsFile
+    "read the settings from standard places,
+     If a --preferences command line argument was given, read it from there"
+     
+    ( AbortOperationRequest , TerminateProcessRequest , Parser parseErrorSignal ) handle:[:ex |
+        'UserPreferences [error]: error reading settings: ' errorPrint.
+        ex description errorPrintCR.
+        ex return.
+    ] do:[
+        "JV@2012-03-07: Try following settings files:
+           $HOME/.smalltalk/settings.stx
+           $HOME/.smalltalk/settings.rc
+           $PWD/settings.stx
+           $PWD/settings.rc
+
+        in that order. Whichever is found, it is read and the rest
+        is not used. Also, path to the file which has beed read is
+        stored in 'UserPreferences current at:#settingsFilename'
+        "
+        |commandLineArguments files continue idx|
+
+        files := nil.
+        commandLineArguments := Smalltalk commandLineArguments.
+        
+        idx := commandLineArguments indexOf: '--preferences'.
+        idx ~~ 0 ifTrue:[
+            | file |
+
+            commandLineArguments size <= idx ifTrue:[
+                self error:'UserPreferences [error]: --preferences requires an argument, none given'
+            ].
+            file := (Smalltalk commandLineArguments at: idx + 1) asFilename.
+            file exists ifFalse:[
+                self error:('UserPreferences [error]: preference file ''', file pathName,''' does not exist').
+            ].
+            file isDirectory ifTrue:[
+                self error:('UserPreferences [error]: preference file ''', file pathName,''' is not a regular file').
+            ].
+            file isReadable ifFalse:[
+                self error:('UserPreferences [error]: preference file ''', file pathName,''' is not readable (check permissions)').
+            ].
+            files := Array with: file.
+            commandLineArguments removeAtIndex: idx + 1.
+            commandLineArguments removeAtIndex: idx.
+        ].
+        files isNil ifTrue:[
+            files := {
+                        (Filename homeDirectory / '.smalltalk' / 'settings.stx') . "/ per-user settings file (new default?)
+                        (Filename homeDirectory / '.smalltalk' / 'settings.rc') .  "/ for backward compatibility with jv-branch
+                        (Smalltalk getSystemFileName: 'settings.stx') .            "/ old stx default
+                        (Smalltalk getSystemFileName: 'settings.rc') .             "/ for backward compatibility with jv-branch
+                     }.
+        ].
+        continue := true.
+        files do:[:each|
+            | eachFile |
+
+            (continue and:[each notNil and:[(eachFile := each asFilename) exists]]) ifTrue:[
+                continue := false.
+                eachFile pathName infoPrintCR.
+                eachFile fileIn.
+                UserPreferences current at:#settingsFilename put: eachFile pathName.
+            ].
+        ].
+        continue ifTrue:[ 
+            'UserPreferences [info]: no settings.stx file found' infoPrintCR 
+        ].
+    ].
+
+    "Created: / 16-07-2018 / 12:50:32 / Claus Gittinger"
 ! !
 
 !UserPreferences class methodsFor:'accessing'!
@@ -878,6 +948,8 @@
     ^ modified ? false
 ! !
 
+
+
 !UserPreferences methodsFor:'accessing-locale'!
 
 dateInputFormat
@@ -1646,6 +1718,7 @@
     ^ DiffCodeView
 ! !
 
+
 !UserPreferences methodsFor:'accessing-prefs-UI'!
 
 allowMouseWheelZoom