001: /**
002: * $RCSfile: VALinkKDE.java,v $
003: * @creation 28/03/00
004: * @modification $Date: 2005/03/30 19:42:47 $
005: * Bug-fixing and additional features by Antonio Petrelli
006: */package com.memoire.vainstall;
007:
008: import java.io.File;
009: import java.io.FileNotFoundException;
010: import java.io.FileOutputStream;
011: import java.io.IOException;
012: import java.io.PrintWriter;
013: import java.util.Date;
014: import java.util.Set;
015:
016: /**
017: * @version $Id: VALinkKDE.java,v 1.5 2005/03/30 19:42:47 deniger Exp $
018: * @author Guillaume Desnoix
019: */
020:
021: public class VALinkKDE {
022:
023: private static void writeEntry(String _name, File _file)
024: throws FileNotFoundException {
025: writeEntry(_name, _file, _name, _name);
026: }
027:
028: private static void writeEntry(String _name, File _file,
029: String shortcutName, String shortcutIconName)
030: throws FileNotFoundException {
031: PrintWriter out = new PrintWriter(new FileOutputStream(_file));
032:
033: out.println("[KDE Desktop Entry]");
034:
035: out.println("Name=" + shortcutName);
036: out.println("Comment=" + VAGlobals.APP_NAME + " "
037: + VAGlobals.APP_VERSION);
038: out.println("Exec="
039: + new File(VAGlobals.DEST_PATH, _name + ".sh")
040: .getAbsolutePath());
041:
042: out.println("Icon=" + getIcon(shortcutIconName));
043:
044: out.println("Terminal=0");
045: out.println("Type=Application");
046:
047: out.println("");
048: out.println("# KDE Config File");
049: out.println("# for " + VAGlobals.APP_NAME + " "
050: + VAGlobals.APP_VERSION);
051: out.println("# produced by VAInstall on " + new Date());
052:
053: out.close();
054: }
055:
056: public static boolean create(String _name, Set shortcuts)
057: throws IOException {
058: boolean r = false;
059: File tempFile, f;
060: String prefixDir;
061:
062: // MENU
063:
064: prefixDir = System.getProperty("user.home") + File.separator
065: + ".kde" + File.separator + "share";
066: f = new File(prefixDir + File.separator + "applnk-mdk");
067: if (!f.exists())
068: f = new File(prefixDir + File.separator + "applnk");
069: tempFile = new java.io.File(f, VAGlobals.LINK_SECTION_NAME);
070: if (!tempFile.exists()) {
071: if (tempFile.mkdirs()) {
072: shortcuts.add(tempFile.getAbsolutePath());
073: f = tempFile;
074: }
075: } else if (tempFile.isDirectory()) {
076: f = tempFile;
077: shortcuts.add(tempFile.getAbsolutePath());
078: }
079:
080: if (f.canWrite()) {
081: f = new File(f, _name + ".desktop");
082: // System.err.println(""+f);
083: shortcuts.add(f.getAbsolutePath());
084: try {
085: writeEntry(_name, f);
086: r = true;
087: } catch (FileNotFoundException ex) {
088: }
089: }
090:
091: // DESKTOP
092:
093: f = new File(System.getProperty("user.home"), "Desktop");
094:
095: if (f.canWrite()) {
096: f = new File(f, _name + ".desktop");
097: // System.err.println(""+f);
098: shortcuts.add(f.getAbsolutePath());
099: try {
100: writeEntry(_name, f);
101: } catch (FileNotFoundException ex) {
102: }
103: }
104:
105: return r;
106: }
107:
108: public static boolean createUninstallShortcut(Set shortcuts)
109: throws IOException {
110: boolean r = false;
111: File tempFile, f;
112: String uninstallName;
113: String prefixDir;
114:
115: // MENU
116:
117: prefixDir = System.getProperty("user.home") + File.separator
118: + ".kde" + File.separator + "share";
119: f = new File(prefixDir + File.separator + "applnk-mdk");
120: if (!f.exists())
121: f = new File(prefixDir + File.separator + "applnk");
122: tempFile = new java.io.File(f, VAGlobals.LINK_SECTION_NAME);
123: if (!tempFile.exists()) {
124: if (tempFile.mkdirs()) {
125: shortcuts.add(tempFile.getAbsolutePath());
126: f = tempFile;
127: }
128: } else if (tempFile.isDirectory()) {
129: f = tempFile;
130: shortcuts.add(tempFile.getAbsolutePath());
131: }
132:
133: // MENU
134:
135: if (f.canWrite()) {
136: uninstallName = "uninstall_" + VAGlobals.APP_NAME + "_"
137: + VAGlobals.APP_VERSION;
138: f = new File(f, uninstallName + ".desktop");
139: // System.err.println(""+f);
140: shortcuts.add(f.getAbsolutePath());
141: try {
142: writeEntry(uninstallName, f, "Uninstall "
143: + VAGlobals.APP_NAME, "uninstall");
144: r = true;
145: } catch (FileNotFoundException ex) {
146: }
147: }
148: return r;
149: }
150:
151: public static boolean createAll(Object[] _launchparams,
152: Set shortCuts) throws IOException {
153: boolean r = true;
154: if (_launchparams != null)
155: for (int i = 0; i < _launchparams.length; i++)
156: r &= create((String) ((Object[]) _launchparams[i])[0],
157: shortCuts);
158: if (VAGlobals.CREATE_UNINSTALL_SHORTCUT)
159: r &= createUninstallShortcut(shortCuts);
160: return r;
161: }
162:
163: public static boolean delete() throws IOException {
164: boolean r = false;
165:
166: File f = new File(System.getProperty("user.home")
167: + System.getProperty("file.separator") + ".kde"
168: + System.getProperty("file.separator") + "share"
169: + System.getProperty("file.separator") + "applnk");
170:
171: if (f.canWrite()) {
172: f = new File(f, VAGlobals.LINK_ENTRY_NAME + ".desktop");
173: if (f.exists()) {
174: f.delete();
175: r = true;
176: }
177: }
178:
179: /* f=new File(System.getProperty("user.home"),"Desktop");
180:
181: if(f.canWrite())
182: {
183: f=new File(f,VAGlobals.LINK_ENTRY_NAME+".desktop");
184: if(f.exists()) { f.delete(); r=true; }
185: }*/
186:
187: return r;
188: }
189:
190: private static String getIcon(String _name) {
191: File common_icon = null;
192: if ((VAGlobals.LINK_ENTRY_ICON != null)
193: && (VAGlobals.LINK_ENTRY_ICON.length() > 0)) {
194: common_icon = new File(VAGlobals.DEST_PATH,
195: VAGlobals.LINK_ENTRY_ICON.replace('/',
196: File.separatorChar)
197: + ".xpm");
198: VAGlobals.printDebug("common_icon=" + common_icon);
199: }
200: File script_icon = null;
201: if (common_icon != null)
202: script_icon = new File(common_icon.getParentFile(), _name
203: + ".xpm");
204: else
205: script_icon = new File(VAGlobals.DEST_PATH, _name + ".xpm");
206: VAGlobals.printDebug("script_icon=" + script_icon);
207:
208: if (script_icon != null && script_icon.exists())
209: return script_icon.getAbsolutePath();
210: if (common_icon != null && common_icon.exists())
211: return common_icon.getAbsolutePath();
212: return null;
213: }
214: }
|