[vwnc] absolute location of image file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] absolute location of image file?

Rob Vens-2
I am looking for a way to determine in a platform-independent way (but of course resulting in platform-dependent strings) the location of the VisualWorks image.
As it is, for example "ObjectMemory imageDirectory" does not give me the directory of the image in my application on Windows but the folder in which it was installed, which is the parent directory:

Program Files
  MijnGeld
    system
      mijngeld.exe

gives me c:\Program Files\MijnGeld.
"Filename defaultClass currentDirectory" is of course even more unreliable, because this depends on whatever shortcut was used to start the application.
On Mac OS X the imageDirectory correctly yields the folder of the image, even if it is inside the "hidden" resources folder in the application folder.
Are there any options to find out "where I am" on all platforms, wherever the user fancies to install my stuff?


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] absolute location of image file?

Alan Knight-2
You should probably look at the implementation of ObjectMemory imageDirectory, which just calls imageFilename, truncates it, and makes it absolute if it wasn't. It might be that imageFilename is in fact relative (though it typically isn't) in which case your only real option is to resolve it relative to currentDirectory. That won't work if currentDirectory has actually changed, but shouldn't matter how the image was started.

At 12:34 PM 5/5/2008, Rob Vens wrote:
I am looking for a way to determine in a platform-independent way (but of course resulting in platform-dependent strings) the location of the VisualWorks image.
As it is, for example "ObjectMemory imageDirectory" does not give me the directory of the image in my application on Windows but the folder in which it was installed, which is the parent directory:

Program Files
  MijnGeld
    system
      mijngeld.exe

gives me c:\Program Files\MijnGeld.
"Filename defaultClass currentDirectory" is of course even more unreliable, because this depends on whatever shortcut was used to start the application.
On Mac OS X the imageDirectory correctly yields the folder of the image, even if it is inside the "hidden" resources folder in the application folder.
Are there any options to find out "where I am" on all platforms, wherever the user fancies to install my stuff?

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

--
Alan Knight [|], Engineering Manager, Cincom Smalltalk

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] absolute location of image file?

Mark Pirogovsky-3
In reply to this post by Rob Vens-2
There are few things you can do:

One of them uses the CEnvironment, so it should be more or less platform
independent.  The code was written about 10 years ago and it looks ugly,
but works:
===============
getExeFromCmdLn
     | exeExt file |
     exeExt := '.exe'.    " PC only for now "
     file := CEnvironment commandLine detect:
                     [:str |
                     str size > exeExt size
                         and: [exeExt match: (str copyFrom: str size -
exeExt size + 1 to: str size)]]
                 ifNone: [CEnvironment commandLine first].
     "file = CEnvironment commandLine first ifFalse:[self error:'cannot
determine executable on the command line']."
     ^file
===============
for non PC just use "CEnvironment commandLine first"


==============
getImageFromCmdLn
     | imageExtension image |
     imageExtension := Filename imageExtension.
     image := CEnvironment commandLine detect:
                     [:str |
                     str size > imageExtension size and:
                             [(str copyFrom: str size - imageExtension
size + 1 to: str size)
                                 = imageExtension]]
                 ifNone: [nil].
     ^image
====================


In Win32 environment one can use the call to  The GetModuleFileName
function which retrieves the fully-qualified path for the file that
contains the specified module that the current process owns.
The handle Handle to the module whose path is being requested. If this
parameter is NULL, GetModuleFileName retrieves the path of the
executable file of the current process. As in the

| xif shortPath resultLength longName |
     ^
     [xif := Win32SystemSupport new.
     shortPath := xif LPTSTR gcMalloc: 2048.
     resultLength := xif
                 GetModuleFileName: aHandle
                 into: shortPath
                 inBufferSized: 2048.
     longName := shortPath copyCStringFromHeap.
     resultLength = 0 ifTrue: [nil] ifFalse: [longName]]
             on: Error
             do: [:ex | ex returnWith: nil]

GetModuleFileName: hModule into: lpFilename inBufferSized: nSize
     <C: DWORD _wincall GetModuleFileNameA(
           HMODULE hModule,
          LPTSTR lpFilename,
           DWORD nSize)>
     ^self externalAccessFailedWith: _errorCode



Rob Vens wrote:

> I am looking for a way to determine in a platform-independent way (but
> of course resulting in platform-dependent strings) the location of the
> VisualWorks image.
> As it is, for example "ObjectMemory imageDirectory" does not give me the
> directory of the image in my application on Windows but the folder in
> which it was installed, which is the parent directory:
>
> Program Files
>   MijnGeld
>     system
>       mijngeld.exe
>
> gives me c:\Program Files\MijnGeld.
> "Filename defaultClass currentDirectory" is of course even more
> unreliable, because this depends on whatever shortcut was used to start
> the application.
> On Mac OS X the imageDirectory correctly yields the folder of the image,
> even if it is inside the "hidden" resources folder in the application
> folder.
> Are there any options to find out "where I am" on all platforms,
> wherever the user fancies to install my stuff?
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc