📄 plugins.tcl
字号:
set plugins(${cur_plugin}_URL_plugininfo_online) $URL_plugininfo set plugins(${cur_plugin}_URL_lang_online) $URL_lang set plugins(${cur_plugin}_URL_file_online) $URL_file return 0 } ############################################################### # DownloadMain (plugin) # # Download the main file of a plugin # # Arguments # The name of the plugin # # Return # 0 if there was a problem, 1 else # proc DownloadMain { plugin } { global HOME HOME2 variable plugins set version [getInfo $plugin cvs_version_online] set program_dir [set ::program_dir] set w ".updatelangplugin" if { [winfo exists $w] } { $w.update.txt configure -text "[trans updating] $plugin..." } set place [getInfo $plugin URL_place] set URL [getInfo $plugin URL_main_online] if { $place == 1 } { set token [::http::geturl "${::weburl}/autoupdater/plugins/$plugin/$plugin.tcl" -timeout 120000 -binary 1] } elseif { $place == 2 } { set token [::http::geturl "${::weburl}/autoupdater/plugins2/$plugin/$plugin.tcl" -timeout 120000 -binary 1] } elseif { $place == 3 && $URL != "" } { set URL "[subst $URL]" set token [::http::geturl "$URL" -timeout 120000 -binary 1] } else { return 0 } set status [::http::status $token] if { $status != "ok" } { ::http::cleanup $token return 0 } set content [::http::data $token] if { [string first "<html>" "$content"] != -1 } { ::http::cleanup $token return 0 } set filename [file join [getInfo $plugin plugin_dir] $plugin.tcl] set fid [open $filename w] fconfigure $fid -encoding binary puts -nonewline $fid "$content" close $fid ::http::cleanup $token return 1 } ############################################################### # DownloadLangs (plugin langs) # # Download the lang files of a plugin # # Arguments # The name of the plugin # The langs we want to download, which is a list of items "{langcode version}" # # Return # 0 if there was a problem, 1 else # proc DownloadLangs { plugin langs } { global HOME HOME2 variable plugins set program_dir [set ::program_dir] set w ".updatelangplugin" foreach lang $langs { set langcode [lindex $lang 0] set version [lindex $lang 1] if { [winfo exists $w] } { $w.update.txt configure -text "[trans updating] $plugin : lang$langcode..." } set place [getInfo $plugin URL_place] set URL [getInfo $plugin URL_lang_online] if { $place == 1 } { set token [::http::geturl "${::weburl}/autoupdater/plugins/$plugin/lang/lang$langcode" -timeout 120000 -binary 1] } elseif { $place == 2 } { set token [::http::geturl "${::weburl}/autoupdater/plugins2/$plugin/lang/lang$langcode" -timeout 120000 -binary 1] } elseif { $place == 3 && $URL != "" } { set URL "[subst $URL]" set token [::http::geturl "$URL" -timeout 120000 -binary 1] } else { return 0 } set status [::http::status $token] if { $status != "ok" } { ::http::cleanup $token return 0 } set content [::http::data $token] if { [string first "<html>" "$content"] != -1 } { ::http::cleanup $token return 0 } set filename [file join [getInfo $plugin plugin_dir] "lang" lang$langcode] set fid [open $filename w] fconfigure $fid -encoding binary puts -nonewline $fid "$content" close $fid ::http::cleanup $token } return 1 } ############################################################### # DownloadFiles (plugin files) # # Download the other files of a plugin # # Arguments # The name of the plugin # The files we want to download, which is a list of items "{path version}" # # Return # 0 if there was a problem, 1 else # proc DownloadFiles { plugin files } { global HOME HOME2 variable plugins set program_dir [set ::program_dir] set w ".updatelangplugin" foreach file_version $files { set file [lindex $file_version 0] set version [lindex $file_version 1] if { [winfo exists $w] } { $w.update.txt configure -text "[trans updating] $plugin : $file..." } set place [getInfo $plugin URL_place] set URL [getInfo $plugin URL_file_online] if { $place == 1 } { set token [::http::geturl "${::weburl}/autoupdater/plugins/$plugin/$file" -timeout 120000 -binary 1] } elseif { $place == 2} { set token [::http::geturl "${::weburl}/autoupdater/plugins2/$plugin/$file" -timeout 120000 -binary 1] } elseif { $place == 3 && $URL != "" } { set URL "[subst $URL]" set token [::http::geturl "$URL" -timeout 120000 -binary 1] } else { return 0 } set status [::http::status $token] if { $status != "ok" } { ::http::cleanup $token return 0 } set content [::http::data $token] if { [string first "<html>" "$content"] != -1 } { ::http::cleanup $token return 0 } set filename [file join [getInfo $plugin plugin_dir] $file] set dir [file join [getInfo $plugin plugin_dir] [file dirname $file]] if { ![file isdirectory $dir] } { file mkdir $dir status_log "Auto-update ($plugin) : create dir $dir\n" red } set fid [open $filename w] fconfigure $fid -encoding binary puts -nonewline $fid "$content" close $fid ::http::cleanup $token } return 1 } ############################################################### # UpdatePlugin (plugin) # # Update a plugin # # Arguments # The name of the plugin # # Return # none # proc UpdatePlugin { plugin } { variable plugins variable loadedplugins set error 0 set mainstate 0 set langstate 0 set filestate 0 # if no error occurs while updating the plugin, save the plugininfo.xml file #if { [catch { if { [getInfo $plugin updated_main] == 1 } { set mainstate [DownloadMain $plugin] } else { set mainstate 1 } if { [getInfo $plugin updated_lang] == 1 } { set langstate [DownloadLangs $plugin [getInfo $plugin updated_langs]] } else { set langstate 1 } if { [getInfo $plugin updated_file] == 1 } { set filestate [DownloadFiles $plugin [getInfo $plugin updated_files]] } else { set filestate 1 } # }] } { # status_log "Error while updating $plugin\n" red # set error 1 #} if { $mainstate == 1 && $langstate == 1 && $filestate == 1 && $error == 0 } { SavePlugininfo $plugin # Reload the plugin if it was loaded if { [lsearch $loadedplugins $plugin] != -1 } { UnLoadPlugin $plugin LoadPlugin $plugin } } else { status_log "Error while updating $plugin : main $mainstate, lang $langstate, file $filestate, error $error\n" red } } ############################################################### # UpdatedPlugins () # # Look for updated files for every plugins # # Arguments # none # # Return # 1 if a plugin has been updated, 0 else # proc UpdatedPlugins { } { variable plugins set updatedplugins 0 foreach plugin [getPlugins] { set updated 0 set protected 0 LoadInfoAutoupdate $plugin set path [getInfo $plugin plugin_dir] # If the file is protected if { ![file writable [file join $path plugininfo.xml]] } { continue } if { [LoadInfoAutoupdate_Online $plugin] == 0 } { continue } if { [getInfo $plugin amsn_version_online] == ""} { continue } # If the online plugin is not compatible with the current version of aMSN if { ![::plugins::CheckRequirements [getInfo $plugin amsn_version_online]] } { status_log "Can't update $plugin : required version [getInfo $plugin amsn_version_online]\n" red continue } # If the main file has been updated if { [DetectNew [getInfo $plugin cvs_version] [getInfo $plugin cvs_version_online]] } { set file [file join $path $plugin.tcl] if { ![file writable $file] } { set protected 1 } else { set plugins(${plugin}_updated_main) 1 set updated 1 } } else { set plugins(${plugin}_updated_main) 0 } # Check each language file set plugins(${plugin}_updated_langs) "" foreach lang_online [getInfo $plugin lang_online] { set langcode_online [lindex $lang_online 0] set version_online [lindex $lang_online 1] if { [::lang::LangExists $langcode_online] } { foreach lang [getInfo $plugin lang] { set langcode [lindex $lang 0] set version [lindex $lang 1] if { $langcode == $langcode_online } { break } } if { [::plugins::DetectNew $version $version_online] } { set file [file join $path "lang" lang$langcode] if { [file exists $file] && ![file writable $file] } { set protected 1 } else { lappend plugins(${plugin}_updated_langs) [list $langcode_online $version_online] set plugins(${plugin}_updated_lang) 1 set updated 1 } } } } # Check each other file set plugins(${plugin}_updated_files) "" foreach file_online [getInfo $plugin file_online] { set pathfile_online [lindex $file_online 0] set version_online [lindex $file_online 1] foreach file [getInfo $plugin file] { set pathfile [lindex $file 0] set version [lindex $file 1] if { $pathfile == $pathfile_online } { break } } if { [::plugins::DetectNew $version $version_online] } { set file [file join $path $pathfile_online] if { [file exists $file] && ![file writable $file] } { set protected 1 } else { lappend plugins(${plugin}_updated_files) [list $pathfile_online $version_online] set plugins(${plugin}_updated_file) 1 set updated 1 } } } # If the plugin has been updated and no file is protected, add it to the updated plugin list if { $updated == 1 && $protected == 0 } { set plugins(${plugin}_updated) 1 set updatedplugins 1 } elseif { $updated == 1 } { set plugins(${plugin}_updated) 0 status_log "Can't update $plugin : files protected\n" red } else { set plugins(${plugin}_updated) 0 } } return $updatedplugins } ############################################################### # DetectNew (version onlineversion) # # Tell if the onlineversion is upper the version # # Arguments # The version and the onlineversion # # Return # 1 if onlineversion > version, 0 else # proc DetectNew { version onlineversion } { set current [split $version "."] set new [split $onlineversion "."] if { $version == "" || $onlineversion == ""} { return 0 } elseif { [lindex $new 0] > [lindex $current 0] } { return 1 } elseif { [lindex $new 0] == [lindex $current 0] && [lindex $new 1] > [lindex $current 1] } { return 1 } else { return 0 } } ############################################################### # SavePlugininfo (plugin) # # Save the plugininfo.xml file of a plugin # # Arguments # The name of the plugin # # Return # none # proc SavePlugininfo { plugin } { global HOME2 set file "[file join $HOME2 $plugin.xml]" set pathplugininfo [file join [getInfo $plugin plugin_dir] plugininfo.xml] if { [file exists $file] } { file copy -force $file $pathplugininfo file delete $file } else { status_log "Error while updating $plugin : can't find plugininfo.xml\n" } } ############################################################### # getOnlinePluginsList () # # Get the list of the plugins which are online # # Arguments # none # # Return # none # proc getOnlinePluginsList { } { global HOME2 set token [::http::geturl "${::weburl}/autoupdater/pluginslist.xml" -timeout 120000 -binary 1] set status [::http::status $token] if { $status != "ok" } { ::http::cleanup $token return 0 } set content [::http::data $token] set filename [file join $HOME2 "pluginslist.xml"] set fid [open $filename w] fconfigure $fid -encoding binary puts -nonewline $fid "$content" close $fid ::http::cleanup $token } ############################################################### # OnlinePluginGui () # # Display the plugins which are online # # Arguments # none # # Return # none # # NOT YET FINISHED # proc OnlinePluginGui { } { set w .onlinepluginlist if { [winfo exists $w] } { raise $w return } ::plugins::getOnlinePluginsList toplevel $w wm title $w [trans getonlineplugins] wm geometry $w 500x400 }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -