1 5 6 package com.memoire.vainstall; 7 8 import java.io.File ; 9 import java.io.IOException ; 10 11 16 17 public class JNIWindowsShortcut { 18 25 public static final int CUSTOM_LOCATION = 0; 26 27 public static final int ON_DESKTOP = 1; 28 29 public static final int ON_START_MENU = 2; 30 31 32 public static final int USER_ONLY = 0; 33 34 public static final int EVERYBODY = 1; 35 36 37 public static final int SHOW_NORMAL = 0; 38 39 public static final int SHOW_MAX = 1; 40 41 public static final int SHOW_MIN = 2; 42 43 public static boolean isDllLoaded_; 44 45 public static void loadLib(){ 46 if(!isDllLoaded_){ 47 isDllLoaded_=true; 48 System.load( LIB_NAME); 49 } 50 } 51 52 53 public static String LIB_NAME = "JNIWinShortcut"; 54 private static final String DEFAULT_LINK = "LaunchIt"; 55 56 77 public static final String createShortcut(String targetname, 78 String workingdir, 79 String args, 80 int openas, 81 String linkname, 82 int location, 83 int forwhom, 84 String iconfile, 85 int iconoffset, 86 String description) 87 throws IOException { 88 loadLib(); 89 if (targetname == null) targetname = ""; 90 if (workingdir == null) workingdir = ""; 91 if (args == null) args = ""; 92 if (linkname == null || linkname.length() == 0) linkname = 93 DEFAULT_LINK; 94 if (iconfile == null) iconfile = ""; 95 if (description == null) description = ""; 96 String f=createShortcutJNI(targetname, workingdir, args, 97 openas, linkname, location, forwhom, iconfile, 98 iconoffset, description); 99 File shortcutFile = new File (f); 100 if(!shortcutFile.exists()){ 101 if(VAGlobals.DEBUG) VAGlobals.printDebug("shortcut not found "+shortcutFile.getName()); 102 String name=shortcutFile.getName(); 103 int idxDot=name.lastIndexOf('.'); 104 if(idxDot>0){ 105 name=name.substring(0,idxDot); 106 File test=new File (shortcutFile.getParentFile(),name+".pif"); 107 System.err.println("file tested "+test); 108 if(test.exists()) { 109 if(VAGlobals.DEBUG) VAGlobals.printDebug("shortcut guessed "+test.getName()); 110 111 f=test.getAbsolutePath(); 112 } 113 } 114 } 115 return f; 116 } 117 118 119 126 127 public static final String getShortcutDir(int location, 128 int forwhom) { 129 loadLib(); 130 return getLinkDir(location, forwhom); 131 } 132 133 134 141 142 public static final String getShortcutName(String linkname, 143 int location, 144 int forwhom) 145 throws IOException { 146 loadLib(); 147 if (linkname == null || linkname.length() == 0) linkname = 148 DEFAULT_LINK; 149 return getLinkName(linkname, location, forwhom); 150 } 151 152 157 158 public static final int getMaxPathlength() { 159 loadLib(); 160 return getMAX_PATH(); 161 } 162 163 164 private static final native String createShortcutJNI(String targetname, 165 String workingdir, 166 String args, 167 int openas, 168 String linkname, 169 int location, 170 int forwhom, 171 String iconfile, 172 int iconoffset, 173 String descriptions) throws IOException ; 174 175 180 private static final native String getLinkDir(int location, 181 int forwhom); 182 183 189 190 private static final native String getLinkName(String linkname, 191 int location, 192 int forwhom) throws IOException ; 193 194 198 199 private static final native int getMAX_PATH(); 200 201 } 202
| Popular Tags
|