Skip to content

Commit

Permalink
Update INIConfig.java
Browse files Browse the repository at this point in the history
  • Loading branch information
BytingBulldogs3539 committed Feb 4, 2023
1 parent 25edc1c commit 40866dd
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.ini4j.Wini;
import org.ini4j.Profile.Section;

import edu.wpi.first.wpilibj.DriverStation;

/** Add your docs here. */
public class INIConfig {
Wini ini;
Expand All @@ -26,21 +28,27 @@ public INIConfig(String filename) {
}

public void autoPopulate(Object o) {
Field[] fields = o.getClass().getFields();
for (Field field : fields) {
String[] split = field.getName().split("_");
int length = split.length;
if (length >= 2) {
try {

field.set(o, getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType()));
if (ini != null) {
Field[] fields = o.getClass().getFields();
for (Field field : fields) {
String[] split = field.getName().split("_");
int length = split.length;
if (length >= 2) {
try {

if(getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType())!=null)
{
field.set(o,
getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType()));
}

} catch (IllegalArgumentException | IllegalAccessException e) {
// DriverStation.reportWarning("Could not load item "+field.getName()+" from
// file "+iniConfig.getFileName(), e.getStackTrace());
} catch (IllegalArgumentException | IllegalAccessException e) {
DriverStation.reportWarning("Could not load item " + field.getName() + " from file " + filename,
e.getStackTrace());
}
}
field.getType();
}
field.getType();
}
}

Expand Down

0 comments on commit 40866dd

Please sign in to comment.