Jump to content
Sign in to follow this  
ttleser

FileWrite & different langauge

Recommended Posts

ttleser

I've got a script that reads an INI file line by line. The file contains multiple langauges. I've created a script that modifies certain lines that meet a criteria I specified. I'm having a problem with FileWrite and one of the non-english langauges, Japanese in particular.

My script will scan the original INI file using a FOR NEXT loop and place each line into an array. I can display the Japanese writing in the array using a msgbox and see it perfectly, no distortion. If I use FileWrite to write the contents of the array to another INI file, the line that's Japanese gets changed around.

Here's what the original lines looks like:

[CXT\localized_names\Item5]

template_name=VSO 光沢テンプレート, クリアな背景でページごとに 4 つまでのエピソード/タイトル

Description=ページごとに 4 つまでのエピソードのあるエピソード/チャプタ メニュー、ページごとに 3 つまでの音声と字幕言語の設定メニュー、チャプタと設定のメニューにアクセスするイントロダクション メニューを備えています。

locale=1041

locale_name=Japanese

Thumbnail=clear\_4chapitres_modele.jpg

Here's what it looks like in the new INI file as a result of FileWrite:

[CXT\localized_names\Item5]

template_name=VSO ????????, ????????????? 4 ?????????/????

Description=?????? 4 ?????????????????/???? ??????????? 3 ??????????????????????????????????????????????? ????????????

locale=1041

locale_name=Japanese

Thumbnail=clear\_4chapitres_modele.jpg

Anyone have any thoughts on this? Oh, BTW, I'm viewing both original and new file using notepad.

Share this post


Link to post
Share on other sites
PsaltyDS

INI files are usually plain ANSI text. Don't you need to use Unicode formats to get multilingual support like that?

:)


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

Share this post


Link to post
Share on other sites
ttleser

#include <file.au3>
#include <GUIConstantsEx.au3>
#Include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#Include <String.au3>


Dim $aRecords,$SourceFile,$DestFile,$CheckNewIntro,$NewIntroSecVar,$CheckNewMain,$CheckNewOutro

$hGUI = GUICreate("Label Printer Test Utility",300,350)

GuiCtrlCreateLabel("Template Name within ConvertX",10,5,160,20)
$NewTemplateName = GuiCtrlCreateInput("",10,25,280,20)

$ChooseSource = GUICtrlCreateButton("Choose Source Template",10,55,130,30,0x2000)
$ChooseDest = GUICtrlCreateButton("Choose Destination File",160,55,130,30,0x2000)

GuiCtrlCreateLabel("Original",96,100,60,20)
GuiCtrlCreateLabel("Intro Duration",10,120,80,20)
$CurrentIntroDuration = GUICtrlCreateInput("",90,115,50,20,0x0002)
GUICtrlSetState(-1, $GUI_DISABLE)
GuiCtrlCreateLabel("Sec",145,120,30,20)
$CurrentIntroSec = GuiCtrlCreateLabel("",170,120,105,20,0x0002)

GuiCtrlCreateLabel("Main Duration",10,145,80,20)
$CurrentMainDuration = GuiCtrlCreateInput("",90,140,50,20,0x0002)
GUICtrlSetState(-1, $GUI_DISABLE)
GuiCtrlCreateLabel("Sec",145,145,30,20)
$CurrentMainSec = GuiCtrlCreateLabel("",170,145,105,20,0x0002)

GuiCtrlCreateLabel("Outro Duration",10,170,80,20)
$CurrentOutroDuration = GuiCtrlCreateInput("",90,165,50,20,0x0002)
GUICtrlSetState(-1, $GUI_DISABLE)
GuiCtrlCreateLabel("Sec",145,1470,30,20)
$CurrentOutroSec = GuiCtrlCreateLabel("",170,170,105,20,0x0002)

GuiCtrlCreateLabel("New",102,200,60,20)
GuiCtrlCreateLabel("Intro Duration",10,220,80,20)
$NewIntroDuration = GuiCtrlCreateInput("",90,215,50,20,0x0002)
GuiCtrlCreateLabel("Sec",145,220,30,20)
$NewIntroSec = GuiCtrlCreateLabel("",170,220,105,20,0x0002)

GuiCtrlCreateLabel("Main Duration",10,245,80,20)
$NewMainDuration = GuiCtrlCreateInput("",90,240,50,20,0x0002)
GuiCtrlCreateLabel("Sec",145,245,30,20)
$NewMainSec = GuiCtrlCreateLabel("",170,245,105,20,0x0002)

