Adds a new class for handling converter profiles
This commit is contained in:
parent
a0b5b65054
commit
d349629574
@ -0,0 +1,64 @@
|
||||
package net.knarcraft.ffmpegconverter.converter;
|
||||
|
||||
import net.knarcraft.ffmpegconverter.utility.FileUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The ConverterProfiles class is responsible for loading and retrieving settings for a converter
|
||||
*/
|
||||
public class ConverterProfiles {
|
||||
|
||||
private Map<String, Map<String, String>> loadedProfiles;
|
||||
|
||||
/**
|
||||
* Instantiates a new converter profiles object
|
||||
*/
|
||||
public ConverterProfiles() {
|
||||
loadedProfiles = new HashMap<>();
|
||||
try {
|
||||
loadProfiles();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all available converter profiles as a set
|
||||
* @return <p>A set of all loaded converter profiles.</p>
|
||||
*/
|
||||
public Set<String> getProfiles() {
|
||||
return loadedProfiles.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all profile settings for the given converter profile
|
||||
* @param profileName <p>The name of the converter profile to get settings for.</p>
|
||||
* @return <p>Settings for the converter profile.</p>
|
||||
*/
|
||||
public Map<String, String> getProfileSettings(String profileName) {
|
||||
return loadedProfiles.get(profileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all converter profiles
|
||||
* @throws IOException <p>If unable to read the converter profiles file.</p>
|
||||
*/
|
||||
private void loadProfiles() throws IOException {
|
||||
String[] profiles = FileUtil.readFileLines("converter_profiles.txt");
|
||||
for (String profile : profiles) {
|
||||
Map<String, String> profileSettings = new HashMap<>();
|
||||
String[] settings = profile.split("\\|");
|
||||
String profileName = settings[0];
|
||||
for (int i = 1; i < settings.length; i++) {
|
||||
String[] settingParts = settings[i].split(":");
|
||||
profileSettings.put(settingParts[0], settingParts[1]);
|
||||
}
|
||||
loadedProfiles.put(profileName, profileSettings);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user