29
29
30
30
package net .imagej .ui .swing .updater ;
31
31
32
+ import java .awt .EventQueue ;
32
33
import java .io .DataInputStream ;
33
34
import java .io .File ;
34
35
import java .io .IOException ;
35
36
import java .lang .reflect .InvocationTargetException ;
36
37
import java .net .Authenticator ;
37
38
import java .net .HttpURLConnection ;
38
- import java .net .MalformedURLException ;
39
39
import java .net .URL ;
40
- import java .net .URLClassLoader ;
41
40
import java .net .URLConnection ;
42
41
import java .net .UnknownHostException ;
43
- import java .util .ArrayList ;
44
42
import java .util .List ;
45
43
46
44
import net .imagej .ui .swing .updater .ViewOptions .Option ;
47
45
import net .imagej .updater .*;
48
46
import net .imagej .updater .Conflicts .Conflict ;
49
47
import net .imagej .updater .util .*;
50
48
49
+ import org .scijava .Context ;
51
50
import org .scijava .app .StatusService ;
52
- import org .scijava .command .CommandService ;
53
51
import org .scijava .event .ContextDisposingEvent ;
54
52
import org .scijava .event .EventHandler ;
55
53
import org .scijava .log .LogService ;
59
57
import org .scijava .plugin .Plugin ;
60
58
import org .scijava .util .AppUtils ;
61
59
62
- import javax .swing .*;
63
-
64
60
/**
65
61
* The Updater. As a command.
66
62
*
69
65
@ Plugin (type = UpdaterUI .class , menu = { @ Menu (label = "Help" ),
70
66
@ Menu (label = "Update..." ) })
71
67
public class ImageJUpdater implements UpdaterUI {
68
+
72
69
private UpdaterFrame main ;
73
70
71
+ @ Parameter (required = false )
72
+ private Context context ;
73
+
74
74
@ Parameter (required = false )
75
75
private StatusService statusService ;
76
76
@@ -82,6 +82,7 @@ public class ImageJUpdater implements UpdaterUI {
82
82
83
83
@ Override
84
84
public void run () {
85
+ new LauncherMigrator (context ).checkLaunchStatus ();
85
86
86
87
if (errorIfDebian ()) return ;
87
88
@@ -91,14 +92,12 @@ public void run() {
91
92
92
93
if (errorIfNetworkInaccessible (log )) return ;
93
94
94
- String imagejDirProperty = System .getProperty ("imagej.dir" );
95
- final File imagejRoot = imagejDirProperty != null ? new File (imagejDirProperty ) :
96
- AppUtils .getBaseDirectory ("ij.dir" , FilesCollection .class , "updater" );
97
- final FilesCollection files = new FilesCollection (log , imagejRoot );
95
+ final File appDir = getAppDirectory ();
96
+ final FilesCollection files = new FilesCollection (log , appDir );
98
97
99
98
UpdaterUserInterface .set (new SwingUserInterface (log , statusService ));
100
99
101
- if (new File (imagejRoot , "update" ).exists ()) {
100
+ if (new File (appDir , "update" ).exists ()) {
102
101
if (!UpdaterUserInterface .get ().promptYesNo ("It is suggested that you restart ImageJ, then continue the update.\n "
103
102
+ "Alternately, you can attempt to continue the upgrade without\n "
104
103
+ "restarting, but ImageJ might crash.\n \n "
@@ -187,14 +186,20 @@ protected void updateConflictList() {
187
186
main .updateFilesTable ();
188
187
}
189
188
189
+ static File getAppDirectory () {
190
+ String imagejDirProperty = System .getProperty ("imagej.dir" );
191
+ return imagejDirProperty != null ? new File (imagejDirProperty ) :
192
+ AppUtils .getBaseDirectory ("ij.dir" , FilesCollection .class , "updater" );
193
+ }
194
+
190
195
private void refreshUpdateSites (FilesCollection files )
191
196
throws InterruptedException , InvocationTargetException
192
197
{
193
198
List <URLChange >
194
199
changes = AvailableSites .initializeAndAddSites (files , (Logger ) log );
195
200
if (ReviewSiteURLsDialog .shouldBeDisplayed (changes )) {
196
201
ReviewSiteURLsDialog dialog = new ReviewSiteURLsDialog (main , changes );
197
- SwingUtilities .invokeAndWait (() -> dialog .setVisible (true ));
202
+ EventQueue .invokeAndWait (() -> dialog .setVisible (true ));
198
203
if (dialog .isOkPressed ())
199
204
AvailableSites .applySitesURLUpdates (files , changes );
200
205
}
0 commit comments