GuiCtrlCreateLabel("Outro Duration",10,270,80,20)
$NewOutroDuration = GuiCtrlCreateInput("",90,265,50,20,0x0002)
GuiCtrlCreateLabel("Sec",145,270,30,20)
$NewOutroSec = GuiCtrlCreateLabel("",170,270,105,20,0x0002)

$Process = GUICtrlCreateButton("PROCESS",90,300,120,40)

GUISetState()
While 1
    $msg = GUIGetMsg()
    If GuiCtrlRead($NewIntroDuration) <> $CheckNewIntro Then
        $CheckNewIntro = GuiCtrlRead($NewIntroDuration)
        GuiCtrlSetData($NewIntroSec,fullNotation(GuiCtrlRead($NewIntroDuration)*1000000)&" MicroSec")
    EndIf
    If GuiCtrlRead($NewMainDuration) <> $CheckNewMain Then
        $CheckNewMain = GuiCtrlRead($NewMainDuration)
        GuiCtrlSetData($NewMainSec,fullNotation(GuiCtrlRead($NewMainDuration)*1000000)&" MicroSec")
    EndIf
    If GuiCtrlRead($NewOutroDuration) <> $CheckNewOutro Then
        $CheckNewOutro = GuiCtrlRead($NewOutroDuration)
        GuiCtrlSetData($NewOutroSec,fullNotation(GuiCtrlRead($NewOutroDuration)*1000000)&" MicroSec")
    EndIf
    Select
        Case $msg = $ChooseSource
            ClearData()
            ChooseSource()
            ReadFile()
        Case $msg = $ChooseDest
            ChooseDest()
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Process
            Process()
    EndSelect
WEnd

Func ClearData()
    $aRecords = ""
    GUICtrlSetData($CurrentIntroDuration,"")
    GUICtrlSetData($CurrentMainDuration,"")
    GUICtrlSetData($CurrentOutroDuration,"")
EndFunc


Func fullNotation($number)
  Local $t = String($number)
  If StringInstr($t, "e-") Then
     $t = StringSplit( StringReplace($t, "e-", "|") , "|")
     Return "." & _StringRepeat("0", $t[2]-1)  & StringReplace($t[1], ".", "")
  Else
     Return $number
  EndIf
EndFunc

Func ChooseSource()
    $message = "Choose the Source Template File."
    $SourceFile = FileOpenDialog($message, "c:\program files\VSO\ConvertX\3\Templates", "Template (*.ini)")

    If @error Then
        MsgBox(4096,"","No File Chosen.")
    EndIf   
EndFunc

Func ChooseDest()
    $message = "Choose the file to be created."
    $DestFile = FileSaveDialog($message, "c:\program files\VSO\ConvertX\3\Templates", "Template (*.ini)",16,"TemplateA.ini")

    If @error Then
        MsgBox(4096,"","No File Specified.")
    EndIf   
EndFunc

