commit aa057fca910c45d9a3b6ede7fceab217fc757a9c Author: Jeddunk Date: Mon Nov 4 06:32:24 2019 +0100 init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0dc5435 --- /dev/null +++ b/.gitignore @@ -0,0 +1,159 @@ +# Created by https://www.gitignore.io/api/java,maven,windows,intellij +# Edit at https://www.gitignore.io/?templates=java,maven,windows,intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/**/sonarlint/ + +# SonarQube Plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator/ + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/java,maven,windows,intellij + +cream_api.ini +steamapps.json diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..f18f631 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..7aa4d2c --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..cc10d56 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1,2 @@ +Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided. + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..c0bce70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..62f90ed --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a3c549e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/auto-cream-api.iml b/auto-cream-api.iml new file mode 100644 index 0000000..81ae37b --- /dev/null +++ b/auto-cream-api.iml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f5203f2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + xyz.jeddunk + auto-cream-api + 1.0-SNAPSHOT + + + UTF-8 + 1.8 + 1.8 + + + + + + maven-jar-plugin + 2.4 + + + src/main/resources/META-INF/MANIFEST.MF + + + + + maven-assembly-plugin + 2.2-beta-5 + + + + Main + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + + + com.jfoenix + jfoenix + 8.0.8 + compile + + + + org.apache.commons + commons-configuration2 + 2.6 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + com.ibasco.agql + agql-steam-webapi + 0.1.7 + + + de.jensd + fontawesomefx-commons + 8.15 + compile + + + de.jensd + fontawesomefx-fontawesome + 4.7.0-5 + compile + + + \ No newline at end of file diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java new file mode 100644 index 0000000..92338ef --- /dev/null +++ b/src/main/java/Controller.java @@ -0,0 +1,162 @@ +import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamApp; +import com.jfoenix.controls.*; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.control.Tooltip; +import javafx.stage.FileChooser; +import org.apache.commons.configuration2.ex.ConfigurationException; + +import javax.swing.*; +import java.io.File; +import java.io.IOException; + +public class Controller { + public JFXButton path_button; + private CreamApiConfig config = CreamApiConfig.getInstance(); + private SteamAppsListCache cache = new SteamAppsListCache(); + @FXML public JFXTextField path_textfield; + @FXML public JFXTextField appId_textfield; + @FXML public JFXTextField game_name_textfield; + @FXML public JFXComboBox language_combobox; + @FXML public JFXTextArea dlc_textarea; + @FXML public JFXCheckBox extra_protection_checkbox; + @FXML public JFXCheckBox offline_checkbox; + @FXML public JFXCheckBox unlock_all_checkbox; + @FXML public JFXButton reset_button; + @FXML public JFXButton save_button; + @FXML public JFXButton getAppId_button; + + public Controller() {} + + @FXML + public void initialize() { + read(); + generate_tooltips(); + fix_dlc_textarea_prompt_text(); + } + + private void read() { + appId_textfield.setText(config.getAppId().toString()); + dlc_textarea.setText(config.getDlcListAsString()); + game_name_textfield.setText(cache.getGame(config.getAppId()).getName()); + extra_protection_checkbox.setSelected(config.getExtraProtection()); + offline_checkbox.setSelected(config.getForceOffline()); + unlock_all_checkbox.setSelected(config.getUnlockAll()); + language_combobox.setItems(FXCollections.observableArrayList(config.getLanguages())); + language_combobox.getSelectionModel().select(config.getLanguage()); + unlockAll_disableDlcTextArea(); + } + + private void fix_dlc_textarea_prompt_text() { + dlc_textarea.setPromptText("List of DLC...\r0000 = DLC Name"); + } + + private void generate_tooltips() { + Tooltip extra_protection_tooltip = new Tooltip("\"extra protection\""); + extra_protection_checkbox.setTooltip(extra_protection_tooltip); + Tooltip.install(extra_protection_checkbox, extra_protection_tooltip); + } + + public void reset() { + config.read(); + read(); + } + + public void save() { + config.setDlcListFromString(dlc_textarea.getText()); + config.setAppId(Integer.parseInt(appId_textfield.getText())); + config.setExtraProtection(extra_protection_checkbox.isSelected()); + config.setForceOffline(offline_checkbox.isSelected()); + config.setUnlockAll(unlock_all_checkbox.isSelected()); + config.setLanguage(language_combobox.getValue()); + try { + config.sync(); + } catch (ConfigurationException e) { + e.printStackTrace(); + } + } + + public void getAppId() { + final SteamApp game = cache.getGame(game_name_textfield.getText()); + if (game == null) { + appId_textfield.setText("-1"); + } else { + appId_textfield.setText(String.valueOf(game.getAppid())); + } + } + + public void unlockAll_disableDlcTextArea() { + dlc_textarea.setDisable(unlock_all_checkbox.isSelected()); + } + + public void getDlcList() { + // https://github.com/Sak32009/GetDLCInfoFromSteamDB/blob/master/sak32009-get-dlc-info-from-steamdb.user.js + /*async getData() { + // CHECK IF THE APPID HAS DLCs + if (!$("#dlc").length) { + return false; + } + // SELF + const self = this; + // SET APPID + this.steamDB.appID = $(".scope-app[data-appid]").data("appid"); + // SET APPID NAME + this.steamDB.appIDName = $("td[itemprop='name']").text(); + // GET APPID DLCS FROM TAB + $("tr.app[data-appid]").each((_index, _values) => { + const $this = $(_values); + const appID = $this.data("appid"); + const appIDName = $this.find(`td:nth-of-type(2)`).text().trim(); + // ADD DATA + self.steamDB.appIDDLCs[appID] = { + name: appIDName + }; + // +1 + self.steamDB.appIDDLCsCount += 1; + }); + // GET APPID DLCS FROM REQUEST + await this.getHttpRequest(`${self.info.steamDBLinked + this.steamDB.appID}`, ({ + responseText + }) => { + // APPS + const $apps = $($.parseHTML(responseText)).find("tr.app[data-appid]"); + // FETCH APPS + $apps.each((_index, _values) => { + const $this = $(_values); + const appID = $this.attr("data-appid"); + const appIDType = $this.find("td:nth-of-type(2)").text().trim(); + const appIDName = $this.find("td:nth-of-type(3)").text().trim(); + // CHECK IF EXISTS + if (!(appID in self.steamDB.appIDDLCs) && appIDType === "DLC") { + // ADD DATA + self.steamDB.appIDDLCs[appID] = { + name: appIDName + }; + // +1 + self.steamDB.appIDDLCsCount += 1; + } + }); + // RUN + self.start(); + }); + }*/ + } + + public void openFileChooser(ActionEvent event) { + FileChooser chooser = new FileChooser(); + chooser.setTitle("Choose steam_api(64).dll..."); + FileChooser.ExtensionFilter filter = + new FileChooser.ExtensionFilter("steam_api(64).dll", + "steam_api.dll", "steam_api64.dll"); + chooser.getExtensionFilters().add(filter); + final File file = chooser.showOpenDialog(path_button.getScene().getWindow()); + try { + config.setConfig(file.getParent() + "\\cream_api.ini"); + path_textfield.setText(file.getParent()); + } catch (ConfigurationException | IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/CreamApiConfig.java b/src/main/java/CreamApiConfig.java new file mode 100644 index 0000000..c511fbe --- /dev/null +++ b/src/main/java/CreamApiConfig.java @@ -0,0 +1,200 @@ +import org.apache.commons.configuration2.INIConfiguration; +import org.apache.commons.configuration2.SubnodeConfiguration; +import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; +import org.apache.commons.configuration2.builder.fluent.Configurations; +import org.apache.commons.configuration2.ex.ConfigurationException; + +import java.io.File; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.*; + +@SuppressWarnings("WeakerAccess") +public class CreamApiConfig { + private static CreamApiConfig configInstance; + private static final Configurations CONFIGS = new Configurations(); + + private INIConfiguration config; + private String path = "cream_api.ini"; + //private Ini ini; + private Integer appId; + private String language; + private Boolean unlockAll; + private Boolean extraProtection; + private Boolean forceOffline; + private Map dlc = new HashMap<>(); + private List languages = new ArrayList<>(); + + private CreamApiConfig() { + try { + config = CONFIGS.ini(path); + config.setCommentLeadingCharsUsedInInput(";"); + } catch (ConfigurationException e) { + e.printStackTrace(); + } + /*try { + //ini = new Ini(new File("cream_api.ini")); + //Config iniConfig = Config.getGlobal().clone(); + } catch (IOException e) { + System.err.println("Can't open \"cream_api.ini\"!"); + 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(); + } + + public static synchronized CreamApiConfig getInstance() { + if (configInstance == null) { + configInstance = new CreamApiConfig(); + } + return configInstance; + } + + 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 dlc_temp = ini.get("dlc"); + for (Map.Entry e: dlc_temp.entrySet()) + dlc.put(Integer.parseInt(e.getKey()), e.getValue());*/ + appId = config.getInt("steam.appid"); + language = config.getString("steam.language"); + if (language == null) { + language = "english"; + } + unlockAll = config.getBoolean("steam.unlockall"); + extraProtection = config.getBoolean("steam.extraprotection"); + forceOffline = config.getBoolean("steam.forceoffline"); + final SubnodeConfiguration dlc_section = config.getSection("dlc"); + for (Iterator it = dlc_section.getKeys(); it.hasNext(); ) { + String k = it.next(); + final String v = dlc_section.getString(k); + dlc.put(Integer.parseInt(k), v); + } + } + + 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 e: dlc.entrySet()) { + ini.put("dlc", e.getKey().toString(), e.getValue()); + } + ini.store();*/ + FileBasedConfigurationBuilder builder = CONFIGS.iniBuilder(path); + config = builder.getConfiguration(); + config.setCommentLeadingCharsUsedInInput(";"); + + config.setProperty("steam.appid", appId); + config.setProperty("steam.language", language); + config.setProperty("steam.unlockall", unlockAll); + config.setProperty("steam.extraprotection", extraProtection); + config.setProperty("steam.forceoffline", forceOffline); + final SubnodeConfiguration dlc_section = config.getSection("dlc"); + dlc_section.clear(); + for (Map.Entry e : this.dlc.entrySet()) { + config.setProperty("dlc." + e.getKey().toString(), e.getValue()); + } + + builder.save(); + } + + // DLC list parsing + + public String getDlcListAsString() { + StringBuilder sb = new StringBuilder(); + for (Map.Entry e: dlc.entrySet()) { + sb.append(e.getKey()); + sb.append("="); + sb.append(e.getValue()); + sb.append("\r\n"); + } + return sb.toString(); + } + + public void setDlcListFromString(String str) { + dlc.clear(); + final String[] lines = str.split("\\R+"); + for (String line : lines) { + final String[] split = line.split("\\s*=\\s*", 2); + if (split.length == 2) dlc.put(Integer.parseInt(split[0]), split[1]); + else System.err.println(MessageFormat.format("Error while splitting line: \"{0}\"", line)); + } + } + + // GETTERS AND SETTERS + + public Integer getAppId() { + return appId; + } + + public void setAppId(Integer appId) { + this.appId = appId; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public Boolean getUnlockAll() { + return unlockAll; + } + + public void setUnlockAll(Boolean unlockAll) { + this.unlockAll = unlockAll; + } + + public Boolean getExtraProtection() { + return extraProtection; + } + + public void setExtraProtection(Boolean extraProtection) { + this.extraProtection = extraProtection; + } + + public Boolean getForceOffline() { + return forceOffline; + } + + public void setForceOffline(Boolean forceOffline) { + this.forceOffline = forceOffline; + } + + public List getLanguages() { + return languages; + } + + public void setConfig(String path) throws ConfigurationException, IOException { + File file = new File(path); + if (!file.exists()) { + final boolean newFile = file.createNewFile(); + } + this.config = CONFIGS.ini(path); + this.config.setCommentLeadingCharsUsedInInput(";"); + this.path = path; + } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..3974de4 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,23 @@ +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Main extends Application { + + @Override + public void start(Stage primaryStage) throws Exception{ + Parent root = FXMLLoader.load(ClassLoader.getSystemResource("mainWindow.fxml"));//getClass().getResource("/mainWindow.fxml") + primaryStage.setTitle("Auto CreamAPI"); + primaryStage.setMinWidth(655 + 25); + primaryStage.setMinHeight(360 + 50); + primaryStage.setScene(new Scene(root, 1200, 600)); + primaryStage.show(); + } + + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/main/java/SteamAppsListCache.java b/src/main/java/SteamAppsListCache.java new file mode 100644 index 0000000..dd57a86 --- /dev/null +++ b/src/main/java/SteamAppsListCache.java @@ -0,0 +1,101 @@ +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.ibasco.agql.protocols.valve.steam.webapi.SteamWebApiClient; +import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamApps; +import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamApp; + +import java.io.*; +import java.lang.reflect.Type; +import java.text.MessageFormat; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("WeakerAccess") +public class SteamAppsListCache { + + static class SteamAppsList { + Instant timestamp; + List steamAppsList; + } + + private SteamAppsList list = new SteamAppsList(); + private File cacheFile = new File("steamapps.json"); + + public SteamAppsListCache() { + getListFromFile(); + if (Instant.now().isAfter(list.timestamp.plus(Duration.ofDays(14)))) { + getListFromApi(); + saveListToFile(); + } + } + + public SteamApp getGame (int appId) { + for (SteamApp app : list.steamAppsList) { + if (app.getAppid() == appId) { + return app; + } + } + return null; + } + + public SteamApp getGame (String name) { + for (SteamApp app : list.steamAppsList) { + if (app.getName().equalsIgnoreCase(name)) { + return app; + } + } + return null; + } + + private void getListFromApi() { + SteamWebApiClient client = new SteamWebApiClient(); + SteamApps steamApps = new SteamApps(client); + /*SteamStorefront storefront = new SteamStorefront(client); + StoreAppDetails appDetails = storefront.getAppDetails(440).exceptionally(throwable -> { + System.err.println(MessageFormat.format("Error Occurred: {}", throwable)); + return new StoreAppDetails(); + }).join(); + System.out.println(appDetails); + Gson gson = new Gson(); + System.out.println(gson.toJson(appDetails));*/ + list.timestamp = Instant.now(); + list.steamAppsList = steamApps.getAppList().exceptionally(throwable -> { + System.err.println(MessageFormat.format("Error Occurred: {}", throwable)); + return new ArrayList<>(); + }).join(); + } + + private void saveListToFile() { + Gson gson = new Gson(); + String jsonString = gson.toJson(list); + try { + BufferedWriter fOut = new BufferedWriter(new FileWriter(cacheFile)); + fOut.write(jsonString); + fOut.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void getListFromFile() { + try { + BufferedReader fIn = new BufferedReader(new FileReader(cacheFile)); + StringBuilder content = new StringBuilder(); + String line; + + while ((line = fIn.readLine()) != null) { + content.append(line); + //content.append(System.lineSeparator()); + } + + String json = content.toString(); + final Type type = new TypeToken() {}.getType(); + Gson gson = new Gson(); + list = gson.fromJson(json, type); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3e22e7e --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1 @@ +Main-Class: Main diff --git a/src/main/resources/mainWindow.fxml b/src/main/resources/mainWindow.fxml new file mode 100644 index 0000000..32f59ec --- /dev/null +++ b/src/main/resources/mainWindow.fxml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +