root / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.main / src / main / java / org / gvsig / installer / main / DefaultLauncher.java @ 37822
History | View | Annotate | Download (2.59 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.main; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.FileInputStream; |
32 |
import java.io.FileOutputStream; |
33 |
import java.io.IOException; |
34 |
import java.io.InputStream; |
35 |
import java.io.OutputStream; |
36 |
|
37 |
/**
|
38 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
39 |
*/
|
40 |
public class DefaultLauncher { |
41 |
|
42 |
private File appFolder; |
43 |
|
44 |
public File getApplicationFolder() throws IOException { |
45 |
if (appFolder == null) { |
46 |
File templateFile = new File(getClass().getClassLoader() |
47 |
.getResource("application").getFile());
|
48 |
appFolder = new File(System.getProperty("java.io.tmpdir") |
49 |
+ File.separator + "tmp_gvsig_installer"); |
50 |
|
51 |
copy(templateFile, appFolder); |
52 |
} |
53 |
|
54 |
return appFolder;
|
55 |
} |
56 |
|
57 |
public File getPluginsFolder() throws IOException { |
58 |
return new File(appFolder, "plugins"); |
59 |
} |
60 |
|
61 |
public File getInstallFolder() throws IOException { |
62 |
return new File(appFolder, "install"); |
63 |
} |
64 |
|
65 |
public void copy(File sourceLocation, File targetLocation) |
66 |
throws IOException { |
67 |
if (sourceLocation.isDirectory()) {
|
68 |
if (!targetLocation.exists()) {
|
69 |
targetLocation.mkdir(); |
70 |
} |
71 |
|
72 |
String[] children = sourceLocation.list(); |
73 |
for (int i = 0; i < children.length; i++) { |
74 |
copy(new File(sourceLocation, children[i]), new File( |
75 |
targetLocation, children[i])); |
76 |
} |
77 |
} else {
|
78 |
targetLocation.getParentFile().mkdirs(); |
79 |
|
80 |
InputStream in = new FileInputStream(sourceLocation); |
81 |
OutputStream out = new FileOutputStream(targetLocation); |
82 |
|
83 |
// Copy the bits from instream to outstream
|
84 |
byte[] buf = new byte[1024]; |
85 |
int len;
|
86 |
while ((len = in.read(buf)) > 0) { |
87 |
out.write(buf, 0, len);
|
88 |
} |
89 |
in.close(); |
90 |
out.close(); |
91 |
} |
92 |
} |
93 |
} |