Func ReadFile()
    If Not _FileReadToArray($SourceFile,$aRecords) Then
       MsgBox(4096,"Error", " Error reading file:" & @error)
       Exit
    EndIf

    For $x = 1 to $aRecords[0]
        If $aRecords[$x] = "Origin=MNUP_INTRO" AND StringLeft($aRecords[$x+1],10) = "TimeStamp=" Then
        ElseIf StringLeft($aRecords[$x],15) = "intro_duration=" AND GuiCtrlRead($CurrentIntroDuration) = "" Then
            GUICtrlSetData($CurrentIntroDuration,(StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))*.000001))
            $IntroSec = StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))
            If StringLen($IntroSec) < 6 Then
                While StringLen($IntroSec) < 6
                    $IntroSec = "0"&$IntroSec
                WEnd
                $IntroSec = "."&$IntroSec
                While StringRight($IntroSec,1) = "0"
                    $IntroSec = StringTrimRight($IntroSec,1)
                WEnd
            Else
                $IntroSec = _StringInsert($IntroSec, ".", StringLen($IntroSec)-6)
                $IntroSec = StringTrimRight($IntroSec,7)
            EndIf
            GuiCtrlSetData($CurrentIntroSec,$IntroSec*1000000&" MicroSec")
            
        ElseIf StringLeft($aRecords[$x],14) = "main_duration=" AND GuiCtrlRead($CurrentMainDuration) = "" Then
            GUICtrlSetData($CurrentMainDuration,(StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))*.000001))
            $MainSec = StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))
            If StringLen($MainSec) < 6 Then
                msgbox(0,"test",$MainSec)
                While StringLen($MainSec) < 6
                    $MainSec = "0"&$MainSec
                    msgbox(0,"Add",$MainSec)
                WEnd
                $MainSec = "."&$MainSec
                While StringRight($MainSec,1) = "0"
                    $MainSec = StringTrimRight($MainSec,1)
                WEnd
            Else
                $MainSec = _StringInsert($MainSec, ".", StringLen($MainSec)-6)
                $MainSec = StringTrimRight($MainSec,7)
            GuiCtrlSetData($CurrentMainSec,$MainSec*1000000&" MicroSec")
            EndIf
        ElseIf StringLeft($aRecords[$x],15) = "outro_duration=" AND GuiCtrlRead($CurrentOutroDuration) = "" Then
            GUICtrlSetData($CurrentOutroDuration,(StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))*.000001))
            $OutroSec = StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))
            If StringLen($OutroSec) < 6 Then
                msgbox(0,"test",$OutroSec)
                While StringLen($OutroSec) < 6
                    $OutroSec = "0"&$OutroSec
                    msgbox(0,"Add",$OutroSec)
                WEnd
                $OutroSec = "."&$OutroSec
                While StringRight($OutroSec,1) = "0"
                    $OutroSec = StringTrimRight($OutroSec,1)
                WEnd
            Else
                $OutroSec = _StringInsert($OutroSec, ".", StringLen($OutroSec)-6)
                $OutroSec = StringTrimRight($OutroSec,7)
            EndIf
            GuiCtrlSetData($CurrentOutroSec,$OutroSec*1000000&" MicroSec")
        EndIf
    Next
EndFunc

Func Process()
    $aRecords = ""
    If Not _FileReadToArray($SourceFile,$aRecords) Then
       MsgBox(4096,"Error", " Error reading file:" & @error)
       Exit
    EndIf
    
    $FileWrite = FileOpen($DestFile, 2)
    For $x = 1 to $aRecords[0]
        If StringLeft($aRecords[$x],10) = "TimeStamp=" AND $aRecords[$x-1] = "Origin=MNUP_INTRO" Then
            $TimeStamp = StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))
            $IntroRatio = $TimeStamp/(GuiCtrlRead($CurrentIntroDuration)*1000000)
            If StringIsFloat($IntroRatio*(GuiCtrlRead($NewIntroDuration)*1000000)) = 1 Then
                FileWrite($FileWrite,"TimeStamp="&(Int($IntroRatio*(GuiCtrlRead($NewIntroDuration)*1000000))+1)&@CRLF)
            Else
                FileWrite($FileWrite,"TimeStamp="&$IntroRatio*(GuiCtrlRead($NewIntroDuration)*1000000)&@CRLF)
            EndIf
            
        ElseIf StringLeft($aRecords[$x],10) = "TimeStamp=" AND $aRecords[$x-1] = "Origin=MNUP_OUTRO" Then
            $TimeStamp = StringTrimLeft($aRecords[$x],StringInStr($aRecords[$x],"="))
            $OutroRatio = $TimeStamp/(GuiCtrlRead($CurrentOutroDuration)*1000000)
            If StringIsFloat($OutroRatio*(GuiCtrlRead($NewOutroDuration)*1000000)) = 1 Then
                FileWrite($FileWrite,"TimeStamp="&(Int($OutroRatio*(GuiCtrlRead($NewOutroDuration)*1000000))+1)&@CRLF)
            Else
                FileWrite($FileWrite,"TimeStamp="&$OutroRatio*(GuiCtrlRead($NewOutroDuration)*1000000)&@CRLF)
            EndIf
        
        ElseIf StringLeft($aRecords[$x],14) = "template_name=" AND $aRecords[$x-1] = "[CXT\localized_names\Item5]" Then
            msgbox(0,"test",$aRecords[$x])
            
        ElseIf StringLeft($aRecords[$x],14) = "template_name=" AND $aRecords[$x-1] <> "[CXT\localized_names\Item0]" Then
            FileWrite($FileWrite,$aRecords[$x]&" ,"&@CRLF)
        
        ElseIf StringLeft($aRecords[$x],14) = "template_name=" AND $aRecords[$x-1] = "[CXT\localized_names\Item0]" Then
            FileWrite($FileWrite,"template_name="&GuiCtrlRead($NewTemplateName)&@CRLF)
        
        ElseIf StringLeft($aRecords[$x],15) = "intro_duration=" Then
            FileWrite($FileWrite,"intro_duration="&(GuiCtrlRead($NewIntroDuration)*1000000)&@CRLF)
            
        ElseIf StringLeft($aRecords[$x],14) = "main_duration=" Then
            FileWrite($FileWrite,"main_duration="&(GuiCtrlRead($NewMainDuration)*1000000)&@CRLF)
            
        ElseIf StringLeft($aRecords[$x],15) = "outro_duration=" Then
            FileWrite($FileWrite,"outro_duration="&(GuiCtrlRead($NewOutroDuration)*1000000)&@CRLF)
            
        Else
            FileWrite($FileWrite, $aRecords[$x]&@CRLF)
        EndIf
    Next
    FileClose($FileWrite)
    msgbox(0,"NOTICE","Process is complete.")
