From: Pat Thoyts Date: Fri, 27 Nov 2009 00:34:33 +0000 (+0000) Subject: Use the users registry to store settings on Windows. X-Git-Tag: v2.6~13 X-Git-Url: http://privyetmir.co.uk/gitweb?a=commitdiff_plain;h=86778859f3bb1c8ea78771447eeb3f80aa263e79;p=sockspy Use the users registry to store settings on Windows. Signed-off-by: Pat Thoyts --- diff --git a/bin/sockspy.tcl b/bin/sockspy.tcl index c0a9cff..2abc6e2 100644 --- a/bin/sockspy.tcl +++ b/bin/sockspy.tcl @@ -260,8 +260,10 @@ proc createMain {} { grid columnconfigure . 0 -weight 1 bind .out clearOutput - bind all {console show} - bind all {console show} + if {[tk windowingsystem] eq "win32"} { + bind all {console show} + bind all {console show} + } focus .out wm geometry . +10+10 wm deiconify . @@ -1145,6 +1147,10 @@ proc DoExtract {who data timestamp} { proc stateRestore {} { global env state SP extract + if {[useRegistry]} { + if {[stateRestoreRegistry]} { return } + } + switch $::tcl_platform(platform) "macintosh" { set stateFile [file join $env(PREF_FOLDER) "SockSpy Preferences"] } "windows" { @@ -1168,6 +1174,21 @@ proc stateRestore {} { trace variable $v w stateSave } } + +set regkey {HKEY_CURRENT_USER\SOFTWARE\sockspy.sourceforge.net} +proc stateRestoreRegistry {} { + global env state SP extract regkey + set r 0 + foreach name $::saveList { + catch { + uplevel #0 [list set $name [registry get $regkey $name]] + trace variable $name w stateSave + set r 1 + } + } + return $r +} + ##+######################################################################### # # stateSave and stateSaveReal - Save program state. @@ -1189,6 +1210,10 @@ proc stateSave {a b c} { proc stateSaveReal {} { global state SP extract + if {[useRegistry]} { + return [stateSaveRegistry] + } + # silently ignore open failure if {[catch {open $state(stateFile) w} sf]} return @@ -1207,6 +1232,24 @@ proc stateSaveReal {} { close $sf } +proc stateSaveRegistry {} { + global state SP extract regkey + foreach name $::saveList { + registry set $regkey $name [set $name] sz + } +} + +proc useRegistry {} { + global tcl_platform + set r 0 + if {$tcl_platform(platform) eq "windows"} { + if {![catch {package require registry}]} { + set r 1 + } + } + return $r +} + ################################################################ ################################################################ ################################################################