Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single Post  Topic: Обмен кнопками 
Author Message
DrShark



PostPosted: Thu Jan 03, 2008 16:20    Post subject: Reply with quote

Примеры кнопок для изменения языка:
1. Устанавливает английский язык по-умолчанию
Quote:
TOTALCMD#BAR#DATA
"C:\Program Files\totalcmd\changelng.vbs"
%%eng%%
C:\WINDOWS\System32\WScript.exe
changelng (one lng)
C:\Program Files\totalcmd\

-1

2. По-очереди меняет языки, идущие в параметрах.
Quote:
TOTALCMD#BAR#DATA
wscript.exe
"C:\Program Files\totalcmd\changelng.vbs" wcmd_rus wcmd_ukr wcmd_ext1_eng %%eng%%
C:\WINDOWS\System32\WScript.exe
changelng - multilang
C:\Program Files\totalcmd\

-1

Глядя на эти кнопки, надеюсь, станет понятным описание к скрипту:
Code:
'====================================================================
' changelng 1.0 - VB-скрипт для изменения языка Total Commander
' Использование:
' [wscript.exe] changelng.vbs wcmd_rus [wcmd_ukr] [%%eng%%]
' В рамках ([]) поданы необязательные параметры.
' Один параметр, следующий за changelng.vbs, указывает на
' применение этого языка независимо от текущего.
' Если параметра 2 или более, определяется текущий язык,
' и если он присутствует в параметрах, используется следующий за ним,
' в противном случае применяется язык, указанный в первом параметре.
' Под применением языка подразумевается применение .lng и .mnu файла,
' имя которого указано в параметре, т.е. для wcmd_rus будут использоватся
' wcmd_rus.lng и wcmd_rus.mnu
' Для использования умолчательного английского языка
' в качестве параметра следует использовать %%eng%%
' (c) DrShark, 2008
' Для работы с ini используется слегка модифицированный код Nolan Bagadiong,
' NAME: VBScript ReadINI/WriteINI
'
' AUTHOR: Bagadiong, Nolan
' DATE : 7/27/2001
'====================================================================

' Объявление переменных
Option Explicit
Public Lngext, Mnuext
Public FileSysObj, ini, reSection, reKey
Public ShellObj, argument, oArgs, ArgNum, teststr, LngArg, MyLng, MyMnu, Lng, Mnu
Public myscriptname, curdir, wincmdini
Set ShellObj = CreateObject("WScript.Shell")
Set oArgs = WScript.Arguments
LngExt = ".lng"
MnuExt = ".mnu"