EndFunc

Portion of the Original File:

[CXT\localized_names\Item0]

template_name=VSO glossy template, clear background, up to 4 episodes/titles per page

Description=Contains A episode and chapter menu with up to 4 episodes per page, a settings menu with up to 3 audio and 3 subtitles languages per page and a root menu to access to the chapter and settings menu

locale_name=English

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names\Item1]

template_name=modèle transparent glossé de VSO, jusqu'à 4 episodes/titres par page

Description=Contient un menu épisodes et chapitres avec jusqu'à 4 épisodes par page, un menu réglages de langue avec jusqu'à 3 audio et 3 sous-titres, et un menu racine pour donner accès aux menus chapitres et réglages

locale=1036

locale_name=Français

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names\Item2]

template_name=VSO Glossy klar, bis zu 4 Episoden/Titel pro Seite

Description=Enthält ein Episoden- und Kapitelmenü mit bis zu 4 Episoden pro Seite, ein Einstellungsmenü mit bis zu 3 Audio- und 3 Untertitelsprachen pro Seite und ein Einführungsmenü mit Zugriff auf Kapitel- und Einstellungsmenü

locale=1031

locale_name=Deutsch

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names\Item3]

template_name=VSO glossy claro modelo, hasta 4 episodios/titulos por pagina

locale=1034

locale_name=Español

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names\Item4]

template_name=Modello VSO glossy, con sfondo chiaro e fino a 4 episodi / titoli per pagina

locale=1040

locale_name=Italiano

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names\Item5]

template_name=VSO 光沢テンプレート, クリアな背景でページごとに 4 つまでのエピソード/タイトル

Description=ページごとに 4 つまでのエピソードのあるエピソード/チャプタ メニュー、ページごとに 3 つまでの音声と字幕言語の設定メニュー、チャプタと設定のメニューにアクセスするイントロダクション メニューを備えています。

locale=1041

locale_name=Japanese

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names\Item6]

template_name=VSO glossy template, zwart achtergrond, max. 4 episodes/titels per pagina

Description=Bevat een episode en hoofdstuk(ken) menu met tot max. 4 episodes/titels per pagina, een instellingen menu met max. 3 spraak en 3 ondertitel-talen per pagina EN 1 introductie-menu voor toegang tot hoofdstuk(ken) en instellingen menu's

locale=1043

locale_name=Nederlands

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names\Item7]

template_name=Modelo VSO glossy, segundo plano claro, até 4 títulos por página

Description=Contém menu de Títulos para até 4 títulos por página, um menu de Configurações para até 3 áudios e 3 legendas por página e um menu Principal para acessar os menus de Títulos e Configurações

locale=1046

locale_name=Brazilian Portuguese

Thumbnail=clear\_4chapitres_modele.jpg

[CXT\localized_names]

Count=8

[CXT\TypeSettings\Item0]

Name=title

Default_style=FALSE

Share this post


Link to post
Share on other sites
ttleser

Thanks PsaltyDS.

That was exactly it. Didn't know I needed to use UniCode, never used it before.

Changed:

$FileWrite = FileOpen($DestFile, 2)

To:

$FileWrite = FileOpen($DestFile, 34)

Thanks much. :)

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.