|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.izforge.izpack.util.os.ShellLink
This class represents a MS-Windows shell link, aka shortcut. It
supports creation, modification and deletion as well as reporting on
details of shell links. This class uses a number of native methods to
access the MS-Windows registry and load save and manipulate link data.
The native code is contained in the file ShellLink.cpp
.
For more detailed information on Windows shortcuts read the win32
documentation from Microsoft on the IShellLink interface. There are
also useful articles on this topic on the MIcrosoft website.
Using Shell Links in Windows 95
The IShellLink Interface
IShellLink
Field Summary | |
static int |
ALL_USERS
the constant to use for selecting the all users. |
private java.lang.String |
allUsersLinkPath
Path to the location where links for all users are stored. |
private java.lang.String |
arguments
|
static int |
CURRENT_USER
the constant to use for selecting the current user. |
private java.lang.String |
currentUserLinkPath
Path to the location where links for the current user are stored. |
private java.lang.String |
description
|
static int |
DESKTOP
This type of shortcut shows on the desktop |
private java.lang.String |
dummyString
there seems to be an error in JNI that causes an access violation if a String that is accessed from native code borders on another type of variable. |
private java.lang.String |
groupName
|
static int |
HIDE
Hide the window when starting. |
private int |
hotkey
|
private int |
iconIndex
|
private java.lang.String |
iconPath
|
private boolean |
initializeSucceeded
|
private static java.lang.String |
LINK_EXTENSION
the extension that must be used for link files |
private java.lang.String |
linkDirectory
Contains the directory where the link file is stored after any save operation that needs to create that directory. |
private java.lang.String |
linkFileName
this is the fully qualified name of the link on disk. |
private java.lang.String |
linkName
|
private int |
linkType
|
private static int |
MAX_SHOW
|
private static int |
MAX_TYPE
|
static int |
MAXIMIZED
Show the window maximized when starting. |
private static int |
MIN_SHOW
|
private static int |
MIN_TYPE
|
static int |
MINIMIZED
Show the window minimized when starting. |
private int |
nativeHandle
This handle links us to a specific native instance. |
static int |
NORMAL
Show the window 'normal' when starting. |
static int |
PROGRAM_MENU
This type of shortcut shows in the program menu |
private int |
showCommand
|
private static int |
SL_ERROR
Unspecific return if a native call was not successful |
private static int |
SL_INITIALIZED
Return value from native initialization functions if already initialized |
private static int |
SL_NO_IPERSIST
Return value from native uninitialization functions if nohandle for the IPersist interface could be obtained |
private static int |
SL_NO_SAVE
Return value from native uninitialization functions if the save operation fort the link failed |
private static int |
SL_NOT_INITIALIZED
Return value from native uninitialization functions if never initialized |
private static int |
SL_OK
Returned from native calls if the call was successful |
private static int |
SL_OUT_OF_HANDLES
Return value from native uninitialization functions if there are no more interface handles available |
private static int |
SL_WRONG_DATA_TYPE
Return value if the function called had to deal with unexpected data types. |
static int |
START_MENU
This type of shortcut shows in the start menu |
static int |
STARTUP
This type of shortcut is executed at OS launch time |
private java.lang.String |
targetPath
|
private static int |
UNINITIALIZED
|
private int |
userType
|
private java.lang.String |
workingDirectory
|
Constructor Summary | |
ShellLink(int type,
int userType,
java.lang.String group,
java.lang.String name)
Creates an instance of ShellLink from an existing shell link
on disk. |
|
ShellLink(int type,
java.lang.String name)
Creates an instance of ShellLink of a specific type. |
|
ShellLink(java.lang.String name,
int userType)
Creates an instance of ShellLink from an existing shell link
on disk. |
Method Summary | |
protected void |
finalize()
Destructor, releases COM and frees native resources. |
void |
freeLibrary(java.lang.String name)
This method is used to free the library at the end of progam execution. |
private void |
FreeLibrary(java.lang.String name)
This method is used to free the library at the end of progam execution. |
private java.lang.String |
fullLinkName(int userType)
Constructs and returns the fully qualified name for the link file. |
private java.lang.String |
fullLinkPath(int userType)
Constructs and returns the full path for the link file. |
private void |
get()
Gets all members from the native side. |
java.lang.String |
getArguments()
Returns the command line that the link passes to the target. |
private int |
GetArguments()
|
java.lang.String |
getDescription()
Returns the description for the link. |
private int |
GetDescription()
|
java.lang.String |
getDirectoryCreated()
Returns the path of the directory where the link file is stored, if it was necessary during the previous save operation to create the directory. |
java.lang.String |
getFileName()
Returns the fully qualified file name under which the link is saved on disk. |
int |
getHotkey()
Retruns the hotkey that can be used to activate the link. |
private int |
GetHotkey()
|
int |
getIconIndex()
Returns the index of the icon with the icon or resource file |
java.lang.String |
getIconLocation()
Returns the path and file name of the file that contains the icon that is associated with the link. |
private int |
GetIconLocation()
|
private int |
getInterface()
|
java.lang.String |
getLinkName()
Returns the name shown in a menu or on the desktop for the link. |
java.lang.String |
getLinkPath(int userType)
Returns the path where the links of the selected type are stroed. |
private int |
GetLinkPath(int target)
|
private int |
GetPath()
|
int |
getShowCommand()
Returns the initial condition of the target window (HIDE, NORMAL, MINIMIZED, MAXIMIZED). |
private int |
GetShowCommand()
|
java.lang.String |
getTargetPath()
Retruns the absolute path of the link target |
java.lang.String |
getWorkingDirectory()
Retruns the working deirectory for the link target. |
private int |
GetWorkingDirectory()
|
private void |
initialize()
Initializes COM and gets an instance of the IShellLink interface. |
private int |
initializeCOM()
|
private int |
loadLink(java.lang.String name)
|
private int |
releaseCOM()
|
private int |
releaseInterface()
|
private int |
Resolve()
|
void |
save()
Saves this link. |
void |
save(java.lang.String name)
Saves this link to any desired location. |
private int |
saveLink(java.lang.String name)
|
private void |
set()
Sets all members on the native side. |
private int |
SetArguments()
|
void |
setArguments(java.lang.String arguments)
Sets the command line arguments that will be passed to the target when the link is activated. |
private int |
SetDescription()
|
void |
setDescription(java.lang.String description)
Sets the description string that is used to identify the link in a menu or on the desktop. |
private int |
SetHotkey()
|
void |
setHotkey(int hotkey)
Sets the hotkey that can be used to activate the link. |
private int |
SetIconLocation()
|
void |
setIconLocation(java.lang.String path,
int index)
Sets the location of the icon that is shown for the shortcut on the desktop. |
void |
setLinkName(java.lang.String name)
Sets the name shown in a menu or on the desktop for the link. |
void |
setLinkType(int type)
Sets the type of link |
private int |
SetPath()
|
void |
setProgramGroup(java.lang.String groupName)
Sets the name of the program group this ShellLinbk should be placed in. |
private int |
SetShowCommand()
|
void |
setShowCommand(int show)
Sets the show command that is passed to the target application when the link is activated. |
void |
setTargetPath(java.lang.String path)
Sets the absolute path to the shortcut target. |
void |
setUserType(int type)
Sets the user type for link |
private int |
SetWorkingDirectory()
|
void |
setWorkingDirectory(java.lang.String dir)
Sets the working directory for the link target. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int HIDE
public static final int NORMAL
public static final int MINIMIZED
public static final int MAXIMIZED
private static final int MIN_SHOW
private static final int MAX_SHOW
public static final int DESKTOP
public static final int PROGRAM_MENU
public static final int START_MENU
public static final int STARTUP
private static final int MIN_TYPE
private static final int MAX_TYPE
private static final int SL_OK
private static final int SL_ERROR
private static final int SL_INITIALIZED
private static final int SL_NOT_INITIALIZED
private static final int SL_OUT_OF_HANDLES
private static final int SL_NO_IPERSIST
private static final int SL_NO_SAVE
private static final int SL_WRONG_DATA_TYPE
private static final int UNINITIALIZED
private static final java.lang.String LINK_EXTENSION
public static final int CURRENT_USER
public static final int ALL_USERS
private int nativeHandle
private java.lang.String currentUserLinkPath
private java.lang.String allUsersLinkPath
private java.lang.String groupName
private java.lang.String linkName
private java.lang.String linkFileName
private java.lang.String linkDirectory
null
.
private java.lang.String arguments
private java.lang.String description
private java.lang.String iconPath
private java.lang.String targetPath
private java.lang.String workingDirectory
private java.lang.String dummyString
set()
For this reason,
the dummy string is placed here. Observed with version: java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C) Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
private int hotkey
private int iconIndex
private int showCommand
private int linkType
private int userType
private boolean initializeSucceeded
Constructor Detail |
public ShellLink(int type, java.lang.String name) throws java.lang.Exception, java.lang.IllegalArgumentException
ShellLink
of a specific type.
type
- The type of link desired. The following values can be set:DESKTOP
PROGRAM_MENU
START_MENU
STARTUP
name
- The name that the link should display on a menu or on
the desktop. Do not include a file extension.
java.lang.IllegalArgumentException
- if any of the call parameters are
incorrect
java.lang.Exception
- if problems are encountered in initializing the
native interfacepublic ShellLink(java.lang.String name, int userType) throws java.lang.Exception, java.lang.IllegalArgumentException
ShellLink
from an existing shell link
on disk.
name
- the fully qualified file name of the link.userType
- the type of user for the link path.
java.lang.IllegalArgumentException
- if the name was null
java.lang.Exception
- if problems are encountered in reading the fileCURRENT_USER
,
ALL_USERS
public ShellLink(int type, int userType, java.lang.String group, java.lang.String name) throws java.lang.Exception, java.lang.IllegalArgumentException
ShellLink
from an existing shell link
on disk.
type
- The type of link, one of the following values: DESKTOP
PROGRAM_MENU
START_MENU
STARTUP
userType
- the type of user for the link path.group
- The program group this link is a part of. If the
link is not part of a program group, pass an empty
string or null for this parameter.name
- The file name of this link. Do not include a file
extension.
java.lang.IllegalArgumentException
- if any of the call parameters are
incorrect
java.lang.Exception
- if problems are encountered in initializing the
native interfaceCURRENT_USER
,
ALL_USERS
Method Detail |
private int initializeCOM()
private int releaseCOM()
private int getInterface()
private int releaseInterface()
private int GetArguments()
private int GetDescription()
private int GetHotkey()
private int GetIconLocation()
private int GetPath()
private int GetShowCommand()
private int GetWorkingDirectory()
private int Resolve()
private int SetArguments()
private int SetDescription()
private int SetHotkey()
private int SetIconLocation()
private int SetPath()
private int SetShowCommand()
private int SetWorkingDirectory()
private int saveLink(java.lang.String name)
private int loadLink(java.lang.String name)
private int GetLinkPath(int target)
private void FreeLibrary(java.lang.String name)
private void initialize() throws java.lang.Exception
java.lang.Exception
- if problems are encounteredprotected void finalize()
public void freeLibrary(java.lang.String name)
freeLibrary
in interface NativeLibraryClient
name
- the name of the library to free. Use only the name and
extension but not the path.NativeLibraryClient.freeLibrary(java.lang.String)
private java.lang.String fullLinkPath(int userType)
userType
- the type of user for the link path.
CURRENT_USER
,
ALL_USERS
private java.lang.String fullLinkName(int userType)
userType
- the type of user for the link path.
CURRENT_USER
,
ALL_USERS
private void set() throws java.lang.Exception
java.lang.Exception
- if any problem is encountered during this operation.private void get() throws java.lang.Exception
java.lang.Exception
- if any problem is encountered during this operation.public void setProgramGroup(java.lang.String groupName)
groupName
- the name of the program grouppublic void setArguments(java.lang.String arguments)
arguments
- the command line argumentsgetArguments()
public void setDescription(java.lang.String description)
description
- the descriptiojn stringgetDescription()
public void setHotkey(int hotkey)
hotkey
- a valid Windows virtual key code. Modifiers (e.g. for
alt or shift key) are added in the upper byte. Note
that only the lower 16 bits for tis parameter are used.getHotkey()
public void setIconLocation(java.lang.String path, int index)
path
- a fully qualified file name of a file that contains
the icon.index
- the index of the specific icon to use in the file.
If there is only one icon in the file, use an index
of 0.getIconLocation()
public void setTargetPath(java.lang.String path)
path
- the fully qualified file name of the targetgetTargetPath()
public void setShowCommand(int show)
HIDE
will cause the target window not to show at
all. There is not even a button on the taskbar. This is a very useful
setting when batch files are used to launch a Java application as it
will then appear to run just like any native Windows application.
show
- the show command. Valid settings are: HIDE
NORMAL
MINIMIZED
MAXIMIZED
getShowCommand()
public void setWorkingDirectory(java.lang.String dir)
dir
- the working directorygetWorkingDirectory()
public void setLinkName(java.lang.String name)
name
- The name that the link should display on a menu or on
the desktop. Do not include a file extension.public void setLinkType(int type) throws java.lang.IllegalArgumentException
type
- The type of link desired. The following values can be set:java.lang.IllegalArgumentException
- if an an invalid type is passedpublic void setUserType(int type) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if an an invalid type is passedCURRENT_USER
,
ALL_USERS
public java.lang.String getLinkPath(int userType)
userType
- the type of user for the link path.
CURRENT_USER
,
ALL_USERS
public java.lang.String getArguments()
setArguments(java.lang.String)
public java.lang.String getDescription()
setDescription(java.lang.String)
public int getHotkey()
setHotkey(int)
public java.lang.String getIconLocation()
setIconLocation(java.lang.String, int)
public int getIconIndex()
setIconLocation(java.lang.String, int)
public java.lang.String getTargetPath()
setTargetPath(java.lang.String)
public int getShowCommand()
setShowCommand(int)
public java.lang.String getWorkingDirectory()
setWorkingDirectory(java.lang.String)
public java.lang.String getFileName()
public java.lang.String getDirectoryCreated()
null
if no save operation was carried
out or there was no need to create a directory during the previous save
operation.
null
if no save operation was carried out or
there was no need to create a directory during the previous
save operation.public java.lang.String getLinkName()
public void save() throws java.lang.Exception
java.lang.Exception
- if problems are encounteredpublic void save(java.lang.String name) throws java.lang.Exception
name
- the fully qualified file name for the link
java.lang.IllegalArgumentException
- if the parameter was null
java.lang.Exception
- if the save operation could not be carried out
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |