Jump to content

FileInstall corrupts XML (changes UTF-16 encoding)


Recommended Posts

Hi All

I have a task to install Adobe FMLE (Flash Media Live Encoder 3.1) in some systems and create a XML profile and invoke RTMP streaming as and when needed - by command line. To accomplish this task, I have a few applications in AutoIt and one of them contains the default XML profile and some logic to decide the stream name on the basis of individual systems. So I use a FileInstall("source", $destination, 1) command in my script and compile it.

When this application is executed, it ingresses the XML (UTF-16) from source and outputs it to outputs it to destination. Then I use the function "_ReplaceStringInFile()" to replace the server URL and stream name in the default XML and I pass it to Adobe's command line application (FMLECmd.exe).

The destination XML gets corrupted and I cannot open it in either web browsers or cannot pass it to FMLECmd.exe - they all throw errors.

I guess while ingress and out of file, AutoIt changes the file encoding (as I was able to re-produce similar error messages on copy-pasting the XML contents to a notepad and saving as .xml file (ANSI encoding)). How can I avoid it or solve the problem.

Please help.

- Sincere Regards

Akshay Mishra

Link to comment
Share on other sites

FileInstall() does a binary file copy that does not interpret encoding at all. If the file encoding is changed it would be when you edit the file, not when FileInstall saved it to disk.

:graduated:

P.S. On further examination, the problem might be in _ReplaceStringInFile():

;===============================================================================
    ;== Open the output file in write mode
    ;===============================================================================
    Local $hWriteHandle = FileOpen($szFileName, $FO_OVERWRITE)

Where $FO_OVERWRITE = 2, from FileConstants.au3.

You could edit that to a custom function with $FO_UNICODE instead of $FO_OVERWRITE and it might work for you.

:(

Edit: Even better, just change that section to:

;===============================================================================
    ;== Open the output file in write mode
    ;===============================================================================
    Local $iEncoding = FileGetEncoding($szFileName)
    Local $hWriteHandle = FileOpen($szFileName, $iEncoding + $FO_OVERWRITE)
    If $hWriteHandle = -1 Then Return SetError(2, 0, -1)

:D

Edit 2: Opened BugTrack #1805.

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Dear PsaltyDS

Thanks alot. Yes you were right, it was not FileInstall() but editing it which was resulting in the issue.

I followed your suggestion and am able to copy and edit the XML successfully.

I wrote a function for that, here is the code snippet am using :

;=================================================================================================

Func _EditXml($filepath, $oldStr, $newStr)

Local $iEncoding = FileGetEncoding($filepath)

;~ MsgBox(4096, "File Encoding", "File Path = " & $filepath & @CRLF & "Encoding = " & $iEncoding)

;~ ------------------------------ Read File

Local $hndlFileRead = FileOpen($filepath, ($iEncoding + $FO_READ))

If ($hndlFileRead = -1) Then

Return SetError(2, 0, -1)

EndIf

Local $FileContent = FileRead($hndlFileRead)

FileClose($hndlFileRead)

;~ --------------------------------------

$FileContent = StringReplace($FileContent, $oldStr, $newStr)

;~ WriteFile ------------------------------------

Local $hndlFileWrite = FileOpen($filepath, ($iEncoding + $FO_OVERWRITE))

If ($hndlFileWrite = -1) Then

Return SetError(2, 0, -1)

EndIf

FileWrite($hndlFileWrite, $FileContent)

FileClose($hndlFileWrite)

;~ ----------------------------------------------------------

EndFunc ;==>_EditXml

;=================================================================================================

I am very grateful to your help and the promptness with which you helped.

Thanks once again. :graduated:

-- Sincere Regards

Akshay Mishra

(Bangalore, India)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...