Languages can now be defined in a file.
INI properties which are not editable will now be set. Code improvements.
This commit is contained in:
parent
0eedf452d7
commit
14408cd9a6
16
languages.txt
Normal file
16
languages.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# List of languages
|
||||||
|
# https://partner.steamgames.com/doc/store/localization#supported_languages
|
||||||
|
|
||||||
|
english
|
||||||
|
latam
|
||||||
|
brazilian
|
||||||
|
german
|
||||||
|
french
|
||||||
|
italian
|
||||||
|
portuguese
|
||||||
|
spanish
|
||||||
|
russian
|
||||||
|
schinese
|
||||||
|
tchinese
|
||||||
|
japanese
|
||||||
|
koreana
|
@ -1,7 +1,6 @@
|
|||||||
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamApp;
|
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamApp;
|
||||||
import com.jfoenix.controls.*;
|
import com.jfoenix.controls.*;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
@ -99,7 +98,7 @@ public class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void getAppId() {
|
public void getAppId() {
|
||||||
final SteamApp game = cache.searchGame(game_name_textfield.getText());
|
final SteamApp game = cache.findGame(game_name_textfield.getText());
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
appId_textfield.setText("-1");
|
appId_textfield.setText("-1");
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import org.apache.commons.configuration2.INIConfiguration;
|
import org.apache.commons.configuration2.*;
|
||||||
import org.apache.commons.configuration2.SubnodeConfiguration;
|
|
||||||
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
|
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
|
||||||
import org.apache.commons.configuration2.builder.fluent.Configurations;
|
import org.apache.commons.configuration2.builder.fluent.Configurations;
|
||||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -16,7 +14,6 @@ public class CreamApiConfig {
|
|||||||
|
|
||||||
private INIConfiguration config;
|
private INIConfiguration config;
|
||||||
private String path = "cream_api.ini";
|
private String path = "cream_api.ini";
|
||||||
//private Ini ini;
|
|
||||||
private Integer appId;
|
private Integer appId;
|
||||||
private String language;
|
private String language;
|
||||||
private Boolean unlockAll;
|
private Boolean unlockAll;
|
||||||
@ -32,27 +29,14 @@ public class CreamApiConfig {
|
|||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
/*try {
|
|
||||||
//ini = new Ini(new File("cream_api.ini"));
|
File langFile = new File("languages.txt");
|
||||||
//Config iniConfig = Config.getGlobal().clone();
|
try {
|
||||||
|
BufferedReader fIn = new BufferedReader(new FileReader(langFile));
|
||||||
|
fIn.lines().filter(line -> !line.isEmpty() && !line.startsWith("#")).forEach(line -> languages.add(line));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Can't open \"cream_api.ini\"!");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}*/
|
}
|
||||||
// https://partner.steamgames.com/doc/store/localization#supported_languages
|
|
||||||
languages.add("english");
|
|
||||||
languages.add("latam");
|
|
||||||
languages.add("brazilian");
|
|
||||||
languages.add("german");
|
|
||||||
languages.add("french");
|
|
||||||
languages.add("italian");
|
|
||||||
languages.add("portuguese");
|
|
||||||
languages.add("spanish");
|
|
||||||
languages.add("russian");
|
|
||||||
languages.add("schinese");
|
|
||||||
languages.add("tchinese");
|
|
||||||
languages.add("japanese");
|
|
||||||
languages.add("koreana");
|
|
||||||
read();
|
read();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,17 +48,6 @@ public class CreamApiConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void read() {
|
public void read() {
|
||||||
/*appId = ini.get("steam", "appid", int.class);
|
|
||||||
language = ini.get("steam", "language", String.class);
|
|
||||||
if (language == null) {
|
|
||||||
language = "english";
|
|
||||||
}
|
|
||||||
unlockAll = ini.get("steam", "unlockall", boolean.class);
|
|
||||||
extraProtection = ini.get("steam", "extraprotection", boolean.class);
|
|
||||||
forceOffline = ini.get("steam", "forceoffline", boolean.class);
|
|
||||||
Map<String, String> dlc_temp = ini.get("dlc");
|
|
||||||
for (Map.Entry<String, String> e: dlc_temp.entrySet())
|
|
||||||
dlc.put(Integer.parseInt(e.getKey()), e.getValue());*/
|
|
||||||
appId = config.getInt("steam.appid");
|
appId = config.getInt("steam.appid");
|
||||||
language = config.getString("steam.language");
|
language = config.getString("steam.language");
|
||||||
if (language == null) {
|
if (language == null) {
|
||||||
@ -84,23 +57,10 @@ public class CreamApiConfig {
|
|||||||
extraProtection = config.getBoolean("steam.extraprotection");
|
extraProtection = config.getBoolean("steam.extraprotection");
|
||||||
forceOffline = config.getBoolean("steam.forceoffline");
|
forceOffline = config.getBoolean("steam.forceoffline");
|
||||||
final SubnodeConfiguration dlc_section = config.getSection("dlc");
|
final SubnodeConfiguration dlc_section = config.getSection("dlc");
|
||||||
for (Iterator<String> it = dlc_section.getKeys(); it.hasNext(); ) {
|
dlc_section.getKeys().forEachRemaining(k -> dlc.put(Integer.parseInt(k), dlc_section.getString(k)));
|
||||||
String k = it.next();
|
|
||||||
final String v = dlc_section.getString(k);
|
|
||||||
dlc.put(Integer.parseInt(k), v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sync() throws ConfigurationException {
|
public void sync() throws ConfigurationException {
|
||||||
/*ini.put("steam", "appid", appId);
|
|
||||||
ini.put("steam", "language", language);
|
|
||||||
ini.put("steam", "unlockall", unlockAll);
|
|
||||||
ini.put("steam", "extraprotection", extraProtection);
|
|
||||||
ini.put("steam", "forceoffline", forceOffline);
|
|
||||||
for (Map.Entry<Integer, String> e: dlc.entrySet()) {
|
|
||||||
ini.put("dlc", e.getKey().toString(), e.getValue());
|
|
||||||
}
|
|
||||||
ini.store();*/
|
|
||||||
FileBasedConfigurationBuilder<INIConfiguration> builder = CONFIGS.iniBuilder(path);
|
FileBasedConfigurationBuilder<INIConfiguration> builder = CONFIGS.iniBuilder(path);
|
||||||
config = builder.getConfiguration();
|
config = builder.getConfiguration();
|
||||||
config.setCommentLeadingCharsUsedInInput(";");
|
config.setCommentLeadingCharsUsedInInput(";");
|
||||||
@ -112,9 +72,13 @@ public class CreamApiConfig {
|
|||||||
config.setProperty("steam.forceoffline", forceOffline);
|
config.setProperty("steam.forceoffline", forceOffline);
|
||||||
final SubnodeConfiguration dlc_section = config.getSection("dlc");
|
final SubnodeConfiguration dlc_section = config.getSection("dlc");
|
||||||
dlc_section.clear();
|
dlc_section.clear();
|
||||||
for (Map.Entry<Integer, String> e : this.dlc.entrySet()) {
|
this.dlc.forEach((key, value) -> config.setProperty("dlc." + key.toString(), value));
|
||||||
config.setProperty("dlc." + e.getKey().toString(), e.getValue());
|
|
||||||
}
|
// default settings
|
||||||
|
config.setProperty("steam.orgapi", "steam_api_o.dll");
|
||||||
|
config.setProperty("steam.orgapi64", "steam_api64_o.dll");
|
||||||
|
config.setProperty("steam.lowviolence", false);
|
||||||
|
config.setProperty("steam_misc.disableuserinterface", false);
|
||||||
|
|
||||||
builder.save();
|
builder.save();
|
||||||
}
|
}
|
||||||
@ -123,23 +87,17 @@ public class CreamApiConfig {
|
|||||||
|
|
||||||
public String getDlcListAsString() {
|
public String getDlcListAsString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Map.Entry<Integer, String> e: dlc.entrySet()) {
|
dlc.forEach((key, value) -> sb.append(key).append("=").append(value).append("\r\n"));
|
||||||
sb.append(e.getKey());
|
|
||||||
sb.append("=");
|
|
||||||
sb.append(e.getValue());
|
|
||||||
sb.append("\r\n");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDlcListFromString(String str) {
|
public void setDlcListFromString(String str) {
|
||||||
dlc.clear();
|
dlc.clear();
|
||||||
final String[] lines = str.split("\\R+");
|
Arrays.stream(str.split("\\R+")).forEach(line -> {
|
||||||
for (String line : lines) {
|
|
||||||
final String[] split = line.split("\\s*=\\s*", 2);
|
final String[] split = line.split("\\s*=\\s*", 2);
|
||||||
if (split.length == 2) dlc.put(Integer.parseInt(split[0]), split[1]);
|
if (split.length == 2) dlc.put(Integer.parseInt(split[0]), split[1]);
|
||||||
else System.err.println(MessageFormat.format("Error while splitting line: \"{0}\"", line));
|
else System.err.println(MessageFormat.format("Error while splitting line: \"{0}\"", line));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// GETTERS AND SETTERS
|
// GETTERS AND SETTERS
|
||||||
|
@ -16,7 +16,6 @@ public class Main extends Application {
|
|||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import java.time.Duration;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public class SteamAppsListCache {
|
public class SteamAppsListCache {
|
||||||
@ -25,7 +26,7 @@ public class SteamAppsListCache {
|
|||||||
|
|
||||||
public SteamAppsListCache() {
|
public SteamAppsListCache() {
|
||||||
getListFromFile();
|
getListFromFile();
|
||||||
if (Instant.now().isAfter(list.timestamp.plus(Duration.ofDays(14)))) {
|
if (Instant.now().isAfter(list.timestamp.plus(Duration.ofDays(3)))) {
|
||||||
getListFromApi();
|
getListFromApi();
|
||||||
saveListToFile();
|
saveListToFile();
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ public class SteamAppsListCache {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SteamApp searchGame(String name) {
|
public SteamApp findGame(String name) {
|
||||||
for (SteamApp app : list.steamAppsList) {
|
for (SteamApp app : list.steamAppsList) {
|
||||||
if (app.getName().toLowerCase().contains(name.toLowerCase())) {
|
if (app.getName().toLowerCase().contains(name.toLowerCase())) {
|
||||||
return app;
|
return app;
|
||||||
@ -91,15 +92,7 @@ public class SteamAppsListCache {
|
|||||||
private void getListFromFile() {
|
private void getListFromFile() {
|
||||||
try {
|
try {
|
||||||
BufferedReader fIn = new BufferedReader(new FileReader(cacheFile));
|
BufferedReader fIn = new BufferedReader(new FileReader(cacheFile));
|
||||||
StringBuilder content = new StringBuilder();
|
String json = fIn.lines().collect(Collectors.joining());
|
||||||
String line;
|
|
||||||
|
|
||||||
while ((line = fIn.readLine()) != null) {
|
|
||||||
content.append(line);
|
|
||||||
//content.append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
String json = content.toString();
|
|
||||||
final Type type = new TypeToken<SteamAppsList>() {}.getType();
|
final Type type = new TypeToken<SteamAppsList>() {}.getType();
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
list = gson.fromJson(json, type);
|
list = gson.fromJson(json, type);
|
||||||
|
Loading…
Reference in New Issue
Block a user