Call main()
' Основной код, не относящийся к применению языков
Sub main()
Dim ErrMsg
myscriptname = Wscript.ScriptFullName
curdir  = Left(myscriptname, InStrRev(myscriptname, "\", -1, 1))
wincmdini = READINI (curdir & "changelng.ini", "General", "wincmdini")
ArgNum = oArgs.Count
LngArg = ArgNum - 1
If ArgNum = 0 Then
 ErrMsg = MsgBox ("Parameters required! See script description for details." & vbCrLf & "Open it in Notepad?", vbYesNo, "Error")
   If ErrMsg = 6 then
                ShellObj.run "Notepad.exe " & chr(34) & Wscript.ScriptFullName & chr(34)
   Else
   WScript.Quit
   End If
 WScript.Quit
End If
MyLng = WScript.Arguments(LngArg)
If ArgNum = 1 Then Call SingleLng()
If ArgNum > 1 Then Call MultiLng()
End Sub

' Если переметр один:
Sub SingleLng()
If MyLng = "%eng%" then
 MnuExt = ""
 LngExt = ""
 MyLng = ""
 MyMnu = ""
End If
MyMnu = MyLng + MnuExt
Call WRITEINI (wincmdini, "Configuration", "Mainmenu", MyMnu)

MyLng = MyLng + LngExt
Call WRITEINI (wincmdini, "Configuration", "LanguageIni", MyLng)
ShellObj.SendKeys "%{F4}"
WScript.Sleep 1000
ShellObj.Run chr(34) & "totalcmd.exe" & chr(34)
End Sub

' Если параметров несколько:
Sub MultiLng()
Dim LngLen, strArg, counter, curlngcnt, WriteLng
counter = 0
Lng = READINI (wincmdini, "Configuration", "LanguageIni")
Mnu = READINI (wincmdini, "Configuration", "Mainmenu")
LngLen = Len(Lng)
If LngLen = 0 then
 MyLng = 0
Else
 MyLng = Mid(Lng, 1, LngLen - 4)
End If
For Each strArg in oArgs
    counter = counter + 1
    if strArg = MyLng then curlngcnt =  counter
Next
If curlngcnt = ArgNum then
 WriteLng = WScript.Arguments(0)
Else
 WriteLng = WScript.Arguments(curlngcnt)
End If
if WriteLng = "%eng%" then
 WriteLng = ""
 MyMnu = ""
 MnuExt = ""
 LngExt = ""
End If
MyMnu = WriteLng + MnuExt
call WRITEINI (wincmdini, "Configuration", "Mainmenu", MyMnu)
MyLng = WriteLng + LngExt
call WRITEINI (wincmdini, "Configuration", "LanguageIni", MyLng)
ShellObj.SendKeys "%{F4}"
WScript.Sleep 1000
ShellObj.Run chr(34) & curdir & "totalcmd.exe" & chr(34)
End Sub

' Работа с ini

'Usage
' READINI (file, section, item) returns value; otherwise returns ""

Function ReadINI(file, section, key)
dim line
set FileSysObj = CreateObject("Scripting.FileSystemObject")
ReadIni=""
If FileSysObj.FileExists(file) then
     Set ini = FileSysObj.OpenTextFile( file, 1, False)

     ' Return array of sections if section and keys are empty
     if section="" then
          set reSection          =new RegExp
          reSection.Global =True
          reSection.IgnoreCase=True
          reSection.Pattern ="\[([a-zA-Z0-9 ]*)\]"

          Do While ini.AtEndofStream =False
               line = ini.ReadLine

               if reSection.Test(line) then
                    tempSection=tempSection & reSection.Replace(line, "$1") & ","
               end if
          loop
          ini.close
          tempSection=left(tempSection, len(tempSection)-1)
          ReadINI=split(tempSection,",")
          set reSection=nothing
          exit function
     end if
' Return array of keys if keys are empty
     if key="" then

          set reSection          =new RegExp
          reSection.Global =True
          reSection.IgnoreCase=True
          reSection.Pattern ="\s*\[\s*" & section & "\s*\]"

          Do While ini.AtEndofStream =False
               line = ini.ReadLine

               if reSection.Test(line) then
                    line=ini.ReadLine

                    do while instr(line,"[")=0
                         tempKeys=tempKeys & trim(left(line,instr(line,"=")-1)) & ","
                         line=ini.ReadLine
                    loop
                    tempKeys=left(tempKeys,(len(tempkeys)-1)) ' Remove last comma
                    ReadINI =split(tempKeys,",")
                    exit function
               end if
          loop
     end if
'===================

' READINI Part for file, section, key

     set reSection          =new RegExp
     reSection.Global =False
     reSection.IgnoreCase=True
     'reSection.Pattern ="\s*[\s*" & section & "\s*]"
     reSection.Pattern ="\s*\[\s*" & section & "\s*\]"

     set reKey           =new RegExp
     reKey.Global     =False
     reKey.IgnoreCase=True
     reKey.Pattern="\s*" & key & "\s*=\s*"

     Do While ini.AtEndofStream = False
          line = ini.ReadLine

               if reSection.Test(line) = True then

                    line=ini.ReadLine
                    do while instr(line,"[")=0

                         if reKey.Test(line) then

                              ReadINI=trim(mid(line,instr(line,"=")+1))

                              exit do
                         end if
                         line=ini.ReadLine
                    Loop

          exit do
          end if
     loop
     ini.Close
     set reSection=nothing
     set reKey =nothing
end if ' If FileSysObj
end function

'==================
' WRITEINI ( file, section, item, value )
' file = path and name of ini file
' section = [Section] must be in brackets in the ini file
' item = the variable to read;
' value = the value to assign to the item.
'
Sub WriteIni( file, section, item, value )
Dim in_section, section_exists, item_exists, wrote, path, TristateFalse
Dim reWSection, reItem, read_ini, write_ini
Dim line
set FileSysObj = CreateObject("Scripting.FileSystemObject")
in_section = False
section_exists = False
item_exists = ( ReadIni( file, section, item ) <> "" )
wrote = False
path = Mid( file, 1, InStrRev( file, "\" ) )
Set read_ini = FileSysObj.OpenTextFile( file, 1, True, TristateFalse )
Set write_ini = FileSysObj.CreateTextFile( path & "temp_ini.ini", False )

set reWSection           =new RegExp
reWSection.Global      =False
reWSection.IgnoreCase=True
reWSection.Pattern      ="\s*[\s*" & section & "\s*]"

set reItem =new RegExp
reItem.Global =False
reItem.IgnoreCase=True
reItem.Pattern ="\s*" & item & "\s*="

While read_ini.AtEndOfStream = False
line = read_ini.ReadLine

     If wrote = False Then
          If reWSection.Test(line) Then
               section_exists = True
               in_section = True
          ElseIf InStr( line, "[" )> 0 Then
               in_section = False
          End If
     End If

     If in_section Then
          If item_exists = False Then
               write_ini.WriteLine line
               write_ini.WriteLine item & "=" & value
               wrote = True
               in_section = False
               'DrShark
               'msgbox "Writing " & line
               ElseIf reItem.Test(line) Then
                    write_ini.WriteLine item & "=" & value
                    wrote = True
                    in_section = False
          Else
               write_ini.WriteLine line
          End If
     Else
          write_ini.WriteLine line
     End If
Wend

If section_exists = False Then ' section doesn't exist
     section=trim(section)
     item     =trim(item)

     write_ini.WriteLine
     write_ini.WriteLine "[" & section & "]"
     write_ini.WriteLine item & "=" & value
End If

read_ini.Close
write_ini.Close
FileSysObj.DeleteFile file
FileSysObj.MoveFile path & "temp_ini.ini", file
set reWSection=nothing
set reItem=nothing
End Sub

Установка скрипта проста:
бросить его в папку с totalcmd.exe, затем создать там ini-файл changelng.ini и записать туда правильный путь к wincmd.ini:
Quote:
[General]
wincmdini=c:\program files\totalcmd\wincmd.ini

Затем остаётся только перетащить скрипт на панель ТК и вбить нужные параметры.
Собственно, это первый работающий вариант скрипта и в дальнейшем
есть мысли его улучшить, т.к. сейчас он, очень вероятно Smile, не работает на read-only носителях.

з.ы. Модераторам: можно перенести скрипт в автоматизацию, а здесь оставить кнопки. Есть смысл?
View user's profile Send private message Visit poster's website


Powered by phpBB © 2001, 2005 phpBB Group