1 7 8 package com.memoire.vainstall; 9 10 import java.io.File ; 11 import java.io.FileNotFoundException ; 12 import java.io.FileOutputStream ; 13 import java.io.IOException ; 14 import java.io.PrintWriter ; 15 import java.util.Date ; 16 import java.util.Set ; 17 18 22 23 public class VALinkGnome 24 { 25 private static String getIcon(String _name) 26 { 27 File common_icon=null; 28 if( (VAGlobals.LINK_ENTRY_ICON!=null) 29 &&(VAGlobals.LINK_ENTRY_ICON.length()>0)) 30 { 31 common_icon=new File 32 (VAGlobals.DEST_PATH, 33 VAGlobals.LINK_ENTRY_ICON.replace('/',File.separatorChar)+".png"); 34 VAGlobals.printDebug("common_icon="+common_icon); 35 } 36 File script_icon=null; 37 if(common_icon!=null) 38 script_icon=new File (common_icon.getParentFile(),_name + ".png"); 39 else 40 script_icon=new File (VAGlobals.DEST_PATH,_name+".png"); 41 VAGlobals.printDebug("script_icon="+script_icon); 42 43 if(script_icon.exists()) return script_icon.getAbsolutePath(); 44 if(common_icon.exists()) return common_icon.getAbsolutePath(); 45 return null; 46 } 47 48 private static void writeEntry(String _name, File _file) throws FileNotFoundException { 49 writeEntry(_name, _file, _name, _name); 50 } 51 52 private static void writeEntry(String _name, File _file, String shortcutName, String shortcutIconName) 53 throws FileNotFoundException 54 { 55 PrintWriter out=new PrintWriter (new FileOutputStream (_file)); 56 57 out.println("[Desktop Entry]"); 58 59 out.println("Name="+ shortcutName); 60 out.println("Comment="+VAGlobals.APP_NAME+" "+VAGlobals.APP_VERSION); 61 out.println("Exec="+new File 62 (VAGlobals.DEST_PATH,_name+".sh") 63 .getAbsolutePath()); 64 65 out.println("Icon="+getIcon(shortcutIconName)); 66 out.println("Terminal=0"); 67 out.println("Type=Application"); 68 out.println("Categories=Application;"); 69 70 out.println(""); 71 out.println("# Gnome Config File"); 72 out.println("# for "+_name+" ("+ 73 VAGlobals.APP_NAME+" "+VAGlobals.APP_VERSION+")"); 74 out.println("# produced by VAInstall on "+new Date ()); 75 76 out.flush(); 77 out.close(); 78 79 _file.setLastModified(System.currentTimeMillis()+5000l); 81 } 82 83 public static boolean delete(String _name) throws IOException 84 { 85 boolean r=false; 86 87 File f=new File (System.getProperty("user.home")+ 88 System.getProperty("file.separator")+ 89 ".gnome"+ 90 System.getProperty("file.separator")+ 91 "apps"); 92 93 if(f.canWrite()) 94 { 95 f=new File (f,_name+".desktop"); 96 if(f.exists()) { f.delete(); r=true; } 97 } 98 99 f=new File (System.getProperty("user.home")+ 100 System.getProperty("file.separator")+ 101 ".gnome-desktop"); 102 103 if(f.canWrite()) 104 { 105 f=new File (f,_name+".desktop"); 106 if(f.exists()) { f.delete(); } 107 } 108 109 return r; 110 } 111 112 public static boolean create(String _name, Set shortcuts) throws IOException { 113 return create(_name, shortcuts, System.getProperty("user.home")+ 114 File.separator + ".gnome"+ 115 File.separator + "apps"+ 116 File.separator, true); 117 } 118 119 public static boolean create(String _name, Set shortcuts, String shortcutDir, 120 boolean appendAppDirName) throws IOException { 121 boolean r=false; 122 File tempFile; 123 124 126 File f=new File (shortcutDir); 127 if (appendAppDirName) 128 tempFile = new java.io.File (f, VAGlobals.LINK_SECTION_NAME); 129 else 130 tempFile = f; 131 if (!tempFile.exists()) { 132 if (tempFile.mkdirs()) { 133 shortcuts.add(tempFile.getAbsolutePath()); 134 f = tempFile; 135 } 136 } 137 else if(tempFile.isDirectory()) { 138 f = tempFile; 139 shortcuts.add(tempFile.getAbsolutePath()); 140 } 141 142 144 if(f.canWrite()) 145 { 146 f=new File (f,_name+".desktop"); 147 shortcuts.add(f.getAbsolutePath()); 149 try { writeEntry(_name,f); r=true; } 150 catch(FileNotFoundException ex) { } 151 } 152 153 155 f=new File (System.getProperty("user.home")+ 156 File.separator + ".gnome-desktop"); 157 158 if(f.canWrite()) 159 { 160 f=new File (f,_name+".desktop"); 161 shortcuts.add(f.getAbsolutePath()); 162 try { writeEntry(_name,f); } 164 catch(FileNotFoundException ex) { } 165 } 166 167 return r; 168 } 169 170 public static boolean createUninstallShortcut(Set shortcuts) throws IOException { 171 return createUninstallShortcut(shortcuts, 172 System.getProperty("user.home")+ 173 File.separator + ".gnome"+ 174 File.separator + "apps"+ 175 File.separator, true); 176 } 177 178 public static boolean createUninstallShortcut(Set shortcuts, String shortcutDir, 179 boolean appendAppDirName) throws IOException { 180 boolean r=false; 181 File tempFile; 182 String uninstallName; 183 184 186 File f=new File (shortcutDir); 187 if (appendAppDirName) 188 tempFile = new java.io.File (f, VAGlobals.LINK_SECTION_NAME); 189 else 190 tempFile = f; 191 if (!tempFile.exists()) { 192 if (tempFile.mkdirs()) { 193 shortcuts.add(tempFile.getAbsolutePath()); 194 f = tempFile; 195 } 196 } 197 else if(tempFile.isDirectory()) { 198 f = tempFile; 199 shortcuts.add(tempFile.getAbsolutePath()); 200 } 201 202 204 if(f.canWrite()) 205 { 206 uninstallName = "uninstall_"+VAGlobals.APP_NAME+"_"+VAGlobals.APP_VERSION; 207 f=new File (f, uninstallName + ".desktop"); 208 shortcuts.add(f.getAbsolutePath()); 210 try { writeEntry(uninstallName,f, "Uninstall "+VAGlobals.APP_NAME, "uninstall"); r=true; } 211 catch(FileNotFoundException ex) { } 212 } 213 return r; 214 } 215 216 public static boolean createAll(Object [] _launchparams, Set shortCuts) throws IOException 217 { 218 boolean r=true; 219 String gnome2dir; 220 221 gnome2dir = System.getProperty("user.home")+ File.separator + ".gnome2"+ 222 File.separator + "vfolders"+File.separator + "applications" + File.separator; 223 if(_launchparams!=null) 224 for(int i=0;i<_launchparams.length;i++) { 225 r&=create((String )((Object [])_launchparams[i])[0], shortCuts); 226 r &= create((String )((Object [])_launchparams[i])[0], shortCuts, 227 gnome2dir, false); 228 } 229 if (VAGlobals.CREATE_UNINSTALL_SHORTCUT) { 230 r &= createUninstallShortcut(shortCuts); 231 r &= createUninstallShortcut(shortCuts, gnome2dir, false); 232 } 233 return r; 234 } 235 } 236 | Popular Tags |