Пример #1
0
  /**
   * Moves the chunk group file to the folder for deleted factions.
   *
   * @param groupId
   */
  public static void deleteChunkGroup(String groupId) {

    // Create folders:
    File deletedDirectory = new File(WriteReadType.SETTLEMENT_DELETED.getDirectory());
    File factionDirectory = new File(WriteReadType.SETTLEMENT_NORMAL.getDirectory());
    File deletedFile =
        new File(
            WriteReadType.SETTLEMENT_DELETED.getDirectory()
                + groupId
                + IOConstants.FILE_EXTENTENSION);
    File factionFile =
        new File(
            WriteReadType.SETTLEMENT_NORMAL.getDirectory()
                + groupId
                + IOConstants.FILE_EXTENTENSION);

    if (!deletedDirectory.exists()) {
      deletedDirectory.mkdirs();
      Saga.info("Creating " + deletedDirectory + " directory.");
    }

    if (!factionDirectory.exists()) {
      factionDirectory.mkdirs();
      Saga.info("Creating " + factionDirectory + " directory.");
    }

    // Check if exists.
    if (!factionFile.exists()) {
      Saga.severe("Cant move " + factionFile + ", because it doesent exist.");
    }

    // Rename if target exists:
    for (int i = 1; i < 1000; i++) {
      if (deletedFile.exists()) {
        deletedFile.renameTo(
            new File(
                WriteReadType.SETTLEMENT_DELETED.getDirectory()
                    + groupId
                    + "("
                    + i
                    + ")"
                    + IOConstants.FILE_EXTENTENSION));
      } else {
        break;
      }
    }

    // Move file to deleted folder:
    boolean success = factionFile.renameTo(deletedFile);

    // Notify on failure:
    if (success) {
      Saga.info("Moved " + factionFile + " file to deleted factions folder.");
    } else {
      Saga.severe("Failed to move " + factionFile + " to deleted factions folder.");
    }
  }
Пример #2
0
  /**
   * Gets all settlement IDs in String form for reading.
   *
   * @return all filenames
   */
  public static String[] getAllChunkGroupIds() {

    File directory = new File(WriteReadType.SETTLEMENT_NORMAL.getDirectory());
    FilenameFilter filter =
        new FilenameFilter() {

          @Override
          public boolean accept(File dir, String name) {
            return name.endsWith(IOConstants.FILE_EXTENTENSION);
          }
        };

    if (!directory.exists()) {
      directory.mkdirs();
      Saga.info("Creating " + directory + " directory.");
    }

    String[] names = directory.list(filter);

    if (names == null) {
      Saga.severe("Could not retrieve faction names.");
      names = new String[0];
    }

    // Remove extensions:
    for (int i = 0; i < names.length; i++) {
      names[i] = names[i].replaceAll(IOConstants.FILE_EXTENTENSION, "");
    }

    return names;
  }