Search in sources :

Example 1 with ConfigEntry

use of net.runelite.http.api.config.ConfigEntry in project runelite by runelite.

the class ConfigManager method load.

public void load() {
    if (client == null) {
        loadFromFile();
        return;
    }
    Configuration configuration;
    try {
        configuration = client.get();
    } catch (IOException ex) {
        log.debug("Unable to load configuration from client, using saved configuration from disk", ex);
        loadFromFile();
        return;
    }
    if (configuration.getConfig().isEmpty()) {
        log.debug("No configuration from client, using saved configuration on disk");
        loadFromFile();
        return;
    }
    properties.clear();
    for (ConfigEntry entry : configuration.getConfig()) {
        log.debug("Loading configuration value from client {}: {}", entry.getKey(), entry.getValue());
        final String[] split = entry.getKey().split("\\.");
        final String groupName = split[0];
        final String key = split[1];
        final String value = entry.getValue();
        final String oldValue = (String) properties.setProperty(entry.getKey(), value);
        ConfigChanged configChanged = new ConfigChanged();
        configChanged.setGroup(groupName);
        configChanged.setKey(key);
        configChanged.setOldValue(oldValue);
        configChanged.setNewValue(value);
        eventBus.post(configChanged);
    }
    try {
        saveToFile();
        log.debug("Updated configuration on disk with the latest version");
    } catch (IOException ex) {
        log.warn("Unable to update configuration on disk", ex);
    }
}
Also used : ConfigEntry(net.runelite.http.api.config.ConfigEntry) Configuration(net.runelite.http.api.config.Configuration) ConfigChanged(net.runelite.api.events.ConfigChanged) IOException(java.io.IOException)

Example 2 with ConfigEntry

use of net.runelite.http.api.config.ConfigEntry in project runelite by runelite.

the class ConfigService method get.

@RequestMapping
public Configuration get(HttpServletRequest request, HttpServletResponse response) throws IOException {
    SessionEntry session = auth.handle(request, response);
    if (session == null) {
        return null;
    }
    List<ConfigEntry> config;
    try (Connection con = sql2o.open()) {
        config = con.createQuery("select `key`, value from config where user = :user").addParameter("user", session.getUser()).executeAndFetch(ConfigEntry.class);
    }
    return new Configuration(config);
}
Also used : ConfigEntry(net.runelite.http.api.config.ConfigEntry) Configuration(net.runelite.http.api.config.Configuration) Connection(org.sql2o.Connection) SessionEntry(net.runelite.http.service.account.beans.SessionEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ConfigEntry (net.runelite.http.api.config.ConfigEntry)2 Configuration (net.runelite.http.api.config.Configuration)2 IOException (java.io.IOException)1 ConfigChanged (net.runelite.api.events.ConfigChanged)1 SessionEntry (net.runelite.http.service.account.beans.SessionEntry)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 Connection (org.sql2o.Connection)1