1 | |
package org.jtheque.core.managers.update.actions; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.core.managers.Managers; |
20 | |
import org.jtheque.core.managers.error.InternationalizedError; |
21 | |
import org.jtheque.core.managers.log.ILoggingManager; |
22 | |
import org.jtheque.core.managers.view.able.IViewManager; |
23 | |
import org.jtheque.utils.OSUtils; |
24 | |
import org.jtheque.utils.StringUtils; |
25 | |
import org.jtheque.utils.io.FileException; |
26 | |
import org.jtheque.utils.io.FileUtils; |
27 | |
|
28 | |
import java.io.File; |
29 | |
import java.io.FileNotFoundException; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public final class DownloadAction extends AbstractUpdateAction { |
37 | |
private String url; |
38 | |
private String os; |
39 | |
|
40 | |
@Override |
41 | |
public void execute() { |
42 | 0 | if (canBeExecutedOnThisOS()) { |
43 | |
try { |
44 | 0 | if(!new File(getDestination()).delete()){ |
45 | 0 | setFile("dljt_" + getFile()); |
46 | |
} |
47 | |
|
48 | 0 | FileUtils.downloadFile(url, getDestination()); |
49 | 0 | } catch (FileException e) { |
50 | 0 | Managers.getManager(ILoggingManager.class).getLogger(getClass()).error(e); |
51 | |
|
52 | 0 | if(e.getCause() instanceof FileNotFoundException){ |
53 | 0 | Managers.getManager(IViewManager.class).displayError( |
54 | |
new InternationalizedError("error.update.download", e.getMessage())); |
55 | |
} |
56 | 0 | } |
57 | |
} |
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
private boolean canBeExecutedOnThisOS() { |
66 | 0 | if (StringUtils.isNotEmpty(os)) { |
67 | 0 | if ("linux".equalsIgnoreCase(os)) { |
68 | 0 | return OSUtils.isLinux(); |
69 | 0 | } else if ("mac".equalsIgnoreCase(os)) { |
70 | 0 | return OSUtils.isMac(); |
71 | 0 | } else if ("windows".equalsIgnoreCase(os)) { |
72 | 0 | return OSUtils.isWindows(); |
73 | |
} |
74 | |
} |
75 | |
|
76 | 0 | return true; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public void setUrl(String url) { |
85 | 0 | this.url = url; |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public void setOs(String os) { |
94 | 0 | this.os = os; |
95 | 0 | } |
96 | |
} |