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 VALinkKDE 24 { 25 26 private static void writeEntry(String _name, File _file) throws FileNotFoundException { 27 writeEntry(_name, _file, _name, _name); 28 } 29 30 private static void writeEntry(String _name, File _file, String shortcutName, String shortcutIconName) 31 throws FileNotFoundException  32 { 33 PrintWriter out=new PrintWriter (new FileOutputStream (_file)); 34 35 out.println("[KDE Desktop Entry]"); 36 37 out.println("Name="+shortcutName); 38 out.println("Comment="+VAGlobals.APP_NAME+" "+VAGlobals.APP_VERSION); 39 out.println("Exec="+new File  40 (VAGlobals.DEST_PATH,_name+".sh") 41 .getAbsolutePath()); 42 43 out.println("Icon="+getIcon(shortcutIconName)); 44 45 out.println("Terminal=0"); 46 out.println("Type=Application"); 47 48 out.println(""); 49 out.println("# KDE Config File"); 50 out.println("# for "+VAGlobals.APP_NAME+" "+VAGlobals.APP_VERSION); 51 out.println("# produced by VAInstall on "+new Date ()); 52 53 out.close(); 54 } 55 56 public static boolean create(String _name, Set shortcuts) throws IOException { 57 boolean r=false; 58 File tempFile, f; 59 String prefixDir; 60 61 63 prefixDir = System.getProperty("user.home")+ 64 File.separator + ".kde"+ 65 File.separator + "share"; 66 f = new File (prefixDir + File.separator + "applnk-mdk"); 67 if (!f.exists()) 68 f = new File (prefixDir + File.separator + "applnk"); 69 tempFile = new java.io.File (f, VAGlobals.LINK_SECTION_NAME); 70 if (!tempFile.exists()) { 71 if (tempFile.mkdirs()) { 72 shortcuts.add(tempFile.getAbsolutePath()); 73 f = tempFile; 74 } 75 } 76 else if(tempFile.isDirectory()) { 77 f = tempFile; 78 shortcuts.add(tempFile.getAbsolutePath()); 79 } 80 81 if(f.canWrite()) 82 { 83 f=new File (f, _name+".desktop"); 84 shortcuts.add(f.getAbsolutePath()); 86 try { writeEntry(_name, f); r=true; } 87 catch(FileNotFoundException ex) { } 88 } 89 90 92 f=new File (System.getProperty("user.home"),"Desktop"); 93 94 if(f.canWrite()) 95 { 96 f=new File (f, _name+".desktop"); 97 shortcuts.add(f.getAbsolutePath()); 99 try { writeEntry(_name, f); } 100 catch(FileNotFoundException ex) { } 101 } 102 103 return r; 104 } 105 106 public static boolean createUninstallShortcut(Set shortcuts) throws IOException { 107 boolean r=false; 108 File tempFile, f; 109 String uninstallName; 110 String prefixDir; 111 112 114 prefixDir = System.getProperty("user.home")+ 115 File.separator + ".kde"+ 116 File.separator + "share"; 117 f = new File (prefixDir + File.separator + "applnk-mdk"); 118 if (!f.exists()) 119 f = new File (prefixDir + File.separator + "applnk"); 120 tempFile = new java.io.File (f, VAGlobals.LINK_SECTION_NAME); 121 if (!tempFile.exists()) { 122 if (tempFile.mkdirs()) { 123 shortcuts.add(tempFile.getAbsolutePath()); 124 f = tempFile; 125 } 126 } 127 else if(tempFile.isDirectory()) { 128 f = tempFile; 129 shortcuts.add(tempFile.getAbsolutePath()); 130 } 131 132 134 if(f.canWrite()) 135 { 136 uninstallName = "uninstall_"+VAGlobals.APP_NAME+"_"+VAGlobals.APP_VERSION; 137 f=new File (f, uninstallName + ".desktop"); 138 shortcuts.add(f.getAbsolutePath()); 140 try { writeEntry(uninstallName,f, "Uninstall "+VAGlobals.APP_NAME, "uninstall"); r=true; } 141 catch(FileNotFoundException ex) { } 142 } 143 return r; 144 } 145 146 public static boolean createAll(Object [] _launchparams, Set shortCuts) throws IOException  147 { 148 boolean r=true; 149 if(_launchparams!=null) 150 for(int i=0;i<_launchparams.length;i++) 151 r&=create((String )((Object [])_launchparams[i])[0], shortCuts); 152 if (VAGlobals.CREATE_UNINSTALL_SHORTCUT) 153 r &= createUninstallShortcut(shortCuts); 154 return r; 155 } 156 157 public static boolean delete() throws IOException  158 { 159 boolean r=false; 160 161 File f=new File (System.getProperty("user.home")+ 162 System.getProperty("file.separator")+ 163 ".kde"+ 164 System.getProperty("file.separator")+ 165 "share"+ 166 System.getProperty("file.separator")+ 167 "applnk"); 168 169 if(f.canWrite()) 170 { 171 f=new File (f,VAGlobals.LINK_ENTRY_NAME+".desktop"); 172 if(f.exists()) { f.delete(); r=true; } 173 } 174 175 182 183 return r; 184 } 185 186 private static String getIcon(String _name) 187 { 188 File common_icon=null; 189 if( (VAGlobals.LINK_ENTRY_ICON!=null) 190 &&(VAGlobals.LINK_ENTRY_ICON.length()>0)) 191 { 192 common_icon=new File  193 (VAGlobals.DEST_PATH, 194 VAGlobals.LINK_ENTRY_ICON.replace('/',File.separatorChar)+".xpm"); 195 VAGlobals.printDebug("common_icon="+common_icon); 196 } 197 File script_icon=null; 198 if(common_icon!=null) 199 script_icon=new File (common_icon.getParentFile(),_name + ".xpm"); 200 else 201 script_icon=new File (VAGlobals.DEST_PATH,_name+".xpm"); 202 VAGlobals.printDebug("script_icon="+script_icon); 203 204 if(script_icon != null && script_icon.exists()) return script_icon.getAbsolutePath(); 205 if(common_icon != null && common_icon.exists()) return common_icon.getAbsolutePath(); 206 return null; 207 } 208 } 209
| Popular Tags
|