|
@@ -29,16 +29,10 @@ import com.dmdirc.logger.ErrorLevel;
|
29
|
29
|
import com.dmdirc.logger.Logger;
|
30
|
30
|
import com.dmdirc.util.Downloader;
|
31
|
31
|
|
|
32
|
+import java.awt.event.MouseAdapter;
|
32
|
33
|
import java.awt.event.MouseEvent;
|
33
|
|
-import java.awt.event.MouseListener;
|
34
|
|
-import java.io.BufferedReader;
|
35
|
|
-import java.io.DataOutputStream;
|
36
|
34
|
import java.io.IOException;
|
37
|
|
-import java.io.InputStreamReader;
|
38
|
|
-import java.io.UnsupportedEncodingException;
|
39
|
35
|
import java.net.MalformedURLException;
|
40
|
|
-import java.net.URL;
|
41
|
|
-import java.net.URLConnection;
|
42
|
36
|
import java.util.ArrayList;
|
43
|
37
|
import java.util.Date;
|
44
|
38
|
import java.util.List;
|
|
@@ -54,7 +48,7 @@ import javax.swing.JLabel;
|
54
|
48
|
*
|
55
|
49
|
* @author chris
|
56
|
50
|
*/
|
57
|
|
-public final class UpdateChecker implements Runnable, MouseListener {
|
|
51
|
+public final class UpdateChecker extends MouseAdapter implements Runnable {
|
58
|
52
|
|
59
|
53
|
/** The label used to indicate that there's an update available. */
|
60
|
54
|
private static JLabel label;
|
|
@@ -70,20 +64,18 @@ public final class UpdateChecker implements Runnable, MouseListener {
|
70
|
64
|
}
|
71
|
65
|
|
72
|
66
|
/** {@inheritDoc} */
|
|
67
|
+ @Override
|
73
|
68
|
public void run() {
|
74
|
69
|
Main.getUI().getStatusBar().setMessage("Checking for updates...");
|
75
|
70
|
|
76
|
71
|
updates.clear();
|
77
|
72
|
|
78
|
|
- URL url;
|
79
|
|
- URLConnection urlConn;
|
80
|
|
- DataOutputStream printout;
|
81
|
|
- BufferedReader printin;
|
82
|
73
|
try {
|
83
|
74
|
final String content = "component=client&channel="
|
84
|
75
|
+ Main.UPDATE_CHANNEL + "&date=" + Main.RELEASE_DATE;
|
85
|
76
|
|
86
|
|
- final List<String> response = Downloader.getPage("http://www.dmdirc.com/update.php", content);
|
|
77
|
+ final List<String> response
|
|
78
|
+ = Downloader.getPage("http://www.dmdirc.com/update.php", content);
|
87
|
79
|
|
88
|
80
|
for (String line : response) {
|
89
|
81
|
checkLine(line);
|
|
@@ -95,7 +87,8 @@ public final class UpdateChecker implements Runnable, MouseListener {
|
95
|
87
|
} catch (MalformedURLException ex) {
|
96
|
88
|
Logger.appError(ErrorLevel.LOW, "Error when checking for updates", ex);
|
97
|
89
|
} catch (IOException ex) {
|
98
|
|
- Logger.userError(ErrorLevel.LOW, "I/O error when checking for updates: " + ex.getMessage());
|
|
90
|
+ Logger.userError(ErrorLevel.LOW,
|
|
91
|
+ "I/O error when checking for updates: " + ex.getMessage());
|
99
|
92
|
}
|
100
|
93
|
}
|
101
|
94
|
|
|
@@ -137,22 +130,20 @@ public final class UpdateChecker implements Runnable, MouseListener {
|
137
|
130
|
* frequency specified in the config.
|
138
|
131
|
*/
|
139
|
132
|
public static void init() {
|
140
|
|
- final int last = IdentityManager.getGlobalConfig().getOptionInt("updater", "lastcheck", 0);
|
141
|
|
- final int freq = IdentityManager.getGlobalConfig().getOptionInt("updater", "frequency", 86400);
|
|
133
|
+ final int last
|
|
134
|
+ = IdentityManager.getGlobalConfig().getOptionInt("updater", "lastcheck", 0);
|
|
135
|
+ final int freq
|
|
136
|
+ = IdentityManager.getGlobalConfig().getOptionInt("updater", "frequency", 86400);
|
142
|
137
|
final int timestamp = (int) (new Date().getTime() / 1000);
|
143
|
138
|
int time = 0;
|
144
|
139
|
|
145
|
140
|
if (last + freq > timestamp) {
|
146
|
141
|
time = last + freq - timestamp;
|
147
|
142
|
}
|
148
|
|
-
|
149
|
|
- /*
|
150
|
|
- final List<Update> temp = new ArrayList<Update>();
|
151
|
|
- temp.add(new Update("outofdate teststuff 20073005 20060101 http://www.example.com/"));
|
152
|
|
- new SwingUpdaterDialog(temp);
|
153
|
|
- */
|
154
|
|
-
|
|
143
|
+
|
155
|
144
|
new Timer("Update Checker Timer").schedule(new TimerTask() {
|
|
145
|
+ /** {@inheritDoc} */
|
|
146
|
+ @Override
|
156
|
147
|
public void run() {
|
157
|
148
|
new Thread(new UpdateChecker(), "UpdateChecker thread").start();
|
158
|
149
|
}
|
|
@@ -160,30 +151,11 @@ public final class UpdateChecker implements Runnable, MouseListener {
|
160
|
151
|
}
|
161
|
152
|
|
162
|
153
|
/** {@inheritDoc} */
|
|
154
|
+ @Override
|
163
|
155
|
public void mouseClicked(final MouseEvent e) {
|
164
|
156
|
if (e.getButton() == MouseEvent.BUTTON1) {
|
165
|
157
|
Main.getUI().getUpdaterDialog(updates).display();
|
166
|
158
|
}
|
167
|
159
|
}
|
168
|
160
|
|
169
|
|
- /** {@inheritDoc} */
|
170
|
|
- public void mousePressed(final MouseEvent e) {
|
171
|
|
- // Do nothing
|
172
|
|
- }
|
173
|
|
-
|
174
|
|
- /** {@inheritDoc} */
|
175
|
|
- public void mouseReleased(final MouseEvent e) {
|
176
|
|
- // Do nothing
|
177
|
|
- }
|
178
|
|
-
|
179
|
|
- /** {@inheritDoc} */
|
180
|
|
- public void mouseEntered(final MouseEvent e) {
|
181
|
|
- // Do nothing
|
182
|
|
- }
|
183
|
|
-
|
184
|
|
- /** {@inheritDoc} */
|
185
|
|
- public void mouseExited(final MouseEvent e) {
|
186
|
|
- // Do nothing
|
187
|
|
- }
|
188
|
|
-
|
189
|
161
|
}
|