Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading .ini files #27

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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