modifying cmd file on user machine
Posted 15 August 2008 - 19:05
I'm trying to modify a cmd file included with my installation so that it has the TARGETDIR chosen by the user written to it after OnFirstUIBefore. The last entry in the cmd file before it gets written to looks like this:
call "<insert drive letter>:\program files\Company Name\App\App.cmd"
So what I want to do is simply replace what's in the double quotes with the actual drive letter and TARGETDIR.
This seemed straightforward enough: I opened the file in Binary mode, used SeekBytes with FILE_BIN_END to position the pointer (since this is the last call in the file), and then used WriteBytes to write the actual install path into the file.
The problem is if there are characters remaining from the original call statement shown above: I don't know how to guarantee that this will be completely overwritten while allowing subsequent calls to SeekBytes to remain successful. (An example is if E:\App is chosen as the installation path. "E:\App\App.cmdletter>:\program files\Company Name\App\App.cmd" would thus show up in the cmd file.)
Maybe there's a better way, or maybe Installscript doesn't provide a good way to do it at all. Any feedback would be most welcome!
Posted 17 August 2008 - 20:06
Posted 18 August 2008 - 22:15
Posted 19 August 2008 - 14:39
However, if that's not possible, then you just need to alter you original approach to open the file normally (i.e. non-binary) and process each line of text accordingly.
Specifically, you could rename the original file, read a line, and if it doesn't contain this call statement, then write it back out to the expected filename. Continue doing that until you you find the call statement and, in that case, you would write back out the customized command.
Hope it helps.
Posted 23 August 2008 - 00:59
I treated the file as simple .txt, and this made all the difference.