📄 config.tcl
字号:
close $file_id set HOME $OLDHOME return [LoadLoginList $trigger] } # Clear all list set top [LoginList size 0] for { set idx 0 } { $idx <= $top } {incr idx 1 } { LoginList unset 0 [LoginList get 0] } # Now add profiles from file to list while {[gets $file_id tmp_data] != "-1"} { set temp_data [split $tmp_data] set user_login [lindex $tmp_data 0] set locknum [lindex $tmp_data 1] if {[string first "@" $user_login] == -1} { status_log "Profile $user_login is wrong!! Fixing\n" red #Profile is wrong, fix it from config file set oldHOME $HOME set dirname [string map {"@" "_" "." "_"} $user_login] set HOME [file join $HOMEE $dirname] load_config set user_login [::config::getKey login] set HOME $oldHOME }# puts "temp data : $temp_data" if { $locknum == "" } { #Profile without lock, give it 0 set locknum 0 } LoginList add 0 $user_login $locknum status_log "LoadLoginList: adding profile $user_login with lock num $locknum\n" blue } close $file_id # Modify HOME dir to current profile, chose a non locked profile, if none available go to default if { $trigger == 0 } { #If profiles are disabled, don't load one if { [::config::getGlobalKey disableprofiles] == 1 } { status_log "LoadLoginList: profiles disabled, ignoring\n" blue ::config::setKey login "" set HOME2 $HOME return } status_log "LoadLoginList: getting an initial profile\n" blue set HOME2 $HOME set flag 0 for { set idx 0 } { $idx <= [LoginList size 0] } {incr idx 1} { if { [CheckLock [LoginList get $idx]] != -1 } { LockProfile [LoginList get $idx] status_log "LoadLoginList: profile [LoginList get $idx] is free, locking\n" set flag 1 break } } # if flag is 1 means we found a profile and we use it, if not defaults if { $flag == 1 } { set temp [LoginList get $idx] set dirname [string map {"@" "_" "." "_"} $temp] #set dirname [split $temp "@ ."] #set dirname [join $dirname "_"] set HOME "[file join $HOME2 $dirname]" ::config::setKey login "$temp" status_log "LoadLoginList: we found a free profile: $temp\n" green } else { status_log "LoadLoginList: using default profile\n" green ::config::setKey login "" } SaveLoginList }}#///////////////////////////////////////////////////////////////////////////////# SaveLoginList ()# Saves the list of logins/profiles to the profiles file in the HOME dirproc SaveLoginList {} { global HOME2 tcl_platform currentlock if {$tcl_platform(platform) == "unix"} { set file_id [open "[file join ${HOME2} profiles]" w 00600] } else { set file_id [open "[file join ${HOME2} profiles]" w] } puts $file_id "amsn_profiles_version 1" set idx [LoginList size 0] while { $idx >= 0 } { puts $file_id "[LoginList get $idx] [LoginList getlock 0 [LoginList get $idx]]" incr idx -1 } close $file_id}#///////////////////////////////////////////////////////////////////////////////# LoginList (action age [email])# Controls information for list of profiles read from the profiles file# action can be :# add : Adds new user to list, or if exists makes this user the newest# (age is ignored), lock must be given if new profile# get : Returns the email by age, returns 0 if no email for age exists# exists : Checks the email if exists returns 1, 0 if dosent (age is ignored)# getlock : Returns lock code for given email, if non existant returns -1.# changelock : changes lock for user given by email to lock port given by lock# lockexists : checks if lock exists for some profile, returns 1 if true, 0 if false# unset : Removes profile given by email from the list and moves# all elements up by 1 (age is ignored)# size : Returns [array size ProfileList] - 1# show : Dumps list to status_log, for debugging purposes onlyproc LoginList { action age {email ""} {lock ""} } { variable ProfileList #global ProfileList variable LockList global currentlock switch $action { add { set tmp_list [array get ProfileList] set idx [lsearch $tmp_list "$email"] if { $idx == -1 } { # User dosen't exist, proceed normally for {set idx [expr {[array size ProfileList] - 1}]} {$idx >= 0} {incr idx -1} { set ProfileList([expr {$idx + 1}]) $ProfileList($idx) set LockList([expr {$idx + 1}]) $LockList($idx) } set ProfileList(0) $email set LockList(0) $lock } else { # This means user exists, and we make him newest #set emaillock $LockList([expr {[expr {$idx-1}] / 2}]) set emaillock $LockList([expr {($idx-1) / 2}]) for {set idx [lindex $tmp_list [expr {$idx - 1}]]} {$idx > 0} {incr idx -1} { set ProfileList($idx) $ProfileList([expr {$idx - 1}]) set LockList($idx) $LockList([expr {$idx - 1}]) } set ProfileList(0) $email set LockList(0) $emaillock } } unset { set tmp_list [array get ProfileList] set idx [lsearch $tmp_list "$email"] if { $idx != -1 } { for {set idx [lindex $tmp_list [expr {$idx - 1}]]} {$idx < [expr {[array size ProfileList] - 1}]} {incr idx} { set ProfileList($idx) $ProfileList([expr {$idx + 1}]) set LockList($idx) $LockList([expr {$idx + 1}]) } unset LockList([expr {[array size ProfileList] - 1}]) unset ProfileList([expr {[array size ProfileList] - 1}]) } } get { if { [info exists ProfileList($age)] } { return $ProfileList($age) } else { return 0 } } exists { set tmp_list [array get ProfileList] set idx [lsearch $tmp_list "$email"] if { $idx == -1 } { return 0 } else { return 1 } } getlock { set tmp_list [array get ProfileList] set idx [lsearch $tmp_list "$email"]# puts "$tmp_list donne --> $idx --- $email --- [expr [expr $idx-1] /2] --- $ProfileList([expr [expr $idx-1] /2])" if { $idx == -1 } { return -1 } else { return $LockList([lindex $tmp_list [expr {$idx-1}]]) } } changelock { set tmp_list [array get ProfileList] set idx [lsearch $tmp_list "$email"] if { $idx == -1 } { status_log "changelock called on unexisting email : $email, shouldn't happen!\n" red return -1 } else { set LockList([lindex $tmp_list [expr {$idx-1}]]) $lock } } lockexists { set tmp_list [array get LockList] return [lsearch $tmp_list [LoginList getlock "" "$email"]] } size { return [expr {[array size ProfileList] - 1}] } show { for {set idx 0} {$idx < [array size ProfileList]} {incr idx} { status_log "$idx : $ProfileList($idx)\n"# puts stdout "$idx : $ProfileList($idx) loclist is : $LockList($idx)\n" } } }}#///////////////////////////////////////////////////////////////////////////////# ConfigChange ( window email)# Called when the user selects a combobox item or enters new signin# email : email of the new profile/loginproc ConfigChange { window email } { status_log "ConfigChange: $email\n" blue global HOME HOME2 password log_dir webcam_dir lockSock if { $email != "" } { status_log "ConfigChange: Valid email\n" green if { $email != [::config::getKey login] } { status_log "ConfigChange: Email changed\n" blue if { [LoginList exists 0 [::config::getKey login]] == 1 } { save_config } if { [LoginList exists 0 $email] == 1 } { status_log "ConfigChange: Login exists\n" blue # Profile exists, make the switch set OLDHOME $HOME set dirname [string map {"@" "_" "." "_"} $email] #set dirname [split $email "@ ."] #set dirname [join $dirname "_"] set HOME "[file join $HOME2 $dirname]" if { [CheckLock $email] == -1 } { status_log "ConfigChange: Profile is locked\n" blue msg_box [trans profileinuse] set HOME $OLDHOME # Reselect previous element in combobox set cb [$window list get 0 [LoginList size 0]] set index [lsearch $cb [::config::getKey login]] $window select $index } else { status_log "ConfigChange: Profile is free\n" green if { [info exists password] } { set password "" } # Make sure we delete old lock if { [info exists lockSock] } { if { $lockSock != 0 } { close $lockSock unset lockSock } } if { [LoginList exists 0 [::config::getKey login]] } { LoginList changelock 0 [::config::getKey login] 0 } config::setKey login $email load_config LoginList add 0 $email set log_dir "[file join ${HOME} logs]" set webcam_dir "[file join ${HOME} webcam]" create_dir $webcam_dir # port isn't taken or port taken by other program, meaning profile ain't locked # let's setup the new lock LockProfile $email SaveLoginList cmsn_draw_offline } } } if { [winfo exists .login] } { .login.main.passentry2 delete 0 end if { [info exists password] } { .login.main.passentry2 insert 0 $password } .login.main.statelist select [get_state_list_idx [::config::getKey connectas]] } }}#///////////////////////////////////////////////////////////////////////////////# SwitchProfileMode ( value )# Switches between default and profiled mode, called from radiobuttons# value : If 1 use profiles, if 0 use default profileproc SwitchProfileMode { value } { global lockSock HOME HOME2 log_dir webcam_dir loginmode if { $value == 1 } { if { $HOME == $HOME2 } { for { set idx 0 } { $idx <= [LoginList size 0] } { incr idx } { if { [CheckLock [LoginList get $idx]] != -1 } { set window .login.main.box set cb [$window list get 0 [LoginList size 0]] set index [lsearch $cb [LoginList get $idx]] $window select $index break } } if { [LoginList size 0] == -1 } { msg_box [trans noprofileexists] set loginmode 0 # Going back to default profile set loginmode 0 RefreshLogin .login.main 1 } elseif { $idx > [LoginList size 0] } { msg_box [trans allprofilesinuse] # Going back to default profile set loginmode 0 RefreshLogin .login.main 1 } # Else we are already in a profile, select that profile in combobox } else { set window .login.main.box set cb [$window list get 0 [LoginList size 0]] set index [lsearch $cb [::config::getKey login]] $window select $index unset window } } else { # Switching to default profile, remove lock on previous profiles if needed # Make sure we delete old lock if { [info exists lockSock] } { if { $lockSock != 0 } { close $lockSock unset lockSock } } if { [::config::getKey login] != "" } { LoginList changelock 0 [::config::getKey login] 0 SaveLoginList } # Load default config set HOME $HOME2 config::setKey login "" load_config set log_dir ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -