|
@@ -42,12 +42,12 @@ import com.dmdirc.util.resourcemanager.ResourceManager;
|
42
|
42
|
import java.io.File;
|
43
|
43
|
import java.io.IOException;
|
44
|
44
|
import java.util.ArrayList;
|
|
45
|
+import java.util.Collection;
|
45
|
46
|
import java.util.Collections;
|
46
|
47
|
import java.util.HashMap;
|
47
|
48
|
import java.util.LinkedHashSet;
|
48
|
49
|
import java.util.List;
|
49
|
50
|
import java.util.Map;
|
50
|
|
-import java.util.Set;
|
51
|
51
|
|
52
|
52
|
import org.slf4j.Logger;
|
53
|
53
|
import org.slf4j.LoggerFactory;
|
|
@@ -160,7 +160,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
160
|
160
|
if (!success) {
|
161
|
161
|
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, null,
|
162
|
162
|
"Unable to create directory for default settings folder ("
|
163
|
|
- + target + ")",
|
|
163
|
+ + target + ')',
|
164
|
164
|
"A file with that name already exists, and couldn't be renamed."
|
165
|
165
|
+ " Rename or delete " + file.getAbsolutePath()));
|
166
|
166
|
continue;
|
|
@@ -175,7 +175,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
175
|
175
|
return;
|
176
|
176
|
}
|
177
|
177
|
|
178
|
|
- if (file.listFiles() == null || file.listFiles().length == 0) {
|
|
178
|
+ final File[] files = file.listFiles();
|
|
179
|
+ if (files == null || files.length == 0) {
|
179
|
180
|
extractIdentities(target);
|
180
|
181
|
}
|
181
|
182
|
|
|
@@ -260,11 +261,12 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
260
|
261
|
checkNotNull(dir);
|
261
|
262
|
checkArgument(dir.isDirectory());
|
262
|
263
|
|
263
|
|
- if (dir.listFiles() == null) {
|
|
264
|
+ final File[] files = dir.listFiles();
|
|
265
|
+ if (files == null) {
|
264
|
266
|
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
|
265
|
267
|
"Unable to load user identity files from " + dir.getAbsolutePath(), ""));
|
266
|
268
|
} else {
|
267
|
|
- for (File file : dir.listFiles()) {
|
|
269
|
+ for (File file : files) {
|
268
|
270
|
if (file.isDirectory()) {
|
269
|
271
|
loadUser(file);
|
270
|
272
|
} else {
|
|
@@ -283,7 +285,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
283
|
285
|
private void loadIdentity(final File file) {
|
284
|
286
|
synchronized (identities) {
|
285
|
287
|
for (ConfigProvider identity : getAllIdentities()) {
|
286
|
|
- if ((identity instanceof ConfigFileBackedConfigProvider)
|
|
288
|
+ if (identity instanceof ConfigFileBackedConfigProvider
|
287
|
289
|
&& ((ConfigFileBackedConfigProvider) identity).isFile(file)) {
|
288
|
290
|
// TODO: This manager should keep a list of files->identities instead of
|
289
|
291
|
// relying on the identities remembering.
|
|
@@ -292,7 +294,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
292
|
294
|
} catch (IOException ex) {
|
293
|
295
|
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
|
294
|
296
|
"I/O error when reloading identity file: "
|
295
|
|
- + file.getAbsolutePath() + " (" + ex.getMessage() + ")", ""));
|
|
297
|
+ + file.getAbsolutePath() + " (" + ex.getMessage() + ')', ""));
|
296
|
298
|
} catch (InvalidConfigFileException ex) {
|
297
|
299
|
// Do nothing
|
298
|
300
|
}
|
|
@@ -307,7 +309,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
307
|
309
|
} catch (InvalidIdentityFileException ex) {
|
308
|
310
|
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
|
309
|
311
|
"Invalid identity file: " + file.getAbsolutePath() + " ("
|
310
|
|
- + ex.getMessage() + ")", ""));
|
|
312
|
+ + ex.getMessage() + ')', ""));
|
311
|
313
|
} catch (IOException ex) {
|
312
|
314
|
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
|
313
|
315
|
"I/O error when reading identity file: " + file.getAbsolutePath(), ""));
|
|
@@ -321,8 +323,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
321
|
323
|
*
|
322
|
324
|
* @since 0.6.4
|
323
|
325
|
*/
|
324
|
|
- private Set<ConfigProvider> getAllIdentities() {
|
325
|
|
- final Set<ConfigProvider> res = new LinkedHashSet<>();
|
|
326
|
+ private Iterable<ConfigProvider> getAllIdentities() {
|
|
327
|
+ final Collection<ConfigProvider> res = new LinkedHashSet<>();
|
326
|
328
|
|
327
|
329
|
for (Map.Entry<String, List<ConfigProvider>> entry : identities.entrySet()) {
|
328
|
330
|
res.addAll(entry.getValue());
|
|
@@ -517,7 +519,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
517
|
519
|
+ "with null or empty channel\n\nChannel: " + channel);
|
518
|
520
|
}
|
519
|
521
|
|
520
|
|
- final String myTarget = (channel + "@" + network).toLowerCase();
|
|
522
|
+ final String myTarget = (channel + '@' + network).toLowerCase();
|
521
|
523
|
|
522
|
524
|
synchronized (identities) {
|
523
|
525
|
for (ConfigProvider identity : identities.safeGet(null)) {
|
|
@@ -665,7 +667,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
|
665
|
667
|
int attempt = 1;
|
666
|
668
|
|
667
|
669
|
while (file.exists()) {
|
668
|
|
- file = new File(identitiesDirectory + name + "-" + attempt);
|
|
670
|
+ file = new File(identitiesDirectory + name + '-' + attempt);
|
669
|
671
|
attempt++;
|
670
|
672
|
}
|
671
|
673
|
|