|
33 | 33 |
|
34 | 34 | import java.io.File; |
35 | 35 | import java.io.IOException; |
36 | | -import java.io.UnsupportedEncodingException; |
37 | | -import java.security.MessageDigest; |
38 | | -import java.security.NoSuchAlgorithmException; |
39 | 36 |
|
40 | 37 | import org.scijava.app.AppService; |
41 | 38 | import org.scijava.command.CommandService; |
|
49 | 46 | import org.scijava.service.Service; |
50 | 47 | import org.scijava.text.TextService; |
51 | 48 | import org.scijava.ui.event.UIShownEvent; |
| 49 | +import org.scijava.util.DigestUtils; |
52 | 50 | import org.scijava.util.Prefs; |
53 | 51 | import org.scijava.welcome.event.WelcomeEvent; |
54 | 52 |
|
@@ -97,7 +95,7 @@ private void displayWelcome(final boolean force) { |
97 | 95 | try { |
98 | 96 | if (welcomeFile.exists()) { |
99 | 97 | final String welcomeText = textService.asHTML(welcomeFile); |
100 | | - final String checksum = getChecksum(welcomeText); |
| 98 | + final String checksum = DigestUtils.bestHex(welcomeText); |
101 | 99 | final String previousChecksum = Prefs.get(getClass(), CHECKSUM_PREFS_KEY); |
102 | 100 | if (!force && checksum.equals(previousChecksum)) return; |
103 | 101 | Prefs.put(getClass(), CHECKSUM_PREFS_KEY, checksum); |
@@ -138,34 +136,4 @@ private String firstRunPrefKey() { |
138 | 136 | return "firstRun-" + appService.getApp().getVersion(); |
139 | 137 | } |
140 | 138 |
|
141 | | - // TODO: move this into TextUtils or some such |
142 | | - // see https://github.com/scijava/scijava-common/issues/82 |
143 | | - // get digest of the file as according to fullPath |
144 | | - private String getChecksum(final String text) |
145 | | - { |
146 | | - try { |
147 | | - final MessageDigest digest = MessageDigest.getInstance("SHA-1"); |
148 | | - digest.update(text.getBytes("UTF-8")); |
149 | | - return toHex(digest.digest()); |
150 | | - } |
151 | | - catch (NoSuchAlgorithmException e) { |
152 | | - return "" + text.hashCode(); |
153 | | - } |
154 | | - catch (UnsupportedEncodingException e) { |
155 | | - return "" + text.hashCode(); |
156 | | - } |
157 | | - } |
158 | | - |
159 | | - private final static char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', |
160 | | - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
161 | | - |
162 | | - private String toHex(final byte[] bytes) { |
163 | | - final char[] buffer = new char[bytes.length * 2]; |
164 | | - for (int i = 0; i < bytes.length; i++) { |
165 | | - buffer[i * 2] = hex[(bytes[i] & 0xf0) >> 4]; |
166 | | - buffer[i * 2 + 1] = hex[bytes[i] & 0xf]; |
167 | | - } |
168 | | - return new String(buffer); |
169 | | - } |
170 | | - |
171 | 139 | } |
0 commit comments