Updated included CreamAPI to 4.4.0.0

Error message at launch if CreamAPI DLLs are missing in the folder
Other Improvements
This commit is contained in:
Jeddunk 2020-05-10 14:57:51 +02:00
parent f2b289f8c5
commit 85bd3179b4
7 changed files with 68 additions and 38 deletions

View File

@ -2,6 +2,8 @@
<project version="4"> <project version="4">
<component name="Encoding"> <component name="Encoding">
<file url="file://$PROJECT_DIR$" charset="UTF-8" /> <file url="file://$PROJECT_DIR$" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" /> <file url="PROJECT" charset="UTF-8" />
</component> </component>
</project> </project>

View File

@ -4,11 +4,13 @@ import javafx.collections.FXCollections;
import javafx.concurrent.Service; import javafx.concurrent.Service;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.commons.configuration2.ex.ConfigurationException;
import org.jsoup.HttpStatusException;
import pojo.App; import pojo.App;
import util.CreamApiConfig; import util.CreamApiConfig;
import util.CreamApiDllHandler; import util.CreamApiDllHandler;
@ -26,9 +28,23 @@ import java.util.Objects;
public class Controller { public class Controller {
private static final String REGEX = "(?<steamApiDll>steam_api(?:64)?.dll)$"; private static final String REGEX = "(?<steamApiDll>steam_api(?:64)?.dll)$";
private CreamApiDllHandler handler = CreamApiDllHandler.getInstance(); private CreamApiDllHandler handler = null;
private CreamApiConfig config = CreamApiConfig.getInstance(); {
private SteamAppsListCache cache = new SteamAppsListCache(); try {
handler = CreamApiDllHandler.getInstance();
} catch (IOException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("CreamAPI DLLs missing!");
alert.setHeaderText("CreamAPI DLL files can't be found!");
alert.setContentText("Please download CreamAPI and extract the non-log " +
"version in the same folder as Auto-CreamAPI!\nThe program will now close.");
alert.showAndWait();
System.exit(10);
}
}
private final CreamApiConfig config = CreamApiConfig.getInstance();
private final SteamAppsListCache cache = new SteamAppsListCache();
@FXML @FXML
public Label state_label; public Label state_label;
@FXML @FXML
@ -69,6 +85,7 @@ public class Controller {
generate_tooltips(); generate_tooltips();
fix_dlc_textarea_prompt_text(); fix_dlc_textarea_prompt_text();
reset(true); reset(true);
state_label.setText("Ready.");
} }
private void read() { private void read() {
@ -148,8 +165,10 @@ public class Controller {
config.sync(); config.sync();
} catch (IOException | ConfigurationException e) { } catch (IOException | ConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
cancel();
} catch (NullPointerException e) { } catch (NullPointerException e) {
System.err.println("No configuration file set!"); System.err.println("No configuration file set!");
cancel();
} }
return null; return null;
} }
@ -164,6 +183,10 @@ public class Controller {
setDisableAllButtons(false); setDisableAllButtons(false);
state_label.setText("Saved successfully!"); state_label.setText("Saved successfully!");
}); });
s.setOnCancelled(event -> {
setDisableAllButtons(false);
state_label.setText("Could not save configuration file!");
});
s.start(); s.start();
} }
@ -192,10 +215,20 @@ public class Controller {
return new Task<Void>() { return new Task<Void>() {
@Override @Override
protected Void call() { protected Void call() {
try {
Map<Number, String> collect = cache.getDlcMap(appId_textfield.getText()); Map<Number, String> collect = cache.getDlcMap(appId_textfield.getText());
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
collect.forEach((k, v) -> sb.append(k).append("=").append(v).append("\n")); collect.forEach((k, v) -> sb.append(k).append("=").append(v).append("\n"));
dlc_textarea.setText(sb.toString()); dlc_textarea.setText(sb.toString());
} catch (HttpStatusException e) {
if (e.getStatusCode() == 404) {
System.err.println("App ID empty or not found! (HTTP Status Code: 404)");
}
cancel();
} catch (IOException e) {
e.printStackTrace();
cancel();
}
return null; return null;
} }
}; };
@ -209,6 +242,10 @@ public class Controller {
setDisableAllButtons(false); setDisableAllButtons(false);
state_label.setText("Got list of DLCs successfully!"); state_label.setText("Got list of DLCs successfully!");
}); });
s.setOnCancelled(event -> {
setDisableAllButtons(false);
state_label.setText("Could not get list of DLCs!");
});
s.start(); s.start();
} }
@ -225,6 +262,7 @@ public class Controller {
path_textfield.setText(file.getParent()); path_textfield.setText(file.getParent());
steamApiPathString = file.getAbsolutePath(); steamApiPathString = file.getAbsolutePath();
reset(true); reset(true);
state_label.setText("Ready.");
} catch (ConfigurationException | IOException e) { } catch (ConfigurationException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -20,8 +20,8 @@ public class CreamApiConfig {
private Boolean unlockAll; private Boolean unlockAll;
private Boolean extraProtection; private Boolean extraProtection;
private Boolean forceOffline; private Boolean forceOffline;
private Map<Integer, String> dlc = new HashMap<>(); private final Map<Integer, String> dlc = new HashMap<>();
private List<String> languages = new ArrayList<>(); private final List<String> languages = new ArrayList<>();
private CreamApiConfig() { private CreamApiConfig() {
try { try {
@ -35,7 +35,7 @@ public class CreamApiConfig {
File langFile = new File("languages.txt"); File langFile = new File("languages.txt");
try { try {
BufferedReader fIn = new BufferedReader(new FileReader(langFile)); BufferedReader fIn = new BufferedReader(new FileReader(langFile));
fIn.lines().filter(line -> !line.isEmpty() && !line.startsWith("#")).forEach(line -> languages.add(line)); fIn.lines().filter(line -> !line.isEmpty() && !line.startsWith("#")).forEach(languages::add);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -15,24 +15,14 @@ public class CreamApiDllHandler {
private final String steamApiDllMd5; private final String steamApiDllMd5;
private final String steamApi64DllMd5; private final String steamApi64DllMd5;
private CreamApiDllHandler() { private CreamApiDllHandler() throws IOException {
String steamApiDllMd5 = ""; String steamApiDllMd5 = DigestUtils.md5Hex(Files.newInputStream(steamApiDllPath));
String steamApi64DllMd5 = ""; String steamApi64DllMd5 = DigestUtils.md5Hex(Files.newInputStream(steamApi64DllPath));
try {
steamApiDllMd5 = DigestUtils.md5Hex(Files.newInputStream(steamApiDllPath));
} catch (IOException e) {
System.err.println("File missing: " + steamApiDllPath.toAbsolutePath().toString());
}
try {
steamApi64DllMd5 = DigestUtils.md5Hex(Files.newInputStream(steamApi64DllPath));
} catch (IOException e) {
System.err.println("File missing: " + steamApi64DllPath.toAbsolutePath().toString());
}
this.steamApiDllMd5 = steamApiDllMd5; this.steamApiDllMd5 = steamApiDllMd5;
this.steamApi64DllMd5 = steamApi64DllMd5; this.steamApi64DllMd5 = steamApi64DllMd5;
} }
public static synchronized CreamApiDllHandler getInstance() { public static synchronized CreamApiDllHandler getInstance() throws IOException {
if (creamApiDllHandlerInstance == null) { if (creamApiDllHandlerInstance == null) {
creamApiDllHandlerInstance = new CreamApiDllHandler(); creamApiDllHandlerInstance = new CreamApiDllHandler();
} }

View File

@ -4,7 +4,6 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import kong.unirest.HttpResponse; import kong.unirest.HttpResponse;
import kong.unirest.Unirest; import kong.unirest.Unirest;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -26,29 +25,31 @@ import java.util.stream.Collectors;
public class SteamAppsListCache { public class SteamAppsListCache {
private SteamAppsList list = new SteamAppsList(); private SteamAppsList list = new SteamAppsList();
private File cacheFile = new File("steamapps.json"); private final File cacheFile = new File("steamapps.json");
private MainEnv env; private MainEnv env;
//private String key; //private String key;
public SteamAppsListCache() { public SteamAppsListCache() {
try { try {
Class envDefault = Class.forName("util.env.Default"); Class<?> envDefault = Class.forName("util.env.Default");
env = (MainEnv) envDefault.newInstance(); env = (MainEnv) envDefault.newInstance();
//System.out.println(env.getKey()); // System.out.println(env.getKey());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
env = new MainEnv(); env = new MainEnv();
} catch (IllegalAccessException | InstantiationException e) { } catch (IllegalAccessException | InstantiationException e) {
// Only thrown by newInstance() // Only thrown by newInstance()
e.printStackTrace(); e.printStackTrace();
} }
boolean fileFound = true; //boolean fileFound = true;
try { try {
getListFromFile(); getListFromFile();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
System.err.println("File does not exist, trying to create steamapps.json for the first time..."); System.err.println("File does not exist, trying to create steamapps.json for the first time...");
fileFound = false; //fileFound = false;
sync();
} }
if (!fileFound || Instant.now().isAfter(list.getTimestamp().plus(Duration.ofDays(3)))) { if (Instant.now().isAfter(list.getTimestamp().plus(Duration.ofDays(3)))) {
System.err.println("List in file is not recent!");
sync(); sync();
} }
} }
@ -89,6 +90,7 @@ public class SteamAppsListCache {
} }
private void getListFromApi() { private void getListFromApi() {
System.out.println("Trying to get SteamAppList from API...");
List<App> apps = getApps(); List<App> apps = getApps();
list.setTimestamp(Instant.now()); list.setTimestamp(Instant.now());
list.setSteamAppsList(apps); list.setSteamAppsList(apps);
@ -104,23 +106,27 @@ public class SteamAppsListCache {
} }
private void saveListToFile() throws IOException { private void saveListToFile() throws IOException {
System.out.println("Trying to save SteamAppList to file (" + cacheFile.getAbsolutePath() + ")...");
Gson gson = new Gson(); Gson gson = new Gson();
String jsonString = gson.toJson(list); String jsonString = gson.toJson(list);
BufferedWriter fOut = new BufferedWriter(new FileWriter(cacheFile)); BufferedWriter fOut = new BufferedWriter(new FileWriter(cacheFile));
fOut.write(jsonString); fOut.write(jsonString);
fOut.close(); fOut.close();
System.out.println("Successfully saved SteamAppList to file (" + cacheFile.getAbsolutePath() + ")...");
} }
private void getListFromFile() throws FileNotFoundException { private void getListFromFile() throws FileNotFoundException {
System.out.println("Trying to get SteamAppList from file (" + cacheFile.getAbsolutePath() + ")...");
BufferedReader fIn = new BufferedReader(new FileReader(cacheFile)); BufferedReader fIn = new BufferedReader(new FileReader(cacheFile));
String json = fIn.lines().collect(Collectors.joining()); String json = fIn.lines().collect(Collectors.joining());
final Type type = new TypeToken<SteamAppsList>() { final Type type = new TypeToken<SteamAppsList>() {
}.getType(); }.getType();
Gson gson = new Gson(); Gson gson = new Gson();
list = gson.fromJson(json, type); list = gson.fromJson(json, type);
System.out.println("Successfully got SteamAppList from file (" + cacheFile.getAbsolutePath() + ")...");
} }
public LinkedHashMap<Number, String> getDlcMap(String appId) { public LinkedHashMap<Number, String> getDlcMap(String appId) throws IOException{
Map<Integer, String> steamStoreDLCs = new HashMap<>(); Map<Integer, String> steamStoreDLCs = new HashMap<>();
Map<Integer, String> steamDbDLCs = new HashMap<>(); Map<Integer, String> steamDbDLCs = new HashMap<>();
//StringBuilder sb = new StringBuilder(); //StringBuilder sb = new StringBuilder();
@ -152,12 +158,6 @@ public class SteamAppsListCache {
} }
steamDbDLCs.put(Integer.parseInt(dlc_id), dlc_name); steamDbDLCs.put(Integer.parseInt(dlc_id), dlc_name);
} }
} catch (HttpStatusException e) {
if (e.getStatusCode() == 404) {
System.err.println("App ID empty or not found! (HTTP Status Code: 404)");
}
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) { } catch (NullPointerException e) {
// ignore // ignore
} }

Binary file not shown.

Binary file not shown.