Source Code Cross Referenced for VALinkWindows.java in  » Installer » VAInstall » com » memoire » vainstall » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Installer » VAInstall » com.memoire.vainstall 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $RCSfile: VALinkWindows.java,v $
003:         * @creation     12/03/00
004:         * @modification $Date: 2005/03/07 20:52:02 $
005:         */package com.memoire.vainstall;
006:
007:        import java.io.File;
008:        import java.io.FileInputStream;
009:        import java.io.FileOutputStream;
010:        import java.io.IOException;
011:        import java.util.HashSet;
012:        import java.util.Iterator;
013:        import java.util.Set;
014:
015:        /**
016:         * @version $Id: VALinkWindows.java,v 1.8 2005/03/07 20:52:02 deniger Exp $
017:         * @author Axel von Arnim
018:         */
019:        public class VALinkWindows {
020:
021:            public static boolean move(File _from, File _to) throws IOException {
022:                if (_from == null || !_from.exists())
023:                    return false;
024:                boolean b = _from.renameTo(_to);
025:                if (b)
026:                    return true;
027:                copy(_from, _to);
028:                return _from.delete();
029:            }
030:
031:            public static void copy(File _from, File _to) throws IOException {
032:                if (_from == null || !_from.exists())
033:                    return;
034:                FileOutputStream out = null;
035:                FileInputStream in = null;
036:                try {
037:                    out = new FileOutputStream(_to);
038:                    in = new FileInputStream(_from);
039:                    byte[] buf = new byte[2048];
040:                    int read = in.read(buf);
041:                    while (read > 0) {
042:                        out.write(buf, 0, read);
043:                        read = in.read(buf);
044:                    }
045:                } catch (IOException _e) {
046:                    throw _e;
047:                } finally {
048:                    if (in != null)
049:                        in.close();
050:                    if (out != null)
051:                        out.close();
052:                }
053:            }
054:
055:            /**
056:             * Create one Windows shortcut for each javalauncher script that was
057:             * created.
058:             * <p>
059:             * Links will be named after the corresponding launch scripts.
060:             * <p>
061:             * Icons can be used. If in the install dir an icon file (suffix .ico)
062:             * exists that matches the name of the launcher, it will be used as the icon
063:             * for that launcher. Alternatively, if an icon file exists in the install
064:             * dir that matches LINK_ENTRY_ICON, that icon file will be used. Otherwise,
065:             * no icon is used.
066:             * 
067:             * @see com.memoire.vainstall.VASetup
068:             */
069:            public static boolean create(VAShortcutEntry[] _launchparms,
070:                    File sharedDir, String _installClassName, Set shortcuts)
071:                    throws IOException {
072:                try {
073:                    String linkname, iconfile;
074:
075:                    if (_launchparms == null)
076:                        return false;
077:                    String section = null;
078:                    if ((!"applications".equals(VAGlobals.LINK_SECTION_NAME
079:                            .toLowerCase()))
080:                            && (!"utilities".equals(VAGlobals.LINK_SECTION_NAME
081:                                    .toLowerCase()))
082:                            && (!"programs".equals(VAGlobals.LINK_SECTION_NAME
083:                                    .toLowerCase())))
084:                        section = VAGlobals.LINK_SECTION_NAME;
085:                    if (section == null
086:                            && (_launchparms.length > 1 || _launchparms.length == 1
087:                                    && VAGlobals.CREATE_UNINSTALL_SHORTCUT)) {
088:                        section = VAGlobals.APP_NAME;
089:                    }
090:                    String menulinkdir = null;
091:                    Set shortcutToCreate = new HashSet();
092:                    if (section != null) {
093:                        menulinkdir = JNIWindowsShortcut.getShortcutDir(
094:                                JNIWindowsShortcut.ON_START_MENU,
095:                                JNIWindowsShortcut.EVERYBODY)
096:                                + "\\" + section;
097:                        File mld = new File(menulinkdir);
098:                        if (!mld.exists()) {
099:                            if (!mld.mkdirs()) {
100:                                throw new IOException("unable to create "
101:                                        + menulinkdir);
102:                            }
103:                        } else {
104:                            //add the new folder to the shortcut lists ->delete when
105:                            // uninstall
106:                            shortcuts.add(mld.getAbsolutePath());
107:                        }
108:                        if (VAGlobals.DEBUG)
109:                            VAGlobals
110:                                    .printDebug("menu link dir=" + menulinkdir);
111:
112:                    }
113:                    for (int i = 0; i < _launchparms.length; i++) {
114:                        VAShortcutEntry parmset = _launchparms[i];
115:                        if (parmset.getIconPath() == null) {
116:                            if (parmset.isUninstall()) {
117:                                iconfile = getWindowsIconFile("uninstall",
118:                                        false);
119:                            } else
120:                                iconfile = getWindowsIconFile(
121:                                        parmset.getName(), true);
122:                            parmset.setIconPath(iconfile);
123:                        }
124:                        parmset.setWorkingDirectory(VAGlobals.DEST_PATH);
125:                        //we don't create a shortcut if the user does not want to
126:                        if (parmset.isCreateOnDesktop()) {
127:                            String shortcut = create(parmset,
128:                                    JNIWindowsShortcut.ON_DESKTOP);
129:                            //if created
130:                            if (new File(shortcut).exists())
131:                                shortcuts.add(shortcut);
132:                        }
133:                        String shortcut = null;
134:                        if (menulinkdir != null) {
135:                            if (VAGlobals.DEBUG)
136:                                VAGlobals.printDebug("menu to write="
137:                                        + parmset.getName());
138:
139:                            try {
140:                                shortcut = createCustom(parmset, menulinkdir
141:                                        + "\\" + parmset.getName());
142:                            } catch (IOException _e1) {
143:                                //Fred : there is bug with the accent é,é
144:                                //I don't know how to solve it ....
145:                                shortcut = create(parmset,
146:                                        JNIWindowsShortcut.ON_START_MENU);
147:                                File shortcutFile = new File(shortcut);
148:                                if (shortcutFile.exists()) {
149:                                    File destFile = new File(menulinkdir,
150:                                            shortcutFile.getName());
151:                                    if (VAGlobals.DEBUG
152:                                            && shortcutFile.exists())
153:                                        VAGlobals
154:                                                .printDebug("rename shortcut from=\n "
155:                                                        + shortcutFile
156:                                                                .getAbsolutePath()
157:                                                        + "\nto\n" + destFile);
158:                                    move(shortcutFile, destFile);
159:                                    if (shortcutFile.exists())
160:                                        shortcutFile.delete();
161:                                    shortcut = destFile.getAbsolutePath();
162:                                }
163:                            }
164:                            if (VAGlobals.DEBUG)
165:                                VAGlobals.printDebug("menu written="
166:                                        + parmset.getName());
167:                        } else {
168:                            shortcut = create(parmset,
169:                                    JNIWindowsShortcut.ON_START_MENU);
170:                        }
171:                        if (shortcut != null && new File(shortcut).exists()) {
172:                            shortcuts.add(shortcut);
173:                            shortcutToCreate.add(new File(shortcut));
174:                        }
175:                    }
176:                    //the shortcut for the uninstaller is already created
177:                    //			if (VAGlobals.CREATE_UNINSTALL_SHORTCUT) {
178:                    //				int location = JNIWindowsShortcut.ON_START_MENU;
179:                    //				if (menulinkdir != null) {
180:                    //					location = JNIWindowsShortcut.CUSTOM_LOCATION;
181:                    //					linkname = menulinkdir + "\\";
182:                    //				} else {
183:                    //					linkname = "";
184:                    //				}
185:                    //				linkname += "Uninstall " + VAGlobals.APP_NAME;
186:                    //				iconfile = getWindowsIconFile("uninstall");
187:                    //				String shortcut = JNIWindowsShortcut.createShortcut(
188:                    //						VAGlobals.DEST_PATH
189:                    //								+ System.getProperty("file.separator")
190:                    //								+ "uninstall_" + VAGlobals.APP_NAME + "_"
191:                    //								+ VAGlobals.APP_VERSION + ".bat",
192:                    //						VAGlobals.DEST_PATH, "", // no arguments
193:                    //						JNIWindowsShortcut.SHOW_NORMAL, linkname, location,
194:                    //						JNIWindowsShortcut.EVERYBODY, iconfile, 0, // icon
195:                    //						// offset
196:                    //						"" // description
197:                    //				);
198:                    //				shortcuts.add(shortcut);
199:                    //			}
200:                    if (VAGlobals.SHORTCUTS_IN_INSTALLDIR) {
201:                        File dest = new File(VAGlobals.DEST_PATH);
202:                        for (Iterator it = shortcutToCreate.iterator(); it
203:                                .hasNext();) {
204:                            File f = (File) it.next();
205:                            File shortcutInInstall = new File(dest, f.getName());
206:                            copy(f, shortcutInInstall);
207:                            shortcuts.add(shortcutInInstall.getAbsolutePath());
208:                        }
209:
210:                    }
211:                    return true;
212:                } catch (IOException _e) {
213:
214:                    _e.printStackTrace();
215:                    throw _e;
216:                }
217:            }
218:
219:            /**
220:             * Create a short cut from the entry.
221:             * 
222:             * @parm dest should be one of JNIWindowsShortcut.ON_DESKTOP or
223:             *       JNIWindowsShortcut.ON_START_MENU.
224:             *  
225:             */
226:            private static final String create(VAShortcutEntry parmset, int dest)
227:                    throws IOException {
228:                return JNIWindowsShortcut.createShortcut(parmset.getExePath(),
229:                        parmset.getWorkingDirectory(),
230:                        "", // no arguments
231:                        JNIWindowsShortcut.SHOW_NORMAL, parmset.getName(),
232:                        dest, JNIWindowsShortcut.EVERYBODY, parmset
233:                                .getIconPath(), 0, // icon
234:                        // offset
235:                        parmset.getComment());
236:            }
237:
238:            /**
239:             * @parm dest should be one of JNIWindowsShortcut.ON_DESKTOP or
240:             *       JNIWindowsShortcut.ON_START_MENU.
241:             *  
242:             */
243:            private static final String createCustom(VAShortcutEntry parmset,
244:                    String dest) throws IOException {
245:                return JNIWindowsShortcut.createShortcut(
246:                        parmset.getExePath(),
247:                        parmset.getWorkingDirectory(),
248:                        "", // no arguments
249:                        JNIWindowsShortcut.SHOW_NORMAL, dest,
250:                        JNIWindowsShortcut.CUSTOM_LOCATION,
251:                        JNIWindowsShortcut.EVERYBODY, parmset.getIconPath(), 0, // icon
252:                        // offset
253:                        parmset.getComment());
254:            }
255:
256:            /**
257:             * Return the absolute path of the icon for the <code>name</code>
258:             * executable. If this icon can't be found, the default icon
259:             * <code>LINK_ENTRY_ICON</code> is tried.
260:             */
261:            private static final String getWindowsIconFile(String name,
262:                    boolean _useDefault) {
263:                // get the default icon
264:                File defaultIcon = null;
265:                if ((VAGlobals.LINK_ENTRY_ICON != null)
266:                        && (VAGlobals.LINK_ENTRY_ICON.length() > 0)) {
267:                    defaultIcon = new File(VAGlobals.DEST_PATH,
268:                            VAGlobals.LINK_ENTRY_ICON.replace('/',
269:                                    File.separatorChar)
270:                                    + ".ico");
271:                    VAGlobals.printDebug("default icon= " + defaultIcon);
272:                }
273:                File tryIcon;
274:                if (defaultIcon != null)
275:                    tryIcon = new File(defaultIcon.getParentFile(), name
276:                            + ".ico");
277:                else
278:                    tryIcon = new File(VAGlobals.DEST_PATH, name + ".ico");
279:                VAGlobals.printDebug("try icon= " + tryIcon);
280:                if (tryIcon.exists()) {
281:                    return tryIcon.getAbsolutePath();
282:                }
283:                if (_useDefault && defaultIcon.exists())
284:                    return defaultIcon.getAbsolutePath();
285:                return null;
286:            }
287:
288:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.