wilmens™

by William W. Mensah

An even better solution….

  • Saturday Sep 27,2008 11:52 AM
  • By wmensah
  • In myDiary

So in my last blog the solution was to write a python script to perform the search and replace on the gtk_basepaths in the 2 files and then have a batch file call python and pass the script to it. That is great, but only as long as the user already has python installed on the computer. If not, then that could be a problem because there will be no way to execute the python script. And you don’t really want to ask the user to please go and download python before you run the installer because it depends on python…that’s kind of silly.

Ok so here’s the better solution:

Since the user is supposed to be running Windows, the system on which the installer is going to be run on should be able to execute .vbs files (visual basic script) via command prompt (ah, something we already have :) ). So if you write the search and replace algorithm in vbs you can execute this script with the batch file and the world will be safe.

The algorithm for such a visual basic script can be found here:

Here’s the script:


Const ForReading = 1
Const ForWriting = 2

strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)

Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close

?

For a better understanding of how the script works, read the explanation provided at the link above. In my case I had to change a few things within the script to get it to work the way I wanted but I’ll come back to that later.?

Ok, so the script can be executed like so:

cscript replace.vbs "C:\Scripts\Text.txt" "Jim " "James "

where replace.vbs is the name of the script, C:\Scripts\Text.txt is the file which contains the text to be replaced, “Jim” is the text to find and “James” is the replacement.?

Since I wanted to replace <gtk_basepath> with the value of the GTK_BASEPATH environment variable and then change C:\GTK to C:\\GTK for instance (assuming C:\GTK is the value of the environment variable) I changed the line:

strNewText = Wscript.Arguments(2)

to read:

strNewText = Replace(Wscript.Arguments(2), "\", "\\")

and then from the batch file I called the vb script like so:

start replace.vbs <file_to_replace> %GTK_BASEPATH%

note: in command prompt, %GTK_BASEPATH% returns the value of the environment variable.

that did the trick.

GTK_BASEPATH continued…

  • Tuesday Sep 23,2008 09:45 PM
  • By wmensah
  • In myDiary

So a sweeter approach will be to replace the path to GTK in every file for which this path has been hardcoded (pango.modules and gdk-pixbuf.loaders, in my case) with the GTK_BASEPATH environment variable. How to do this?……simply write a python script to perform a search and replace on whatever the current GTK path in the file is and replace it with the value of GTK_BASEPATH. I haven’t actually tried it but when I do I’ll submit a post stating whether I was successful or not.

The python OS module allows us to determine which operating system the user is currently running so that might be of some help.

GTK for Windows XP/Vista BASEPATH

  • Monday Sep 22,2008 02:30 AM
  • By wmensah
  • In myDiary

Ok, something really weird is going on. Maybe I’m dumb but someone has to explain this to me (so i can quit being dumb). I tried installing GTK 2 Runtime Environment on 2 different operating systems: Windows Vista and XP and got 2 different results which I thought was very strange.

First of all, when installing on XP, the default path was: C:\Program Files\Common Files – what is wrong with that? Nothing – nothing at all but why is it that running the same installer on Vista defaults to C:\GTK? and what happened to that 2.0 directory inside it? That’s some major inconsistency if you’d ask me. Maybe it’s because of how my environment variables are set up.

In XP, the GTK_BASEPATH =?C:\PROGRA~1\COMMON~1\GTK

In Vista, the GTK_BASEPATH = C:\GTK

default value for the environmental variable ‘GTK_BASEPATH’ in Vista 64 bit was set to ‘C:\PROGRA~2\COMMON~1\GTK\2.0′.

I just found a blog via Google search addressing the same issue.

http://dreblen.wordpress.com/2008/08/06/adding-gtk-to-the-windows-path/

and another relevant forum

http://gobby.0×539.de/trac/ticket/292

I still don’t get why there’s a directory ‘C:\GTK\2.0′ in XP but not in the GTK directory in Vista. I’ll try to figure it out later. For now I have created a batch file which kind of fixes the issue:

IF EXIST C:\GTK\2.0 XCOPY C:\GTK\2.0 C:\GTK\ /E /Y

RMDIR C:\GTK\2.0\ /s /q

which simply moves the contents of C:\GTK\2.0 to C:\GTK and removes C:\GTK\2.0

I guess this will do for now till I figure out an alternative method. I know one could be creating a batch file to set the correct GTK_BASEPATH value based on which version of Windows is being run. But that’s just a thought.