cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
bhaskara
Level 3

FileInsertLine UTF8 changing to ANSI

Hi,
I'm working on IS11.5. I'm using FileGrep to read a file on a Japanese machine and then use FileInsertLine to replace that line with some Japanese characters.

However, the file is getting converted from UTF-8 to ANSI format.

Could anyone here help me in resolving this?

Thanks,
Bhaskar
Labels (1)
0 Kudos
(4) Replies
enanrum
Level 9

Is the file getting converted on install? This is only a guess for I have no idea what it would change the file type but if you are installing the file , you may want to check in the Files Property to see what File Type is being used. Auto detect/Ascii/binary - change to Binary!
0 Kudos
bhaskara
Level 3

Actually scenario will be similar as described below.

Along with other installation stuff, a file named abc.xml will also be copied to the INSTALLDIR and the file is in UTF-8 format will packaging.

When IS copies the file into INSTALLDIR, the format remains unaltered (UTF8).

However, according to my requirement as a post install step, I FileGrep abc.xml for a tag @@HOST@@. Then replace the @@HOST@@ with the actual hostname of the machine (where the installation is being performed). And then write the modified line SOMEHOST back into the file using FileInsertLine.

After executing this step (FileInsertLine), the file format is getting changed to ANSI. However my xml file needs to be in UTF-8 format only for my application to start.

If I run the package on English machine, it works fine. However when I run the same on a japanese machine, it is giving this unexpected behavior.

I will be thankful, if I could get some solution to this problem.

Thanks,
Bhaskar
0 Kudos
enanrum
Level 9

Ahh - yes, I've had issues trying to replace strings so I wrote my own class to do it for me and created a custom action after install and do all my string replacements. it was painful but finally got it to work!

If you want to use this by all means...

Just an FYI - I am no java guy and there may be a much easier way of doing this but this is what I've done and works well.

in ISHOME/classes/ I created a custom directory;
ISHOME/classes/custom

Copy the attached file to this directory and rename it from .txt -> .java ( was getting upload error) and compile it. I'm on Unix and IS comes with a compile_BourneShell script to do the compiling for you - not sure if Windows comes with the same thing.

In your ISHOME/classes directory you need to create another class file that will basically put the ReplaceString class file into the package.

Here's what the PutClassReplaceText.java file looks like:

import java.io.*;
import com.installshield.wizard.*;
import com.installshield.util.*;

public class PutClassReplaceText extends WizardAction
{
public void build(WizardBuilderSupport support)
{
try{
support.putClass("custom.ReplaceText");
}catch(IOException e){
}
}
}


Once this is compiled open up your UI and go into the Additional Tools -> Property Manager and Click Register Class and type in PutClassReplaceText.

Once this is complete you need to go to the Sequence view and right click anywhere in the PreInstall section - I do it right before the Welcome Dialog - and right click and add a wizard action. You should see your new action in there called 'Put Class Replace Text' select it. That adds the class to the project.

Now to use it: What I do is add a Custom Action in PostInstall section of the sequences and go into the Events add the import custom.*; to your imports select the CA in context: and On executing in the Event: add the method for the CA.

The replaceString takes 2 arguments, one is the file and the other is an array of SearchString, ReplaceString so you would have something like this:

[CODE]
public void onExecutingBlahBlah{
ReplaceText rp = new ReplaceText();
String host = arg0.resolveString("$V(HOST)");
String port = arg0.resolveString("$V(PORT)");
String infile = arg0.ResolveString("$P(fileBeanName.absoluteInstallLocation)/FileName)");

String[] SearchString = {
"@@HOST@@", host,
"@@PORT@@", port,
};

rp.ReplaceStringInFile(infile,SearchString);
}[/CODE]

Hope this helps.

Regards,
Tom
0 Kudos
bhaskara
Level 3

Hi Tom,

Thank you very much for providing this solution.

I resolved this by writing a DLL in C++ which handles the XML parsing and modification.

I have involved this DLL from the install script, and the required changes are taken care inside the DLL by accepting the required data as function arugments.

Thanking you once again for providing me your way of solution.

Regards,
Bhaskar.
0 Kudos