Skip to content

Commit

Permalink
Fix reading .ini files
Browse files Browse the repository at this point in the history
Fixes a bug which skips entries as the line-counter is increased to unnecessary.
  • Loading branch information
Borewit authored and Borewit committed Jan 16, 2023
1 parent 10e8bca commit 9c15414
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions src/main/java/listfix/io/readers/IniFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,51 +82,42 @@ else if (in_data2.length() == 0)
}
}

public void readIni() throws IOException
{
List<String> tempList = new ArrayList<>();
List<String> lines = Files.readAllLines(Paths.get(fname1), StandardCharsets.UTF_8);

// Read in base media directories
// skip first line, contains header
int i = 1;
while (i < lines.size())
private static int readIniEntries(int lineNr, List<String> tempList, List<String> lines) {
while (lineNr < lines.size())
{
String line = lines.get(i++);
String line = lines.get(lineNr++);
if (line.startsWith("[")) {
++i;
break;
}
tempList.add(line);
}
return lineNr;
}

public void readIni() throws IOException
{
List<String> tempList = new ArrayList<>();
List<String> lines = Files.readAllLines(Paths.get(fname1), StandardCharsets.UTF_8);

// Read in base media directories
// skip first line, contains header
int lineNr = readIniEntries(1, tempList, lines);
mediaDirs = new String[tempList.size()];
tempList.toArray(mediaDirs);

tempList.clear();

// Read in media library directories
// skip first line, contains header
while (i < lines.size())
{
String line = lines.get(i++);
if (line.startsWith("[")) {
++i;
break;
}
tempList.add(line);
}
lineNr = readIniEntries(lineNr, tempList, lines);
mediaLibrary = new String[tempList.size()];
tempList.toArray(mediaLibrary);
tempList.clear();

// Read in media library files
// skip first line, contains header
while (i < lines.size())
{
String line = lines.get(i++);
tempList.add(line);
}
readIniEntries(lineNr, tempList, lines);

mediaLibraryFiles = new String[tempList.size()];
tempList.toArray(mediaLibraryFiles);
tempList.clear();
Expand Down

0 comments on commit 9c15414

Please sign in to comment.