reads from the given partyFile and returns the list of character files for this party @param partyFile a .pcp party file @return a list of files containing the characters in this party
(File partyFile)
| 464 | * @return a list of files containing the characters in this party |
| 465 | */ |
| 466 | @SuppressWarnings("PMD.UnusedLocalVariable") |
| 467 | public static List<File> readCharacterFileList(File partyFile) |
| 468 | { |
| 469 | List<String> lines; |
| 470 | try (BufferedReader bufferedReader = new BufferedReader(new FileReader(partyFile, StandardCharsets.UTF_8))) |
| 471 | { |
| 472 | lines = bufferedReader.lines().collect(Collectors.toList()); |
| 473 | } catch (IOException ex) |
| 474 | { |
| 475 | Logging.errorPrint("Exception in IOHandler::read when reading", ex); |
| 476 | return null; |
| 477 | } |
| 478 | if (lines.size() < 2) |
| 479 | { |
| 480 | Logging.errorPrint("Character files missing in " + partyFile.getAbsolutePath()); |
| 481 | return null; |
| 482 | } |
| 483 | //Read and throw away version info. May change to actually use later |
| 484 | String versionInfo = lines.get(0); |
| 485 | //read character filename data |
| 486 | String charFiles = lines.get(1); |
| 487 | String[] files = charFiles.split(","); |
| 488 | |
| 489 | List<File> fileList = new ArrayList<>(); |
| 490 | for (final String fileName : files) |
| 491 | { |
| 492 | // try to find it in the party's directory |
| 493 | File characterFile = new File(partyFile.getParent(), fileName); |
| 494 | if (!characterFile.exists()) |
| 495 | { |
| 496 | // try using the global pcg path |
| 497 | characterFile = new File(PCGenSettings.getPcgDir(), fileName); |
| 498 | } |
| 499 | if (!characterFile.exists()) |
| 500 | { |
| 501 | // try it as an absolute path |
| 502 | characterFile = new File(fileName); |
| 503 | } |
| 504 | if (characterFile.exists()) |
| 505 | { |
| 506 | fileList.add(characterFile); |
| 507 | } else |
| 508 | { |
| 509 | Logging.errorPrint("Character file does not exist: " + fileName); |
| 510 | } |
| 511 | } |
| 512 | return fileList; |
| 513 | } |
| 514 | |
| 515 | public static void write(File partyFile, List<File> characterFiles) |
| 516 | { |