Добавлены процедуры проверки наличия параметров конфигурации, и установки значений по умолчанию в случае их отсутствия в файле конфигурации.
Добавлена новая секця и два новых парметра в конфиг, для вывода отладочной информации.
This commit is contained in:
@@ -75,6 +75,9 @@ RB=ruby
|
|||||||
HTM=firefox
|
HTM=firefox
|
||||||
HTML=firefox
|
HTML=firefox
|
||||||
LUA=lua
|
LUA=lua
|
||||||
|
\[Debug\]
|
||||||
|
debug=false
|
||||||
|
debugOut=stdout
|
||||||
"
|
"
|
||||||
proc Config::create {dir} {
|
proc Config::create {dir} {
|
||||||
set cfgFile [open [file join $dir projman.ini] "w+"]
|
set cfgFile [open [file join $dir projman.ini] "w+"]
|
||||||
@@ -131,3 +134,47 @@ proc Config::write {dir} {
|
|||||||
ini::commit $cfgFile
|
ini::commit $cfgFile
|
||||||
ini::close $cfgFile
|
ini::close $cfgFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Добавление перменной в список
|
||||||
|
# если отсутствует нужная секция то она будет добавлена.
|
||||||
|
proc Config::AddVariable {key value section} {
|
||||||
|
# Проверяем, существует ли уже такая переменная
|
||||||
|
if {[info exists ::cfgVariables($key)]} {
|
||||||
|
DebugPuts "The variable '$key' already exists: $::cfgVariables($key)"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Добавляем в массив переменных
|
||||||
|
set ::cfgVariables($key) $value
|
||||||
|
|
||||||
|
# Добавляем в список ключей секции
|
||||||
|
if {[info exists ::cfgINIsections($section)]} {
|
||||||
|
# Проверяем, нет ли уже такого ключа в секции
|
||||||
|
if {[lsearch -exact $::cfgINIsections($section) $key] == -1} {
|
||||||
|
lappend ::cfgINIsections($section) $key
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set ::cfgINIsections($section) [list $key]
|
||||||
|
}
|
||||||
|
DebugPuts "Config::AddVariable: The variable '$key' has been added to the array 'cfgVariables'"
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Проверяем наличие переменных в конфиге на основе "эталонного" списка
|
||||||
|
# и выставляем значение по умолчанию если в конфиге переменной нет
|
||||||
|
proc Config::CheckVariables {} {
|
||||||
|
set valList [split $::configDefault "\n"]
|
||||||
|
foreach item $valList {
|
||||||
|
if {[regexp -nocase -all -- {\[(\w+)\]} $item -> v1]} {
|
||||||
|
set section $v1
|
||||||
|
}
|
||||||
|
if {[regexp {^([^=]+)=(.*)$} $item -> var value]} {
|
||||||
|
if ![info exists ::cfgVariables($var)] {
|
||||||
|
DebugPuts "Error in Config::CheckVariables: variable ::cfgVariables($var) not found"
|
||||||
|
Config::AddVariable "$var" "$value" "$section"
|
||||||
|
DebugPuts "Config::CheckVariables: The variable cfgVariables($var) setting to default value \"$value\""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1155,3 +1155,14 @@ proc Paste {} { SendEventToLatestTxtWidget <<Paste>> }
|
|||||||
proc Undo {} { SendEventToLatestTxtWidget <<Undo>> }
|
proc Undo {} { SendEventToLatestTxtWidget <<Undo>> }
|
||||||
proc Redo {} { SendEventToLatestTxtWidget <<Redo>> }
|
proc Redo {} { SendEventToLatestTxtWidget <<Redo>> }
|
||||||
# ------------
|
# ------------
|
||||||
|
|
||||||
|
proc DebugPuts {msg} {
|
||||||
|
global cfgVariables debugFlag
|
||||||
|
if ![info exists cfgVariables(debugFlag)] {
|
||||||
|
set cfgVariables(debugFlag) "true"
|
||||||
|
}
|
||||||
|
if {$cfgVariables(debugFlag) eq "true"} {
|
||||||
|
puts "$msg"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ if {[file exists [file join $dir(cfg) projman.ini]] ==0} {
|
|||||||
Config::create $dir(cfg)
|
Config::create $dir(cfg)
|
||||||
}
|
}
|
||||||
Config::read $dir(cfg)
|
Config::read $dir(cfg)
|
||||||
|
Config::CheckVariables
|
||||||
|
|
||||||
::msgcat::mclocale $cfgVariables(locale)
|
::msgcat::mclocale $cfgVariables(locale)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user