;==================================================================================================================================================== ; (c)Detlev Dalitz.20120101. ; ; Change or add an entry in Mp3tag's "Tools.ini" for Dano's tool "Mp3tagCompleteTags.exe". ; ; Using WinBatch ini file functions. ;==================================================================================================================================================== intPrevIC50 = IntControl (50, 0, 0, 0, 0) ; Remove "Go to web page" button from error boxes. DirChange (DirScript ()) ; Define files names. strFileExe = Environment ("ProgramFiles") : "\Mp3tag\Mp3tagCompleteTags.exe" ; Adapt this line to the real install path of "Mp3tagCompleteTags.exe". strFileToolsIni = Environment ("APPDATA") : "\Mp3tag\data\tools.ini" ; Filepath to the Mp3tag "Tools.ini". strFileToolsIniTmp = ItemReplace ("tmp.ini", -1, strFileToolsIni, ".") ; Use filename "Tools.tmp.ini". ; Set ini file entry as it should be. strToolName = "Mp3tagCompleteTags" strToolParam = `'"'%%_workingpath%%'"'` strToolPath = StrReplace (strFileExe, "\", "\\") strToolInst = "0" ; Tweak the Tools.ini file because of the leading BOM marker, ; which irritates the WinBatch ini functions (cannot read first line when ini file starts with BOM). ;--------------------------------------------------------------------------------------------- ; Note: This block of code lines does the same as the following block with minor code lines. ;--------------------------------------------------------------------------------------------- ; ; For sure we create a temporary copy of the original Tools.ini file. ; strBOM = "" ; hex EFBBBF. ; strText = FileGet (strFileToolsIni) ; intPos = 1 ; ; Remove the leading BOM. ; intBytes = StrByteCount (strBOM, 0) ; While intPos == StrIndex (strText, strBOM, intPos, @FWDSCAN) ; intPos = intPos + intBytes ; EndWhile ; ; Remove possibly leading empty lines. ; intBytes = StrByteCount (@CRLF, 0) ; While intPos == StrIndex (strText, @CRLF, intPos, @FWDSCAN) ; intPos = intPos + intBytes ; EndWhile ; ; Insert leading BOM only in the first line, let follow other content at the second line. ; strText = strBOM : @CRLF : StrSub (strText, intPos, -1) ; intBytesWritten = FilePut (strFileToolsIniTmp, strText) ; Drop (strText) ;--------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------- ; Note: previous block of code lines can be replaced by the following code lines. ; It does not remove possibly empty lines behind the BOM at the top of the ini file. ;--------------------------------------------------------------------------------------------- ; For sure we create a temporary copy of the original Tools.ini file. strBOM = "" ; hex EFBBBF. strText = FileGet (strFileToolsIni) If StrIndex (strText, strBOM : @CRLF, 1, @FWDSCAN) != 1 Then strText = StrReplace (strText, strBOM, strBOM : @CRLF) intBytesWritten = FilePut (strFileToolsIniTmp, strText) Drop (strText) ; Search in our temp ini file for the possibly existing tool name entry. strListKeys = IniItemizePvt ("", strFileToolsIniTmp) intItemsCount = ItemCount (strListKeys, @TAB) intSection = 0 While intSection < intItemsCount strValue = IniReadPvt ("#" : intSection, "MTTOOLSNAME", "", strFileToolsIniTmp) ; The name of the tool to be displayed in user menu. If StrIndexNC (strValue, strToolName, 1, @FWDSCAN) Then Break intSection = intSection + 1 EndWhile ; Add new entry resp. change the existing entry in our temp ini file. ; intSection points to the right place. IniWritePvt ("#" : intSection, "MTTOOLSNAME", strToolName, strFileToolsIniTmp) ; Name to be displayed in user menu. IniWritePvt ("#" : intSection, "MTTOOLSPARAM", strToolParam, strFileToolsIniTmp) ; Syntax as Mp3tag Format String. Note: Special chars must be escaped as unicode representation, e. g. from "=" to "\u003d". IniWritePvt ("#" : intSection, "MTTOOLSPATH", strToolPath, strFileToolsIniTmp) ; Path string to the executable file, Note: backslashes must be doubled. IniWritePvt ("#" : intSection, "MTTOOLSINST", strToolInst, strFileToolsIniTmp) ; How many instances? 0=only one, 1=for each selected file. ; Copy our temp ini file to the original ini file name. blnResult = FileCopy (strFileToolsIniTmp, strFileToolsIni, @TRUE) ; With confirm dialog. ; blnResult = FileCopy (strFileToolsIniTmp, strFileToolsIni, @FALSE) : Without confirm dialog. :CANCEL ; Remove our temp file. If 1 == FileExist (strFileToolsIniTmp) Then blnResult = FileDelete (strFileToolsIniTmp) Exit ;====================================================================================================================================================