Код: Выделить всё
DSVidRen=3Код: Выделить всё
DSVidRen=5Это мне нужно, чтобы не лезть в настройки Media Player Classic-а. (меняем рендер для запуска видео с субтитрами). Установлю скрипты как кнопки на панели.
Модераторы: Avada, CaptainFlint, Nik, d-view, Моторокер
Код: Выделить всё
DSVidRen=3Код: Выделить всё
DSVidRen=5Код: Выделить всё
'=============================================
' Замена текста в файле
'
' Параметры:
' {файл} {текст для поиска} {текст для замены}
'=============================================
Option Explicit
Dim FSO, F, Str1, Str2, Text
Set FSO = CreateObject("Scripting.FileSystemObject")
With WScript
F = .Arguments(0)
Str1 = .Arguments(1)
Str2 = .Arguments(2)
End With
F = FSO.GetAbsolutePathName(CreateObject("WScript.Shell").ExpandEnvironmentStrings(F))
Text = FSO.OpenTextFile(F, 1).ReadAll
Text = Replace(Text, Str1, Str2, 1, -1, 1)
FSO.OpenTextFile(F, 2).Write Text
Set FSO = Nothing
WScript.Quit 0Код: Выделить всё
"C:\Путь\к\ини\файлу\mpc-hc.ini" "DSVidRen=3" "DSVidRen=5"Cцeнapий: D:\Total Commander\PLUGINS\vbs\Subtitles.vbs
Cтpoкa: 16
Cимвoл: 1
Oшибкa: Пyть нe нaйдeн
Кoд: 800A004C
Иcтoчник: Oшибкa выпoлнeния Microsoft VBScript
Batya писал(а):Сделал.ackep писал(а):Снова прийти к портабельности.
Код: Выделить всё
TOTALCMD#BAR#DATA
%COMMANDER_PATH%\PLUGINS\vbs\Subtitles.vbs
"%COMMANDER_PATH%\SOFT\Media Player Classic Home Cinema\mpc-hc.ini" "DSVidRen=3" "DSVidRen=5"
%COMMANDER_PATH%\ICO\2.ico
Субтитры [VMR-7 (renderless)]
0
-1---------------------------
Windows Script Host
---------------------------
Сценарий: D:\Total Commander\PLUGINS\vbs\Subtitles.vbs
Строка: 17
Символ: 1
Ошибка: Путь не найден
Код: 800A004C
Источник: Ошибка выполнения Microsoft VBScript
---------------------------
ОК
---------------------------
Код: Выделить всё
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
If WScript.Arguments.Count = 4 Then
ini = WshShell.ExpandEnvironmentStrings(WScript.Arguments(0))
sec = WScript.Arguments(1)
key = WScript.Arguments(2)
val = WScript.Arguments(3)
If ObjFSO.FileExists(ini) Then
WriteIni ini, sec, key, val
End If
End If
' ------------------------------------------------------------------------------
Function ReadIni( myFilePath, mySection, myKey )
' This function returns a value read from an INI file
'
' Arguments:
' myFilePath [string] the (path and) file name of the INI file
' mySection [string] the section in the INI file to be searched
' myKey [string] the key whose value is to be returned
'
' Returns:
' the [string] value for the specified key in the specified section
'
' CAVEAT: Will return a space if key exists but value is blank
'
' Written by Keith Lacelle
' Modified by Denis St-Pierre and Rob van der Woude
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim intEqualPos
Dim objFSO, objIniFile
Dim strFilePath, strKey, strLeftString, strLine, strSection
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
ReadIni = ""
strFilePath = Trim( myFilePath )
strSection = Trim( mySection )
strKey = Trim( myKey )
If objFSO.FileExists( strFilePath ) Then
Set objIniFile = objFSO.OpenTextFile( strFilePath, ForReading, False )
Do While objIniFile.AtEndOfStream = False
strLine = Trim( objIniFile.ReadLine )
' Check if section is found in the current line
If LCase( strLine ) = "[" & LCase( strSection ) & "]" Then
strLine = Trim( objIniFile.ReadLine )
' Parse lines until the next section is reached
Do While Left( strLine, 1 ) <> "["
' Find position of equal sign in the line
intEqualPos = InStr( 1, strLine, "=", 1 )
If intEqualPos > 0 Then
strLeftString = Trim( Left( strLine, intEqualPos - 1 ) )
' Check if item is found in the current line
If LCase( strLeftString ) = LCase( strKey ) Then
ReadIni = Trim( Mid( strLine, intEqualPos + 1 ) )
' In case the item exists but value is blank
If ReadIni = "" Then
ReadIni = " "
End If
' Abort loop when item is found
Exit Do
End If
End If
' Abort if the end of the INI file is reached
If objIniFile.AtEndOfStream Then Exit Do
' Continue with next line
strLine = Trim( objIniFile.ReadLine )
Loop
Exit Do
End If
Loop
objIniFile.Close
Else
WScript.Echo strFilePath & " doesn't exists. Exiting..."
Wscript.Quit 1
End If
End Function
Sub WriteIni( myFilePath, mySection, myKey, myValue )
' This subroutine writes a value to an INI file
'
' Arguments:
' myFilePath [string] the (path and) file name of the INI file
' mySection [string] the section in the INI file to be searched
' myKey [string] the key whose value is to be written
' myValue [string] the value to be written (myKey will be
' deleted if myValue is <DELETE_THIS_VALUE>)
'
' Returns:
' N/A
'
' CAVEAT: WriteIni function needs ReadIni function to run
'
' Written by Keith Lacelle
' Modified by Denis St-Pierre, Johan Pol and Rob van der Woude
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim blnInSection, blnKeyExists, blnSectionExists, blnWritten
Dim intEqualPos
Dim objFSO, objNewIni, objOrgIni, wshShell
Dim strFilePath, strFolderPath, strKey, strLeftString
Dim strLine, strSection, strTempDir, strTempFile, strValue
strFilePath = Trim( myFilePath )
strSection = Trim( mySection )
strKey = Trim( myKey )
strValue = Trim( myValue )
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set wshShell = CreateObject( "WScript.Shell" )
strTempDir = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
strTempFile = objFSO.BuildPath( strTempDir, objFSO.GetTempName )
Set objOrgIni = objFSO.OpenTextFile( strFilePath, ForReading, True )
Set objNewIni = objFSO.CreateTextFile( strTempFile, False, False )
blnInSection = False
blnSectionExists = False
' Check if the specified key already exists
blnKeyExists = ( ReadIni( strFilePath, strSection, strKey ) <> "" )
blnWritten = False
' Check if path to INI file exists, quit if not
strFolderPath = Mid( strFilePath, 1, InStrRev( strFilePath, "\" ) )
If Not objFSO.FolderExists ( strFolderPath ) Then
WScript.Echo "Error: WriteIni failed, folder path (" _
& strFolderPath & ") to ini file " _
& strFilePath & " not found!"
Set objOrgIni = Nothing
Set objNewIni = Nothing
Set objFSO = Nothing
WScript.Quit 1
End If
While objOrgIni.AtEndOfStream = False
strLine = Trim( objOrgIni.ReadLine )
If blnWritten = False Then
If LCase( strLine ) = "[" & LCase( strSection ) & "]" Then
blnSectionExists = True
blnInSection = True
ElseIf InStr( strLine, "[" ) = 1 Then
blnInSection = False
End If
End If
If blnInSection Then
If blnKeyExists Then
intEqualPos = InStr( 1, strLine, "=", vbTextCompare )
If intEqualPos > 0 Then
strLeftString = Trim( Left( strLine, intEqualPos - 1 ) )
If LCase( strLeftString ) = LCase( strKey ) Then
' Only write the key if the value isn't empty
' Modification by Johan Pol
If strValue <> "<DELETE_THIS_VALUE>" Then
objNewIni.WriteLine strKey & "=" & strValue
End If
blnWritten = True
blnInSection = False
End If
End If
If Not blnWritten Then
objNewIni.WriteLine strLine
End If
Else
objNewIni.WriteLine strLine
' Only write the key if the value isn't empty
' Modification by Johan Pol
If strValue <> "<DELETE_THIS_VALUE>" Then
objNewIni.WriteLine strKey & "=" & strValue
End If
blnWritten = True
blnInSection = False
End If
Else
objNewIni.WriteLine strLine
End If
Wend
If blnSectionExists = False Then ' section doesn't exist
objNewIni.WriteLine
objNewIni.WriteLine "[" & strSection & "]"
' Only write the key if the value isn't empty
' Modification by Johan Pol
If strValue <> "<DELETE_THIS_VALUE>" Then
objNewIni.WriteLine strKey & "=" & strValue
End If
End If
objOrgIni.Close
objNewIni.Close
' Delete old INI file
objFSO.DeleteFile strFilePath, True
' Rename new INI file
objFSO.MoveFile strTempFile, strFilePath
Set objOrgIni = Nothing
Set objNewIni = Nothing
Set objFSO = Nothing
Set wshShell = Nothing
End Sub
Код: Выделить всё
Dim TCS
Set TCS = CreateObject("TCScript.Helper")
ini="%COMMANDER_PATH%\SOFT\Media Player Classic Home Cinema\mpc-hc.ini"
section="кто бы знал название секции?"
key="DSVidRen"
value=3
TCS.INIWrite ini, section, key, value
Set TCS = Nothing
WScript.QuitКод: Выделить всё
TOTALCMD#BAR#DATA
%COMMANDER_PATH%\PLUGINS\vbs\Subtitles.vbs
"%%COMMANDER_PATH%%\SOFT\Media Player Classic Home Cinema\mpc-hc.ini" "DSVidRen=3" "DSVidRen=5"
%COMMANDER_PATH%\ICO\2.ico
Субтитры [VMR-7 (renderless)]
0
-1Код: Выделить всё
Dim TCS
Set TCS = CreateObject("TCScript.Helper")
ini="%COMMANDER_PATH%\SOFT\Media Player Classic Home Cinema\mpc-hc.ini"
section="Settings"
key="DSVidRen"
value = TCS.INIRead (ini, section, key)
If value=3 Then value=5 Else value=3
TCS.INIWrite ini, section, key, value
Set TCS = Nothing
WScript.QuitПридумал полезное применение своему скрипту:Batya писал(а):используем vbs:
Код:
'=============================================
' Замена текста в файле
Путь к скрипту (зелёным цветом) указываем свой.TOTALCMD#BAR#DATA
"%Commander_Path%\Utils\WHS\ReplaceText.vbs" "%Commander_Path%\wincmd.ini" "%Commander_Path%"
"%%Commander_Path%%"
%Commander_Path%\WCMICONS.DLL
Замена путей в wincmd.ini
-1
Спасибо, пригодилось. Сначала не получилось: скрипт пытался найти и заменить в ini-файле "C:\Wincmd", а там были строки с "C:\wincmd". После того как заменил в скрипте бинарное сравнение (vbBinaryCompare = 0) на текстовое (vbTextCompare = 1) - всё заработало как мне было надо.Batya писал(а):Придумал полезное применение своему скрипту