From ebe72c8cdde2d143b7b31746a67d376c59796331 Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Sun, 21 Sep 2025 23:13:01 +0200 Subject: [PATCH 01/11] Add steam launch options --- src-tauri/src/lib.rs | 1 + src-tauri/src/profile/launch/commands.rs | 84 ++- src-tauri/src/profile/launch/mod.rs | 18 +- src-tauri/src/profile/launch/platform.rs | 48 ++ src-tauri/src/util/mod.rs | 1 + src-tauri/src/util/vdf_parser/LICENSE | 504 ++++++++++++++++++ .../src/util/vdf_parser/appinfo_vdf_parser.rs | 129 +++++ src-tauri/src/util/vdf_parser/mod.rs | 9 + src-tauri/src/util/vdf_parser/reader.rs | 341 ++++++++++++ src-tauri/src/util/vdf_parser/vdf_reader.rs | 74 +++ src-tauri/src/util/vdf_parser/vdf_structs.rs | 102 ++++ src/lib/api/profile/launch.ts | 4 +- .../dialogs/LaunchOptionsDialog.svelte | 87 +++ src/lib/components/toolbar/Toolbar.svelte | 43 +- src/lib/types.ts | 27 + 15 files changed, 1467 insertions(+), 5 deletions(-) create mode 100644 src-tauri/src/util/vdf_parser/LICENSE create mode 100644 src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs create mode 100644 src-tauri/src/util/vdf_parser/mod.rs create mode 100644 src-tauri/src/util/vdf_parser/reader.rs create mode 100644 src-tauri/src/util/vdf_parser/vdf_reader.rs create mode 100644 src-tauri/src/util/vdf_parser/vdf_structs.rs create mode 100644 src/lib/components/dialogs/LaunchOptionsDialog.svelte diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 434ed5cc..bcd0a223 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -132,6 +132,7 @@ pub fn run() { profile::launch::commands::launch_game, profile::launch::commands::get_launch_args, profile::launch::commands::open_game_dir, + profile::launch::commands::get_steam_launch_options, profile::install::commands::install_all_mods, profile::install::commands::install_mod, profile::install::commands::cancel_all_installs, diff --git a/src-tauri/src/profile/launch/commands.rs b/src-tauri/src/profile/launch/commands.rs index c66bc494..e74ec429 100644 --- a/src-tauri/src/profile/launch/commands.rs +++ b/src-tauri/src/profile/launch/commands.rs @@ -1,11 +1,21 @@ use eyre::Context; use itertools::Itertools; +use serde::Serialize; use tauri::{command, AppHandle}; +use tracing::warn; use crate::{profile::sync, state::ManagerExt, util::cmd::Result}; +#[derive(Debug, Clone, Serialize)] +pub struct LaunchOption { + pub name: String, + pub arguments: String, + #[serde(rename = "type")] + pub launch_type: String, +} + #[command] -pub async fn launch_game(app: AppHandle) -> Result<()> { +pub async fn launch_game(app: AppHandle, args: Option) -> Result<()> { if app.lock_prefs().pull_before_launch { sync::pull_profile(false, &app).await?; } @@ -13,7 +23,7 @@ pub async fn launch_game(app: AppHandle) -> Result<()> { let prefs = app.lock_prefs(); let manager = app.lock_manager(); - manager.active_game().launch(&prefs, &app)?; + manager.active_game().launch_with_args(&prefs, &app, args)?; Ok(()) } @@ -43,3 +53,73 @@ pub fn open_game_dir(app: AppHandle) -> Result<()> { Ok(()) } + +#[command] +pub fn get_steam_launch_options(app: AppHandle) -> Result> { + let manager = app.lock_manager(); + let managed_game = manager.active_game(); + let game_name = &managed_game.game.name; + let Some(steam) = &managed_game.game.platforms.steam else { + return Err(eyre::eyre!("{} is not available on Steam", game_name).into()); + }; + let raw_options = super::platform::get_steam_launch_options(steam.id) + .context("failed to get Steam launch options")?; + + let mut launch_options = Vec::new(); + + if let Some(options_obj) = raw_options.as_object() { + for (_, option_value) in options_obj.iter() { + if let Some(option) = option_value.as_object() { + let option_type = option + .get("type") + .and_then(|t| t.as_str()) + .unwrap_or("undefined"); + + let arguments = option + .get("arguments") + .and_then(|a| a.as_str()) + .unwrap_or("") + .to_string(); + + let name = match option_type { + "none" | "default" => format!("Play {}", game_name), + "application" => format!("Launch {}", game_name), + "safemode" => format!("Launch {} in Safe Mode", game_name), + "multiplayer" => format!("Launch {} in Multiplayer Mode", game_name), + "config" => format!("Launch Controller Layout Tool"), + "vr" => format!("Launch {} in Steam VR Mode", game_name), + "server" => format!("Launch Dedicated Server"), + "editor" => format!("Launch Game Editor"), + "manual" => format!("Show Manual"), + "benchmark" => format!("Launch Benchmark Tool"), + "option1" | "option2" | "option3" => { + if let Some(description) = + option.get("description").and_then(|d| d.as_str()) + { + format!("Play {}", description) + } else { + format!("Play {} ({})", game_name, option_type) + } + } + "othervr" => format!("Launch {} in Oculus VR Mode", game_name), + "openvroverlay" => format!("Launch {} as Steam VR Overlay", game_name), + "osvr" => format!("Launch {} in OSVR Mode", game_name), + "openxr" => format!("Launch {} in OpenXR Mode", game_name), + // "dialog" => format!("Show {} Launch Options", game_name), // Idk what this is + _ => { + warn!("Undefined launch option type: {}", option_type); + format!("Launch {} ({})", game_name, option_type) + } + }; + + launch_options.push(LaunchOption { + name, + arguments, + launch_type: option_type.to_string(), + }); + } + } + } + + Ok(launch_options) +} diff --git a/src-tauri/src/profile/launch/mod.rs b/src-tauri/src/profile/launch/mod.rs index 57f6d0b5..df5354fc 100644 --- a/src-tauri/src/profile/launch/mod.rs +++ b/src-tauri/src/profile/launch/mod.rs @@ -41,12 +41,28 @@ pub enum LaunchMode { impl ManagedGame { pub fn launch(&self, prefs: &Prefs, app: &AppHandle) -> Result<()> { + self.launch_with_args(prefs, app, None) + } + + pub fn launch_with_args( + &self, + prefs: &Prefs, + app: &AppHandle, + args: Option, + ) -> Result<()> { let game_dir = locate_game_dir(self.game, prefs)?; if let Err(err) = self.copy_required_files(&game_dir) { warn!("failed to copy required files to game directory: {:#}", err); } - let (launch_mode, command) = self.launch_command(&game_dir, prefs)?; + let (launch_mode, mut command) = self.launch_command(&game_dir, prefs)?; + + if let Some(args) = args { + if !args.is_empty() { + command.args(args.split_whitespace()); + } + } + info!("launching {} with command {:?}", self.game.slug, command); do_launch(command, app, launch_mode)?; diff --git a/src-tauri/src/profile/launch/platform.rs b/src-tauri/src/profile/launch/platform.rs index 49a82626..32a34592 100644 --- a/src-tauri/src/profile/launch/platform.rs +++ b/src-tauri/src/profile/launch/platform.rs @@ -98,6 +98,54 @@ fn read_steam_registry() -> Result { Ok(PathBuf::from(path)) } +pub fn get_steam_launch_options(app_id: u32) -> Result { + let app_info = get_steam_app_info(app_id)?; + + app_info + .get("config") + .and_then(|config| config.get("launch")) + .cloned() + .ok_or_eyre(format!("No launch options found for app ID {}", app_id)) +} + +pub fn get_steam_app_info(app_id: u32) -> Result { + use crate::util::vdf_parser::appinfo_vdf_parser::open_appinfo_vdf; + use serde_json::{Map, Value}; + + let steam_binary = find_steam_binary()?; + let steam_path = steam_binary + .parent() + .ok_or_eyre("Steam binary has no parent directory")?; + + let appinfo_path = steam_path.join("appcache").join("appinfo.vdf"); + + ensure!( + appinfo_path.exists(), + "Steam appinfo.vdf not found at {}", + appinfo_path.display() + ); + + info!("Reading Steam app info from {}", appinfo_path.display()); + + let appinfo_vdf: Map = open_appinfo_vdf(&appinfo_path); + + let entries = appinfo_vdf + .get("entries") + .and_then(|e| e.as_array()) + .ok_or_eyre("No entries found in appinfo.vdf")?; + + entries + .iter() + .find(|entry| { + entry + .get("appid") + .and_then(|id| id.as_u64()) + .map_or(false, |id| id == app_id as u64) + }) + .cloned() + .ok_or_eyre(format!("App ID {} not found in Steam appinfo.vdf", app_id)) +} + fn epic_command(game: Game) -> Result { let Some(epic) = &game.platforms.epic_games else { bail!("{} is not available on Epic Games", game.name) diff --git a/src-tauri/src/util/mod.rs b/src-tauri/src/util/mod.rs index 30e53ba2..f6ddd5c6 100644 --- a/src-tauri/src/util/mod.rs +++ b/src-tauri/src/util/mod.rs @@ -6,6 +6,7 @@ pub mod cmd; pub mod error; pub mod fs; pub mod path; +pub mod vdf_parser; pub mod window; pub mod zip; diff --git a/src-tauri/src/util/vdf_parser/LICENSE b/src-tauri/src/util/vdf_parser/LICENSE new file mode 100644 index 00000000..5f757420 --- /dev/null +++ b/src-tauri/src/util/vdf_parser/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! \ No newline at end of file diff --git a/src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs b/src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs new file mode 100644 index 00000000..4346bc64 --- /dev/null +++ b/src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs @@ -0,0 +1,129 @@ +/* + * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 + * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details + */ + +use std::i64; +use std::io::Read; +use std::{fs, path::PathBuf}; + +use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; +use serde_json::{Map, Value}; + +use super::reader::Reader; +use super::vdf_reader::read_entry_map; + +/// Opens the appinfo.vdf file and returns the values as JSON. +pub fn open_appinfo_vdf(path: &PathBuf) -> Map { + let mut file = fs::File::open(path).expect("Path should have existed."); + let metadata = fs::metadata(path).expect("Unable to read metadata."); + + let mut buffer = Vec::with_capacity(metadata.len() as usize); + file.read_to_end(&mut buffer).expect("Buffer overflow."); + + let mut reader = Reader::new(&buffer); + + return read(&mut reader); +} + +/// Reads the appinfo.vdf file and returns the values as JSON. +fn read(reader: &mut Reader) -> Map { + let magic = reader.read_uint32(true); + let _universe = reader.read_uint32(true); //always 1 + + let entries: Vec; + + if magic == 0x07564429 { + let string_table_offset = reader.read_int64(true); + let data_offset = reader.get_offset(); + + reader.seek( + string_table_offset + .try_into() + .expect("String table offset couldn't be converted to usize"), + 0, + ); + + let string_count = reader.read_uint32(true) as usize; + let mut strings = Vec::with_capacity(string_count); + + for _ in 0..string_count { + strings.push(reader.read_string(None)); + } + + reader.seek(data_offset, 0); + + entries = read_app_sections( + reader, + Some(string_table_offset), + Some(magic), + &Some(&mut strings), + ); + } else if magic == 0x07564428 { + entries = read_app_sections(reader, None, None, &None); + } else { + panic!("Magic header is unknown. Expected 0x07564428 or 0x07564429 but got {magic}"); + } + + let mut res: Map = Map::new(); + res.insert(String::from("entries"), Value::Array(entries)); + + return res; +} + +struct AppInfoChunk { + pub offset: usize, + pub length: usize, +} + +/// Reads the appinfo.vdf app sections to a JSON array. +fn read_app_sections( + reader: &mut Reader, + string_table_offset: Option, + magic: Option, + strings: &Option<&mut Vec>, +) -> Vec { + let mut id = reader.read_uint32(true); + let eof = string_table_offset.unwrap_or(i64::MAX) as usize - 4; + + let mut chunks = Vec::new(); + + while id != 0 && reader.get_offset() < eof { + let chunk_size = reader.read_uint32(true); + let offset = reader.get_offset(); + let chunk_length: usize = chunk_size.try_into().unwrap(); + + chunks.push(AppInfoChunk { + offset, + length: chunk_length, + }); + + reader.seek(offset + chunk_length, 0); + id = reader.read_uint32(true); + } + + let entries: Vec = chunks + .par_iter() + .filter_map(|chunk| { + let mut chunk_reader = reader.slice(chunk.offset, chunk.length); + chunk_reader.seek(60, 1); + + let mut entry: Map = read_entry_map(&mut chunk_reader, magic, strings); + + if entry.contains_key("appinfo") { + let appinfo_val: &Value = entry + .get("appinfo") + .expect("Should have been able to get \"appinfo\"."); + let appinfo = appinfo_val + .as_object() + .expect("appinfo should have been an object."); + + entry = appinfo.clone(); + } + + return Some(Value::Object(entry)); + }) + .collect(); + + return entries; +} diff --git a/src-tauri/src/util/vdf_parser/mod.rs b/src-tauri/src/util/vdf_parser/mod.rs new file mode 100644 index 00000000..0b9a45cb --- /dev/null +++ b/src-tauri/src/util/vdf_parser/mod.rs @@ -0,0 +1,9 @@ +/* + * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 + * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details + */ + +pub mod appinfo_vdf_parser; +mod reader; +mod vdf_reader; +mod vdf_structs; diff --git a/src-tauri/src/util/vdf_parser/reader.rs b/src-tauri/src/util/vdf_parser/reader.rs new file mode 100644 index 00000000..6eed06df --- /dev/null +++ b/src-tauri/src/util/vdf_parser/reader.rs @@ -0,0 +1,341 @@ +/* + * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 + * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details + */ + +trait HasByteConvert { + fn from_le_bytes(bytes: &[u8], offset: usize) -> Self; + fn from_be_bytes(bytes: &[u8], offset: usize) -> Self; +} + +impl HasByteConvert for u8 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> u8 { + return bytes[offset]; + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> u8 { + return bytes[offset]; + } +} + +impl HasByteConvert for u16 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> u16 { + return u16::from_le_bytes( + bytes[offset..offset + 2] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> u16 { + return u16::from_be_bytes( + bytes[offset..offset + 2] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for u32 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> u32 { + return u32::from_le_bytes( + bytes[offset..offset + 4] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> u32 { + return u32::from_be_bytes( + bytes[offset..offset + 4] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for u64 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> u64 { + return u64::from_le_bytes( + bytes[offset..offset + 8] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> u64 { + return u64::from_be_bytes( + bytes[offset..offset + 8] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for i8 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> i8 { + return i8::from_le_bytes( + bytes[offset..offset + 1] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> i8 { + return i8::from_be_bytes( + bytes[offset..offset + 1] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for i16 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> i16 { + return i16::from_le_bytes( + bytes[offset..offset + 2] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> i16 { + return i16::from_be_bytes( + bytes[offset..offset + 2] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for i32 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> i32 { + return i32::from_le_bytes( + bytes[offset..offset + 4] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> i32 { + return i32::from_be_bytes( + bytes[offset..offset + 4] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for i64 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> i64 { + return i64::from_le_bytes( + bytes[offset..offset + 8] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> i64 { + return i64::from_be_bytes( + bytes[offset..offset + 8] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for f32 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> f32 { + return f32::from_le_bytes( + bytes[offset..offset + 4] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> f32 { + return f32::from_be_bytes( + bytes[offset..offset + 4] + .try_into() + .expect("incorrect length"), + ); + } +} + +impl HasByteConvert for f64 { + fn from_le_bytes(bytes: &[u8], offset: usize) -> f64 { + return f64::from_le_bytes( + bytes[offset..offset + 8] + .try_into() + .expect("incorrect length"), + ); + } + fn from_be_bytes(bytes: &[u8], offset: usize) -> f64 { + return f64::from_be_bytes( + bytes[offset..offset + 8] + .try_into() + .expect("incorrect length"), + ); + } +} + +pub struct Reader<'a> { + data: &'a [u8], + offset: usize, + length: u64, +} + +#[allow(dead_code)] +impl Reader<'_> { + /// Gets the underlying data of the reader. + pub fn get_data(&self) -> &[u8] { + return self.data; + } + /// Gets the offset of the reader. + pub fn get_offset(&self) -> usize { + return self.offset; + } + /// Gets the length of the reader. + pub fn get_length(&self) -> u64 { + return self.length; + } + + /// Creates a new Reader from the provided buffer. + pub fn new(buf: &[u8]) -> Reader<'_> { + return Reader { + data: buf, + offset: 0, + length: buf.len() as u64, + }; + } + + /// Slices the Reader's buffer and returns a new Reader for the slice. + pub fn slice(&self, offset: usize, length: usize) -> Reader<'_> { + let sliced = &self.data[offset..(offset + length)]; + return Reader { + data: sliced, + offset: 0, + length: length as u64, + }; + } + + /// Seek to a new offset, from 0 (start), 1 (current), or 2 (end) of the buffer. + pub fn seek(&mut self, offset: usize, position: u8) { + if position == 0 { + self.offset = offset; + } else if position == 1 { + self.offset += offset; + } else { + self.offset = (self.length as usize) - offset; + } + } + + /// Gets the remaining length of the buffer. + pub fn remaining(&mut self) -> u64 { + return self.length - (self.offset as u64); + } + + /// Data reading interface. + fn read_i(&mut self, endianness: bool) -> T { + if endianness { + return T::from_le_bytes(self.data, self.offset); + } else { + return T::from_be_bytes(self.data, self.offset); + } + } + + /// Reads the next char from the buffer. + pub fn read_char(&mut self, endianness: bool) -> char { + return self.read_uint8(endianness) as char; + } + + /// Reads the next 8 bit unsigned int from the buffer. + pub fn read_uint8(&mut self, endianness: bool) -> u8 { + let res = self.read_i::(endianness); + self.offset += 1; + return res; + } + /// Reads the next 16 bit unsigned int from the buffer. + pub fn read_uint16(&mut self, endianness: bool) -> u16 { + let res = self.read_i::(endianness); + self.offset += 2; + return res; + } + /// Reads the next 32 bit unsigned int from the buffer. + pub fn read_uint32(&mut self, endianness: bool) -> u32 { + let res = self.read_i::(endianness); + self.offset += 4; + return res; + } + /// Reads the next 64 bit unsigned int from the buffer. + pub fn read_uint64(&mut self, endianness: bool) -> u64 { + let res = self.read_i::(endianness); + self.offset += 8; + return res; + } + + /// Reads the next 8 bit signed int from the buffer. + pub fn read_int8(&mut self, endianness: bool) -> i8 { + let res = self.read_i::(endianness); + self.offset += 1; + return res; + } + /// Reads the next 16 bit signed int from the buffer. + pub fn read_int16(&mut self, endianness: bool) -> i16 { + let res = self.read_i::(endianness); + self.offset += 2; + return res; + } + /// Reads the next 32 bit signed int from the buffer. + pub fn read_int32(&mut self, endianness: bool) -> i32 { + let res = self.read_i::(endianness); + self.offset += 4; + return res; + } + /// Reads the next 64 bit signed int from the buffer. + pub fn read_int64(&mut self, endianness: bool) -> i64 { + let res = self.read_i::(endianness); + self.offset += 8; + return res; + } + + /// Reads the next 32 bit float from the buffer. + pub fn read_float32(&mut self, endianness: bool) -> f32 { + let res = self.read_i::(endianness); + self.offset += 4; + return res; + } + /// Reads the next 64 bit float from the buffer. + pub fn read_float64(&mut self, endianness: bool) -> f64 { + let res = self.read_i::(endianness); + self.offset += 8; + return res; + } + + /// Reads the next string from the buffer, using the provided length or reading till next 00 byte. + pub fn read_string(&mut self, length: Option) -> String { + let mut len: usize = 0; + + if length.is_some() { + len = length.unwrap() as usize; + } else { + loop { + if self.data[self.offset + len] == 0 { + break; + } else { + len += 1; + } + } + } + + let u8_vec = self.data[self.offset..self.offset + len].to_vec(); + + let utf8_res = String::from_utf8(u8_vec.clone()); + self.offset += len + 1; + + if utf8_res.is_ok() { + return utf8_res.unwrap(); + } else { + let u16_vec: Vec = u8_vec + .iter() + .map(|char_code| { + return char_code.to_owned() as u16; + }) + .collect(); + let char_codes = &u16_vec[..]; + + return String::from_utf16(char_codes).unwrap(); + } + } +} diff --git a/src-tauri/src/util/vdf_parser/vdf_reader.rs b/src-tauri/src/util/vdf_parser/vdf_reader.rs new file mode 100644 index 00000000..2b49b001 --- /dev/null +++ b/src-tauri/src/util/vdf_parser/vdf_reader.rs @@ -0,0 +1,74 @@ +/* + * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 + * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details + */ + +use serde_json::{Map, Value}; + +use super::reader::Reader; + +/// Reads a vdf entry string to JSON. +pub fn read_vdf_string( + reader: &mut Reader, + magic: Option, + strings: &Option<&mut Vec>, +) -> String { + if magic.is_some() && magic.unwrap() == 0x07564429 { + let index: usize = reader.read_uint32(true).try_into().unwrap(); + let string_pool = strings.as_ref().unwrap(); + let string = &string_pool[index]; + + return string.to_owned(); + } else { + return reader.read_string(None); + } +} + +/// Reads a vdf entry map to JSON. +pub fn read_entry_map( + reader: &mut Reader, + magic: Option, + strings: &Option<&mut Vec>, +) -> Map { + let mut props = Map::new(); + let mut field_type = reader.read_uint8(true); + + while field_type != 0x08 { + let key = read_vdf_string(reader, magic, strings); + let value = read_entry_field(reader, field_type, magic, strings); + + props.insert(key, value); + + field_type = reader.read_uint8(true); + } + + return props; +} + +/// Reads a vdf entry field to JSON. +pub fn read_entry_field( + reader: &mut Reader, + field_type: u8, + magic: Option, + strings: &Option<&mut Vec>, +) -> Value { + match field_type { + 0x00 => { + //? map + return Value::Object(read_entry_map(reader, magic, strings)); + } + 0x01 => { + //? string + let value = reader.read_string(None); + return Value::String(value); + } + 0x02 => { + //? number + let value = reader.read_uint32(true); + return Value::Number(value.into()); + } + _ => { + panic!("Unexpected field type {}!", field_type); + } + } +} diff --git a/src-tauri/src/util/vdf_parser/vdf_structs.rs b/src-tauri/src/util/vdf_parser/vdf_structs.rs new file mode 100644 index 00000000..6d9e0a55 --- /dev/null +++ b/src-tauri/src/util/vdf_parser/vdf_structs.rs @@ -0,0 +1,102 @@ +/* + * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 + * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details + */ + +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct User { + pub AccountName: String, + pub PersonaName: String, + pub RememberPassword: String, + pub WantsOfflineMode: String, + pub SkipOfflineModeWarning: String, + pub AllowAutoLogin: String, + pub MostRecent: String, + pub TimeStamp: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKLMSteam { + pub SteamPID: String, + pub TempAppCmdLine: String, + pub ReLaunchCmdLine: String, + pub ClientLauncher: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKLMValve { + pub Steam: HKLMSteam, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKLMSoftware { + pub Valve: HKLMValve, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKLM { + pub Software: HKLMSoftware, +} + +// #[derive(Serialize, Deserialize, Debug, PartialEq)] +// #[allow(non_snake_case)] +// pub struct HKCUApp { +// pub Updating: String, +// pub installed: String, +// pub Running: String, +// pub name: String +// } + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKCUSteamGlobal { + pub language: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKCUSteam { + pub RunningAppID: String, + pub steamglobal: HKCUSteamGlobal, + pub language: String, + pub Completed00BE: String, + pub SourceModInstallPath: String, + pub AutoLoginUser: String, + pub Rate: String, + pub AlreadyRetriedOfflineMode: String, + pub apps: HashMap>, + pub StartupMode: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKCUValve { + pub Steam: HKCUSteam, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKCUSoftware { + pub Valve: HKCUValve, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct HKCU { + pub Software: HKCUSoftware, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[allow(non_snake_case)] +pub struct Registry { + pub HKLM: HKLM, + pub HKCU: HKCU, +} diff --git a/src/lib/api/profile/launch.ts b/src/lib/api/profile/launch.ts index ba42ebff..ddad11a3 100644 --- a/src/lib/api/profile/launch.ts +++ b/src/lib/api/profile/launch.ts @@ -1,5 +1,7 @@ import { invoke } from '$lib/invoke'; +import type { LaunchOption } from '$lib/types'; -export const launchGame = () => invoke('launch_game'); +export const launchGame = (args?: string) => invoke('launch_game', { args }); export const getArgs = () => invoke('get_launch_args'); export const openGameDir = () => invoke('open_game_dir'); +export const getSteamLaunchOptions = () => invoke('get_steam_launch_options'); diff --git a/src/lib/components/dialogs/LaunchOptionsDialog.svelte b/src/lib/components/dialogs/LaunchOptionsDialog.svelte new file mode 100644 index 00000000..f904a23a --- /dev/null +++ b/src/lib/components/dialogs/LaunchOptionsDialog.svelte @@ -0,0 +1,87 @@ + + + +

Select how you want to launch the game:

+ +
+ + {#each options as option} + +
+
+
+ {#if selectedOption === option.arguments} +
+ {/if} +
+
+
+
{option.name}
+ +
+
+
+ {/each} +
+
+ +
+ You can disable this dialog by turning off "Show Steam launch options" in (open = false)} + class="text-primary-400 hover:text-primary-300 underline">Settings +
+ + {#snippet buttons()} + + {/snippet} +
diff --git a/src/lib/components/toolbar/Toolbar.svelte b/src/lib/components/toolbar/Toolbar.svelte index 88b42557..29cff304 100644 --- a/src/lib/components/toolbar/Toolbar.svelte +++ b/src/lib/components/toolbar/Toolbar.svelte @@ -1,5 +1,6 @@
@@ -72,3 +106,10 @@ (gamesOpen = false)} /> + + diff --git a/src/lib/types.ts b/src/lib/types.ts index 11547a03..b8a1af29 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -325,3 +325,30 @@ export type ModContextItem = { export type Zoom = { factor: number } | { delta: number }; export type MarkdownCache = 'readme' | 'changelog'; + +export type LaunchOptionType = + | 'none' + | 'default' + | 'application' + | 'safemode' + | 'multiplayer' + | 'config' + | 'vr' + | 'server' + | 'editor' + | 'manual' + | 'benchmark' + | 'option1' + | 'option2' + | 'option3' + | 'othervr' + | 'openvroverlay' + | 'osvr' + | 'openxr' + | { unknown: string }; + +export interface LaunchOption { + name: string; + arguments: string; + type: LaunchOptionType; +} From 5dc8ac326d06d26847147f6d2274e9f03d387291 Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Tue, 30 Sep 2025 02:34:39 +0200 Subject: [PATCH 02/11] Update get_steam_app_info to use create_base_steam_command --- src-tauri/src/profile/launch/platform.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/profile/launch/platform.rs b/src-tauri/src/profile/launch/platform.rs index d48fbfd7..b7e5acb0 100644 --- a/src-tauri/src/profile/launch/platform.rs +++ b/src-tauri/src/profile/launch/platform.rs @@ -146,10 +146,13 @@ pub fn get_steam_app_info(app_id: u32) -> Result { use crate::util::vdf_parser::appinfo_vdf_parser::open_appinfo_vdf; use serde_json::{Map, Value}; - let steam_binary = find_steam_binary()?; - let steam_path = steam_binary + let steam_command = create_base_steam_command()?; + let steam_binary = steam_command.get_program(); + let steam_path = Path::new(steam_binary) .parent() - .ok_or_eyre("Steam binary has no parent directory")?; + .ok_or_eyre("Steam binary has no parent directory")? + .to_path_buf(); + drop(steam_command); let appinfo_path = steam_path.join("appcache").join("appinfo.vdf"); From 2cc82984f63da1dbf3fb953f2a10980af28d765a Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Tue, 30 Sep 2025 02:55:39 +0200 Subject: [PATCH 03/11] Move launch option formatting to frontend --- src-tauri/src/profile/launch/commands.rs | 39 +++------------ .../dialogs/LaunchOptionsDialog.svelte | 12 ++--- src/lib/types.ts | 2 +- src/lib/util.ts | 48 +++++++++++++++++++ 4 files changed, 59 insertions(+), 42 deletions(-) diff --git a/src-tauri/src/profile/launch/commands.rs b/src-tauri/src/profile/launch/commands.rs index e74ec429..f0cb7141 100644 --- a/src-tauri/src/profile/launch/commands.rs +++ b/src-tauri/src/profile/launch/commands.rs @@ -2,16 +2,15 @@ use eyre::Context; use itertools::Itertools; use serde::Serialize; use tauri::{command, AppHandle}; -use tracing::warn; use crate::{profile::sync, state::ManagerExt, util::cmd::Result}; #[derive(Debug, Clone, Serialize)] pub struct LaunchOption { - pub name: String, pub arguments: String, #[serde(rename = "type")] pub launch_type: String, + pub description: Option, } #[command] @@ -81,41 +80,15 @@ pub fn get_steam_launch_options(app: AppHandle) -> Result> { .unwrap_or("") .to_string(); - let name = match option_type { - "none" | "default" => format!("Play {}", game_name), - "application" => format!("Launch {}", game_name), - "safemode" => format!("Launch {} in Safe Mode", game_name), - "multiplayer" => format!("Launch {} in Multiplayer Mode", game_name), - "config" => format!("Launch Controller Layout Tool"), - "vr" => format!("Launch {} in Steam VR Mode", game_name), - "server" => format!("Launch Dedicated Server"), - "editor" => format!("Launch Game Editor"), - "manual" => format!("Show Manual"), - "benchmark" => format!("Launch Benchmark Tool"), - "option1" | "option2" | "option3" => { - if let Some(description) = - option.get("description").and_then(|d| d.as_str()) - { - format!("Play {}", description) - } else { - format!("Play {} ({})", game_name, option_type) - } - } - "othervr" => format!("Launch {} in Oculus VR Mode", game_name), - "openvroverlay" => format!("Launch {} as Steam VR Overlay", game_name), - "osvr" => format!("Launch {} in OSVR Mode", game_name), - "openxr" => format!("Launch {} in OpenXR Mode", game_name), - // "dialog" => format!("Show {} Launch Options", game_name), // Idk what this is - _ => { - warn!("Undefined launch option type: {}", option_type); - format!("Launch {} ({})", game_name, option_type) - } - }; + let description = option + .get("description") + .and_then(|d| d.as_str()) + .map(|s| s.to_string()); launch_options.push(LaunchOption { - name, arguments, launch_type: option_type.to_string(), + description, }); } } diff --git a/src/lib/components/dialogs/LaunchOptionsDialog.svelte b/src/lib/components/dialogs/LaunchOptionsDialog.svelte index f904a23a..5ce25f1a 100644 --- a/src/lib/components/dialogs/LaunchOptionsDialog.svelte +++ b/src/lib/components/dialogs/LaunchOptionsDialog.svelte @@ -3,6 +3,7 @@ import Button from '$lib/components/ui/Button.svelte'; import { RadioGroup } from 'bits-ui'; import type { LaunchOption } from '$lib/types'; + import { formatLaunchOptionName } from '$lib/util'; interface Props { open: boolean; @@ -58,14 +59,9 @@
-
{option.name}
- +
+ {formatLaunchOptionName(option.type, gameName, option.description)} +
diff --git a/src/lib/types.ts b/src/lib/types.ts index 88abaff2..196e0f54 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -350,7 +350,7 @@ export type LaunchOptionType = | { unknown: string }; export interface LaunchOption { - name: string; arguments: string; type: LaunchOptionType; + description?: string; } diff --git a/src/lib/util.ts b/src/lib/util.ts index 0da06936..0798fb22 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -4,6 +4,7 @@ import { type SyncUser, type Game, type MarkdownType, + type LaunchOptionType, ModType } from './types'; import { convertFileSrc } from '@tauri-apps/api/core'; @@ -33,6 +34,53 @@ export function formatTime(seconds: number): string { return `${hours} hour${hours > 1 ? 's' : ''}`; } +export function formatLaunchOptionName( + type: LaunchOptionType, + gameName: string, + description?: string +): string { + switch (type) { + case 'none': + case 'default': + return `Play ${gameName}`; + case 'application': + return `Launch ${gameName}`; + case 'safemode': + return `Launch ${gameName} in Safe Mode`; + case 'multiplayer': + return `Launch ${gameName} in Multiplayer Mode`; + case 'config': + return 'Launch Controller Layout Tool'; + case 'vr': + return `Launch ${gameName} in Steam VR Mode`; + case 'server': + return 'Launch Dedicated Server'; + case 'editor': + return 'Launch Game Editor'; + case 'manual': + return 'Show Manual'; + case 'benchmark': + return 'Launch Benchmark Tool'; + case 'option1': + case 'option2': + case 'option3': + return description ? `Play ${description}` : `Play ${gameName} (${type})`; + case 'othervr': + return `Launch ${gameName} in Oculus VR Mode`; + case 'openvroverlay': + return `Launch ${gameName} as Steam VR Overlay`; + case 'osvr': + return `Launch ${gameName} in OSVR Mode`; + case 'openxr': + return `Launch ${gameName} in OpenXR Mode`; + default: + if (typeof type === 'object' && 'unknown' in type) { + return `Launch ${gameName} (${type.unknown})`; + } + return `Launch ${gameName}`; + } +} + export function shortenNum(value: number): string { var i = value == 0 ? 0 : Math.floor(Math.log(value) / Math.log(1000)); if (i === 0) { From b9fbc82ed1501f03a5d23f851c7fa3f3d498d8fc Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Tue, 30 Sep 2025 03:12:33 +0200 Subject: [PATCH 04/11] Add toggle for Steam launch options dialog --- src-tauri/src/db/migrate.rs | 1 + src-tauri/src/prefs/mod.rs | 1 + src/lib/components/toolbar/Toolbar.svelte | 7 ++++++- src/lib/types.ts | 1 + src/routes/prefs/+page.svelte | 15 ++++++++++++++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/db/migrate.rs b/src-tauri/src/db/migrate.rs index 94b414f5..b4c52ab0 100644 --- a/src-tauri/src/db/migrate.rs +++ b/src-tauri/src/db/migrate.rs @@ -152,6 +152,7 @@ impl From for GamePrefs { custom_args_enabled: legacy.custom_args.is_some(), launch_mode: legacy.launch_mode.into(), platform: legacy.platform.map(Into::into), + show_steam_launch_options: false, } } } diff --git a/src-tauri/src/prefs/mod.rs b/src-tauri/src/prefs/mod.rs index 97e33ab2..233ee1af 100644 --- a/src-tauri/src/prefs/mod.rs +++ b/src-tauri/src/prefs/mod.rs @@ -198,6 +198,7 @@ pub struct GamePrefs { pub custom_args_enabled: bool, pub launch_mode: LaunchMode, pub platform: Option, + pub show_steam_launch_options: bool, } impl Default for Prefs { diff --git a/src/lib/components/toolbar/Toolbar.svelte b/src/lib/components/toolbar/Toolbar.svelte index 29cff304..2fce83d6 100644 --- a/src/lib/components/toolbar/Toolbar.svelte +++ b/src/lib/components/toolbar/Toolbar.svelte @@ -32,7 +32,12 @@ if (currentGameSlug && prefs.gamePrefs.get(currentGameSlug)) { const gamePrefs = prefs.gamePrefs.get(currentGameSlug); - if (gamePrefs && gamePrefs.launchMode.type === 'launcher' && gamePrefs.platform === 'steam') { + if ( + gamePrefs && + gamePrefs.launchMode.type === 'launcher' && + gamePrefs.platform === 'steam' && + gamePrefs.showSteamLaunchOptions + ) { try { const options = await api.profile.launch.getSteamLaunchOptions(); diff --git a/src/lib/types.ts b/src/lib/types.ts index 196e0f54..9f92a2db 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -305,6 +305,7 @@ export type GamePrefs = { customArgsEnabled: boolean; launchMode: LaunchMode; platform: Platform | null; + showSteamLaunchOptions: boolean; }; export type Platform = 'steam' | 'epicGames' | 'oculus' | 'origin' | 'xboxStore'; diff --git a/src/routes/prefs/+page.svelte b/src/routes/prefs/+page.svelte index 05b08ca0..b1e0ba0e 100644 --- a/src/routes/prefs/+page.svelte +++ b/src/routes/prefs/+page.svelte @@ -35,7 +35,8 @@ dirOverride: null, customArgs: [], customArgsEnabled: false, - platform: null + platform: null, + showSteamLaunchOptions: false }; }); @@ -173,6 +174,18 @@ set={set((value) => (gamePrefs!.launchMode = value))} /> + {#if gamePrefs.launchMode.type === 'launcher' && gamePrefs.platform === 'steam'} + (gamePrefs!.showSteamLaunchOptions = value))} + > + When enabled, displays Steam launch options defined by the game developer (if any) before + starting the game. These options may include different game modes like VR, Safe Mode, + Dedicated Server, or other launch configurations specific to the game. + + {/if} + Date: Tue, 30 Sep 2025 03:41:36 +0200 Subject: [PATCH 05/11] Remove unnecessary empty string check for launch args --- src-tauri/src/profile/launch/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src-tauri/src/profile/launch/mod.rs b/src-tauri/src/profile/launch/mod.rs index d524a652..68d800b2 100644 --- a/src-tauri/src/profile/launch/mod.rs +++ b/src-tauri/src/profile/launch/mod.rs @@ -58,9 +58,7 @@ impl ManagedGame { let (launch_mode, mut command) = self.launch_command(&game_dir, prefs)?; if let Some(args) = args { - if !args.is_empty() { - command.args(args.split_whitespace()); - } + command.args(args.split_whitespace()); } info!("launching {} with command {:?}", self.game.slug, command); From 224c1cface7796a4e7b8be7015bd4749797e88d2 Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Thu, 2 Oct 2025 21:41:20 +0200 Subject: [PATCH 06/11] Refactor Steam launch options logic to module level - Replace eager ok_or_eyre(format!) with lazy ok_or_else(|| eyre!) in platform.rs - Remove redundant Map.get() check in Toolbar.svelte --- src-tauri/src/profile/launch/commands.rs | 45 +--------------------- src-tauri/src/profile/launch/mod.rs | 47 ++++++++++++++++++++++- src-tauri/src/profile/launch/platform.rs | 14 +++---- src/lib/components/toolbar/Toolbar.svelte | 2 +- 4 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src-tauri/src/profile/launch/commands.rs b/src-tauri/src/profile/launch/commands.rs index f0cb7141..1c94947d 100644 --- a/src-tauri/src/profile/launch/commands.rs +++ b/src-tauri/src/profile/launch/commands.rs @@ -1,18 +1,9 @@ use eyre::Context; use itertools::Itertools; -use serde::Serialize; use tauri::{command, AppHandle}; use crate::{profile::sync, state::ManagerExt, util::cmd::Result}; -#[derive(Debug, Clone, Serialize)] -pub struct LaunchOption { - pub arguments: String, - #[serde(rename = "type")] - pub launch_type: String, - pub description: Option, -} - #[command] pub async fn launch_game(app: AppHandle, args: Option) -> Result<()> { if app.lock_prefs().pull_before_launch { @@ -54,45 +45,13 @@ pub fn open_game_dir(app: AppHandle) -> Result<()> { } #[command] -pub fn get_steam_launch_options(app: AppHandle) -> Result> { +pub fn get_steam_launch_options(app: AppHandle) -> Result> { let manager = app.lock_manager(); let managed_game = manager.active_game(); let game_name = &managed_game.game.name; let Some(steam) = &managed_game.game.platforms.steam else { return Err(eyre::eyre!("{} is not available on Steam", game_name).into()); }; - let raw_options = super::platform::get_steam_launch_options(steam.id) - .context("failed to get Steam launch options")?; - - let mut launch_options = Vec::new(); - - if let Some(options_obj) = raw_options.as_object() { - for (_, option_value) in options_obj.iter() { - if let Some(option) = option_value.as_object() { - let option_type = option - .get("type") - .and_then(|t| t.as_str()) - .unwrap_or("undefined"); - - let arguments = option - .get("arguments") - .and_then(|a| a.as_str()) - .unwrap_or("") - .to_string(); - - let description = option - .get("description") - .and_then(|d| d.as_str()) - .map(|s| s.to_string()); - - launch_options.push(LaunchOption { - arguments, - launch_type: option_type.to_string(), - description, - }); - } - } - } - Ok(launch_options) + Ok(super::parse_steam_launch_options(steam.id)?) } diff --git a/src-tauri/src/profile/launch/mod.rs b/src-tauri/src/profile/launch/mod.rs index 68d800b2..ee7b73fe 100644 --- a/src-tauri/src/profile/launch/mod.rs +++ b/src-tauri/src/profile/launch/mod.rs @@ -5,7 +5,7 @@ use std::{ process::Command, }; -use eyre::{bail, ensure, eyre, OptionExt, Result}; +use eyre::{bail, ensure, eyre, Context, OptionExt, Result}; use serde::{Deserialize, Serialize}; use tauri::AppHandle; use tokio::time::Duration; @@ -39,6 +39,14 @@ pub enum LaunchMode { Direct { instances: u32, interval_secs: f32 }, } +#[derive(Serialize, Deserialize, Default, Debug, Clone)] +pub struct LaunchOption { + pub arguments: String, + #[serde(rename = "type")] + pub launch_type: String, + pub description: Option, +} + impl ManagedGame { pub fn launch(&self, prefs: &Prefs, app: &AppHandle) -> Result<()> { self.launch_with_args(prefs, app, None) @@ -240,3 +248,40 @@ fn exe_path(game_dir: &Path) -> Result { .map(|entry| entry.path()) .ok_or_eyre("game executable not found") } + +pub fn parse_steam_launch_options(steam_id: u32) -> Result> { + let raw_options = platform::get_steam_launch_options(steam_id) + .context("failed to get Steam launch options")?; + + let mut launch_options = Vec::new(); + + if let Some(options_obj) = raw_options.as_object() { + for (_, option_value) in options_obj.iter() { + if let Some(option) = option_value.as_object() { + let option_type = option + .get("type") + .and_then(|t| t.as_str()) + .unwrap_or("undefined"); + + let arguments = option + .get("arguments") + .and_then(|a| a.as_str()) + .unwrap_or("") + .to_string(); + + let description = option + .get("description") + .and_then(|d| d.as_str()) + .map(|s| s.to_string()); + + launch_options.push(LaunchOption { + arguments, + launch_type: option_type.to_string(), + description, + }); + } + } + } + + Ok(launch_options) +} diff --git a/src-tauri/src/profile/launch/platform.rs b/src-tauri/src/profile/launch/platform.rs index b7e5acb0..b37b1004 100644 --- a/src-tauri/src/profile/launch/platform.rs +++ b/src-tauri/src/profile/launch/platform.rs @@ -3,7 +3,7 @@ use std::{ process::Command, }; -use eyre::{bail, ensure, Context, OptionExt, Result}; +use eyre::{bail, ensure, eyre, Context, OptionExt, Result}; use tracing::{info, warn}; use crate::{ @@ -139,7 +139,7 @@ pub fn get_steam_launch_options(app_id: u32) -> Result { .get("config") .and_then(|config| config.get("launch")) .cloned() - .ok_or_eyre(format!("No launch options found for app ID {}", app_id)) + .ok_or_else(|| eyre!("no launch options found for app ID {}", app_id)) } pub fn get_steam_app_info(app_id: u32) -> Result { @@ -150,7 +150,7 @@ pub fn get_steam_app_info(app_id: u32) -> Result { let steam_binary = steam_command.get_program(); let steam_path = Path::new(steam_binary) .parent() - .ok_or_eyre("Steam binary has no parent directory")? + .ok_or_eyre("steam binary has no parent directory")? .to_path_buf(); drop(steam_command); @@ -158,18 +158,18 @@ pub fn get_steam_app_info(app_id: u32) -> Result { ensure!( appinfo_path.exists(), - "Steam appinfo.vdf not found at {}", + "steam appinfo.vdf not found at {}", appinfo_path.display() ); - info!("Reading Steam app info from {}", appinfo_path.display()); + info!("reading Steam app info from {}", appinfo_path.display()); let appinfo_vdf: Map = open_appinfo_vdf(&appinfo_path); let entries = appinfo_vdf .get("entries") .and_then(|e| e.as_array()) - .ok_or_eyre("No entries found in appinfo.vdf")?; + .ok_or_eyre("no entries found in appinfo.vdf")?; entries .iter() @@ -180,7 +180,7 @@ pub fn get_steam_app_info(app_id: u32) -> Result { .map_or(false, |id| id == app_id as u64) }) .cloned() - .ok_or_eyre(format!("App ID {} not found in Steam appinfo.vdf", app_id)) + .ok_or_else(|| eyre!("app ID {} not found in Steam appinfo.vdf", app_id)) } fn create_epic_command(game: Game) -> Result { diff --git a/src/lib/components/toolbar/Toolbar.svelte b/src/lib/components/toolbar/Toolbar.svelte index 2fce83d6..7470b08f 100644 --- a/src/lib/components/toolbar/Toolbar.svelte +++ b/src/lib/components/toolbar/Toolbar.svelte @@ -29,7 +29,7 @@ prefs.gamePrefs = new Map(Object.entries(prefs.gamePrefs)); const currentGameSlug = games.active?.slug; - if (currentGameSlug && prefs.gamePrefs.get(currentGameSlug)) { + if (currentGameSlug) { const gamePrefs = prefs.gamePrefs.get(currentGameSlug); if ( From 28677738dbf8edf9125a689661989442cc869d0c Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:48:40 +0200 Subject: [PATCH 07/11] Replace VDF parser with new-vdf-parser crate --- src-tauri/Cargo.lock | 12 + src-tauri/Cargo.toml | 1 + src-tauri/src/profile/launch/platform.rs | 2 +- src-tauri/src/util/mod.rs | 1 - src-tauri/src/util/vdf_parser/LICENSE | 504 ------------------ .../src/util/vdf_parser/appinfo_vdf_parser.rs | 129 ----- src-tauri/src/util/vdf_parser/mod.rs | 9 - src-tauri/src/util/vdf_parser/reader.rs | 341 ------------ src-tauri/src/util/vdf_parser/vdf_reader.rs | 74 --- src-tauri/src/util/vdf_parser/vdf_structs.rs | 102 ---- 10 files changed, 14 insertions(+), 1161 deletions(-) delete mode 100644 src-tauri/src/util/vdf_parser/LICENSE delete mode 100644 src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs delete mode 100644 src-tauri/src/util/vdf_parser/mod.rs delete mode 100644 src-tauri/src/util/vdf_parser/reader.rs delete mode 100644 src-tauri/src/util/vdf_parser/vdf_reader.rs delete mode 100644 src-tauri/src/util/vdf_parser/vdf_structs.rs diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index cdbda5a1..723bbac0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1862,6 +1862,7 @@ dependencies = [ "itertools 0.13.0", "justerror", "keyring", + "new-vdf-parser", "open", "rayon", "reqwest", @@ -3333,6 +3334,17 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "new-vdf-parser" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfae50b7ad7d93142e170e4f86d90599282ef7f5108fad4155610cf0aacf1f5" +dependencies = [ + "rayon", + "serde", + "serde_json", +] + [[package]] name = "new_debug_unreachable" version = "1.0.6" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c5a37710..a8234916 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -76,6 +76,7 @@ flate2 = "1" font-kit = "0.14" internment = { version = "0.8.6", features = ["serde"] } reqwest-websocket = { version = "0.5.0", features = ["json"] } +new-vdf-parser = "0.1.0" [target.'cfg(target_os="windows")'.dependencies] winreg = "0.52" diff --git a/src-tauri/src/profile/launch/platform.rs b/src-tauri/src/profile/launch/platform.rs index b37b1004..e9bdd6ea 100644 --- a/src-tauri/src/profile/launch/platform.rs +++ b/src-tauri/src/profile/launch/platform.rs @@ -143,7 +143,7 @@ pub fn get_steam_launch_options(app_id: u32) -> Result { } pub fn get_steam_app_info(app_id: u32) -> Result { - use crate::util::vdf_parser::appinfo_vdf_parser::open_appinfo_vdf; + use new_vdf_parser::appinfo_vdf_parser::open_appinfo_vdf; use serde_json::{Map, Value}; let steam_command = create_base_steam_command()?; diff --git a/src-tauri/src/util/mod.rs b/src-tauri/src/util/mod.rs index f6ddd5c6..30e53ba2 100644 --- a/src-tauri/src/util/mod.rs +++ b/src-tauri/src/util/mod.rs @@ -6,7 +6,6 @@ pub mod cmd; pub mod error; pub mod fs; pub mod path; -pub mod vdf_parser; pub mod window; pub mod zip; diff --git a/src-tauri/src/util/vdf_parser/LICENSE b/src-tauri/src/util/vdf_parser/LICENSE deleted file mode 100644 index 5f757420..00000000 --- a/src-tauri/src/util/vdf_parser/LICENSE +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random - Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! \ No newline at end of file diff --git a/src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs b/src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs deleted file mode 100644 index 4346bc64..00000000 --- a/src-tauri/src/util/vdf_parser/appinfo_vdf_parser.rs +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 - * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details - */ - -use std::i64; -use std::io::Read; -use std::{fs, path::PathBuf}; - -use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; -use serde_json::{Map, Value}; - -use super::reader::Reader; -use super::vdf_reader::read_entry_map; - -/// Opens the appinfo.vdf file and returns the values as JSON. -pub fn open_appinfo_vdf(path: &PathBuf) -> Map { - let mut file = fs::File::open(path).expect("Path should have existed."); - let metadata = fs::metadata(path).expect("Unable to read metadata."); - - let mut buffer = Vec::with_capacity(metadata.len() as usize); - file.read_to_end(&mut buffer).expect("Buffer overflow."); - - let mut reader = Reader::new(&buffer); - - return read(&mut reader); -} - -/// Reads the appinfo.vdf file and returns the values as JSON. -fn read(reader: &mut Reader) -> Map { - let magic = reader.read_uint32(true); - let _universe = reader.read_uint32(true); //always 1 - - let entries: Vec; - - if magic == 0x07564429 { - let string_table_offset = reader.read_int64(true); - let data_offset = reader.get_offset(); - - reader.seek( - string_table_offset - .try_into() - .expect("String table offset couldn't be converted to usize"), - 0, - ); - - let string_count = reader.read_uint32(true) as usize; - let mut strings = Vec::with_capacity(string_count); - - for _ in 0..string_count { - strings.push(reader.read_string(None)); - } - - reader.seek(data_offset, 0); - - entries = read_app_sections( - reader, - Some(string_table_offset), - Some(magic), - &Some(&mut strings), - ); - } else if magic == 0x07564428 { - entries = read_app_sections(reader, None, None, &None); - } else { - panic!("Magic header is unknown. Expected 0x07564428 or 0x07564429 but got {magic}"); - } - - let mut res: Map = Map::new(); - res.insert(String::from("entries"), Value::Array(entries)); - - return res; -} - -struct AppInfoChunk { - pub offset: usize, - pub length: usize, -} - -/// Reads the appinfo.vdf app sections to a JSON array. -fn read_app_sections( - reader: &mut Reader, - string_table_offset: Option, - magic: Option, - strings: &Option<&mut Vec>, -) -> Vec { - let mut id = reader.read_uint32(true); - let eof = string_table_offset.unwrap_or(i64::MAX) as usize - 4; - - let mut chunks = Vec::new(); - - while id != 0 && reader.get_offset() < eof { - let chunk_size = reader.read_uint32(true); - let offset = reader.get_offset(); - let chunk_length: usize = chunk_size.try_into().unwrap(); - - chunks.push(AppInfoChunk { - offset, - length: chunk_length, - }); - - reader.seek(offset + chunk_length, 0); - id = reader.read_uint32(true); - } - - let entries: Vec = chunks - .par_iter() - .filter_map(|chunk| { - let mut chunk_reader = reader.slice(chunk.offset, chunk.length); - chunk_reader.seek(60, 1); - - let mut entry: Map = read_entry_map(&mut chunk_reader, magic, strings); - - if entry.contains_key("appinfo") { - let appinfo_val: &Value = entry - .get("appinfo") - .expect("Should have been able to get \"appinfo\"."); - let appinfo = appinfo_val - .as_object() - .expect("appinfo should have been an object."); - - entry = appinfo.clone(); - } - - return Some(Value::Object(entry)); - }) - .collect(); - - return entries; -} diff --git a/src-tauri/src/util/vdf_parser/mod.rs b/src-tauri/src/util/vdf_parser/mod.rs deleted file mode 100644 index 0b9a45cb..00000000 --- a/src-tauri/src/util/vdf_parser/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -/* - * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 - * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details - */ - -pub mod appinfo_vdf_parser; -mod reader; -mod vdf_reader; -mod vdf_structs; diff --git a/src-tauri/src/util/vdf_parser/reader.rs b/src-tauri/src/util/vdf_parser/reader.rs deleted file mode 100644 index 6eed06df..00000000 --- a/src-tauri/src/util/vdf_parser/reader.rs +++ /dev/null @@ -1,341 +0,0 @@ -/* - * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 - * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details - */ - -trait HasByteConvert { - fn from_le_bytes(bytes: &[u8], offset: usize) -> Self; - fn from_be_bytes(bytes: &[u8], offset: usize) -> Self; -} - -impl HasByteConvert for u8 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> u8 { - return bytes[offset]; - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> u8 { - return bytes[offset]; - } -} - -impl HasByteConvert for u16 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> u16 { - return u16::from_le_bytes( - bytes[offset..offset + 2] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> u16 { - return u16::from_be_bytes( - bytes[offset..offset + 2] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for u32 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> u32 { - return u32::from_le_bytes( - bytes[offset..offset + 4] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> u32 { - return u32::from_be_bytes( - bytes[offset..offset + 4] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for u64 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> u64 { - return u64::from_le_bytes( - bytes[offset..offset + 8] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> u64 { - return u64::from_be_bytes( - bytes[offset..offset + 8] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for i8 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> i8 { - return i8::from_le_bytes( - bytes[offset..offset + 1] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> i8 { - return i8::from_be_bytes( - bytes[offset..offset + 1] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for i16 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> i16 { - return i16::from_le_bytes( - bytes[offset..offset + 2] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> i16 { - return i16::from_be_bytes( - bytes[offset..offset + 2] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for i32 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> i32 { - return i32::from_le_bytes( - bytes[offset..offset + 4] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> i32 { - return i32::from_be_bytes( - bytes[offset..offset + 4] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for i64 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> i64 { - return i64::from_le_bytes( - bytes[offset..offset + 8] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> i64 { - return i64::from_be_bytes( - bytes[offset..offset + 8] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for f32 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> f32 { - return f32::from_le_bytes( - bytes[offset..offset + 4] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> f32 { - return f32::from_be_bytes( - bytes[offset..offset + 4] - .try_into() - .expect("incorrect length"), - ); - } -} - -impl HasByteConvert for f64 { - fn from_le_bytes(bytes: &[u8], offset: usize) -> f64 { - return f64::from_le_bytes( - bytes[offset..offset + 8] - .try_into() - .expect("incorrect length"), - ); - } - fn from_be_bytes(bytes: &[u8], offset: usize) -> f64 { - return f64::from_be_bytes( - bytes[offset..offset + 8] - .try_into() - .expect("incorrect length"), - ); - } -} - -pub struct Reader<'a> { - data: &'a [u8], - offset: usize, - length: u64, -} - -#[allow(dead_code)] -impl Reader<'_> { - /// Gets the underlying data of the reader. - pub fn get_data(&self) -> &[u8] { - return self.data; - } - /// Gets the offset of the reader. - pub fn get_offset(&self) -> usize { - return self.offset; - } - /// Gets the length of the reader. - pub fn get_length(&self) -> u64 { - return self.length; - } - - /// Creates a new Reader from the provided buffer. - pub fn new(buf: &[u8]) -> Reader<'_> { - return Reader { - data: buf, - offset: 0, - length: buf.len() as u64, - }; - } - - /// Slices the Reader's buffer and returns a new Reader for the slice. - pub fn slice(&self, offset: usize, length: usize) -> Reader<'_> { - let sliced = &self.data[offset..(offset + length)]; - return Reader { - data: sliced, - offset: 0, - length: length as u64, - }; - } - - /// Seek to a new offset, from 0 (start), 1 (current), or 2 (end) of the buffer. - pub fn seek(&mut self, offset: usize, position: u8) { - if position == 0 { - self.offset = offset; - } else if position == 1 { - self.offset += offset; - } else { - self.offset = (self.length as usize) - offset; - } - } - - /// Gets the remaining length of the buffer. - pub fn remaining(&mut self) -> u64 { - return self.length - (self.offset as u64); - } - - /// Data reading interface. - fn read_i(&mut self, endianness: bool) -> T { - if endianness { - return T::from_le_bytes(self.data, self.offset); - } else { - return T::from_be_bytes(self.data, self.offset); - } - } - - /// Reads the next char from the buffer. - pub fn read_char(&mut self, endianness: bool) -> char { - return self.read_uint8(endianness) as char; - } - - /// Reads the next 8 bit unsigned int from the buffer. - pub fn read_uint8(&mut self, endianness: bool) -> u8 { - let res = self.read_i::(endianness); - self.offset += 1; - return res; - } - /// Reads the next 16 bit unsigned int from the buffer. - pub fn read_uint16(&mut self, endianness: bool) -> u16 { - let res = self.read_i::(endianness); - self.offset += 2; - return res; - } - /// Reads the next 32 bit unsigned int from the buffer. - pub fn read_uint32(&mut self, endianness: bool) -> u32 { - let res = self.read_i::(endianness); - self.offset += 4; - return res; - } - /// Reads the next 64 bit unsigned int from the buffer. - pub fn read_uint64(&mut self, endianness: bool) -> u64 { - let res = self.read_i::(endianness); - self.offset += 8; - return res; - } - - /// Reads the next 8 bit signed int from the buffer. - pub fn read_int8(&mut self, endianness: bool) -> i8 { - let res = self.read_i::(endianness); - self.offset += 1; - return res; - } - /// Reads the next 16 bit signed int from the buffer. - pub fn read_int16(&mut self, endianness: bool) -> i16 { - let res = self.read_i::(endianness); - self.offset += 2; - return res; - } - /// Reads the next 32 bit signed int from the buffer. - pub fn read_int32(&mut self, endianness: bool) -> i32 { - let res = self.read_i::(endianness); - self.offset += 4; - return res; - } - /// Reads the next 64 bit signed int from the buffer. - pub fn read_int64(&mut self, endianness: bool) -> i64 { - let res = self.read_i::(endianness); - self.offset += 8; - return res; - } - - /// Reads the next 32 bit float from the buffer. - pub fn read_float32(&mut self, endianness: bool) -> f32 { - let res = self.read_i::(endianness); - self.offset += 4; - return res; - } - /// Reads the next 64 bit float from the buffer. - pub fn read_float64(&mut self, endianness: bool) -> f64 { - let res = self.read_i::(endianness); - self.offset += 8; - return res; - } - - /// Reads the next string from the buffer, using the provided length or reading till next 00 byte. - pub fn read_string(&mut self, length: Option) -> String { - let mut len: usize = 0; - - if length.is_some() { - len = length.unwrap() as usize; - } else { - loop { - if self.data[self.offset + len] == 0 { - break; - } else { - len += 1; - } - } - } - - let u8_vec = self.data[self.offset..self.offset + len].to_vec(); - - let utf8_res = String::from_utf8(u8_vec.clone()); - self.offset += len + 1; - - if utf8_res.is_ok() { - return utf8_res.unwrap(); - } else { - let u16_vec: Vec = u8_vec - .iter() - .map(|char_code| { - return char_code.to_owned() as u16; - }) - .collect(); - let char_codes = &u16_vec[..]; - - return String::from_utf16(char_codes).unwrap(); - } - } -} diff --git a/src-tauri/src/util/vdf_parser/vdf_reader.rs b/src-tauri/src/util/vdf_parser/vdf_reader.rs deleted file mode 100644 index 2b49b001..00000000 --- a/src-tauri/src/util/vdf_parser/vdf_reader.rs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 - * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details - */ - -use serde_json::{Map, Value}; - -use super::reader::Reader; - -/// Reads a vdf entry string to JSON. -pub fn read_vdf_string( - reader: &mut Reader, - magic: Option, - strings: &Option<&mut Vec>, -) -> String { - if magic.is_some() && magic.unwrap() == 0x07564429 { - let index: usize = reader.read_uint32(true).try_into().unwrap(); - let string_pool = strings.as_ref().unwrap(); - let string = &string_pool[index]; - - return string.to_owned(); - } else { - return reader.read_string(None); - } -} - -/// Reads a vdf entry map to JSON. -pub fn read_entry_map( - reader: &mut Reader, - magic: Option, - strings: &Option<&mut Vec>, -) -> Map { - let mut props = Map::new(); - let mut field_type = reader.read_uint8(true); - - while field_type != 0x08 { - let key = read_vdf_string(reader, magic, strings); - let value = read_entry_field(reader, field_type, magic, strings); - - props.insert(key, value); - - field_type = reader.read_uint8(true); - } - - return props; -} - -/// Reads a vdf entry field to JSON. -pub fn read_entry_field( - reader: &mut Reader, - field_type: u8, - magic: Option, - strings: &Option<&mut Vec>, -) -> Value { - match field_type { - 0x00 => { - //? map - return Value::Object(read_entry_map(reader, magic, strings)); - } - 0x01 => { - //? string - let value = reader.read_string(None); - return Value::String(value); - } - 0x02 => { - //? number - let value = reader.read_uint32(true); - return Value::Number(value.into()); - } - _ => { - panic!("Unexpected field type {}!", field_type); - } - } -} diff --git a/src-tauri/src/util/vdf_parser/vdf_structs.rs b/src-tauri/src/util/vdf_parser/vdf_structs.rs deleted file mode 100644 index 6d9e0a55..00000000 --- a/src-tauri/src/util/vdf_parser/vdf_structs.rs +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of Steam-Art-Manager which is licensed under GNU Lesser General Public License v2.1 - * See file LICENSE or go to https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html for full license details - */ - -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct User { - pub AccountName: String, - pub PersonaName: String, - pub RememberPassword: String, - pub WantsOfflineMode: String, - pub SkipOfflineModeWarning: String, - pub AllowAutoLogin: String, - pub MostRecent: String, - pub TimeStamp: String, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKLMSteam { - pub SteamPID: String, - pub TempAppCmdLine: String, - pub ReLaunchCmdLine: String, - pub ClientLauncher: String, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKLMValve { - pub Steam: HKLMSteam, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKLMSoftware { - pub Valve: HKLMValve, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKLM { - pub Software: HKLMSoftware, -} - -// #[derive(Serialize, Deserialize, Debug, PartialEq)] -// #[allow(non_snake_case)] -// pub struct HKCUApp { -// pub Updating: String, -// pub installed: String, -// pub Running: String, -// pub name: String -// } - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKCUSteamGlobal { - pub language: String, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKCUSteam { - pub RunningAppID: String, - pub steamglobal: HKCUSteamGlobal, - pub language: String, - pub Completed00BE: String, - pub SourceModInstallPath: String, - pub AutoLoginUser: String, - pub Rate: String, - pub AlreadyRetriedOfflineMode: String, - pub apps: HashMap>, - pub StartupMode: String, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKCUValve { - pub Steam: HKCUSteam, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKCUSoftware { - pub Valve: HKCUValve, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct HKCU { - pub Software: HKCUSoftware, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[allow(non_snake_case)] -pub struct Registry { - pub HKLM: HKLM, - pub HKCU: HKCU, -} From 3e3e2afe52e2556ee0263d2e1fd128cfd989d6b7 Mon Sep 17 00:00:00 2001 From: Kesomannen Date: Tue, 14 Oct 2025 16:12:41 +0200 Subject: [PATCH 08/11] Fix steam launch option not appearing If you hadn't explicity selected steam, gamePrefs.platform would set to null which hides the option --- src/routes/prefs/+page.svelte | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/prefs/+page.svelte b/src/routes/prefs/+page.svelte index b1e0ba0e..8e267c3f 100644 --- a/src/routes/prefs/+page.svelte +++ b/src/routes/prefs/+page.svelte @@ -29,6 +29,10 @@ let gameSlug = $derived(games.active?.slug ?? ''); + let shownPlatform = $derived.by( + () => gamePrefs?.platform ?? games.active?.platforms[0] ?? 'Unknown' + ); + $effect(() => { gamePrefs = prefs?.gamePrefs.get(gameSlug) ?? { launchMode: { type: 'launcher' }, @@ -169,12 +173,12 @@ Launch (gamePrefs!.launchMode = value))} /> - {#if gamePrefs.launchMode.type === 'launcher' && gamePrefs.platform === 'steam'} + {#if gamePrefs.launchMode.type === 'launcher' && shownPlatform === 'steam'} Date: Tue, 14 Oct 2025 16:13:31 +0200 Subject: [PATCH 09/11] Tweak steam launch option ui Makes it look a bit more inline with the rest of the ui --- .../dialogs/LaunchOptionsDialog.svelte | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/lib/components/dialogs/LaunchOptionsDialog.svelte b/src/lib/components/dialogs/LaunchOptionsDialog.svelte index 5ce25f1a..6d03a1d3 100644 --- a/src/lib/components/dialogs/LaunchOptionsDialog.svelte +++ b/src/lib/components/dialogs/LaunchOptionsDialog.svelte @@ -4,6 +4,7 @@ import { RadioGroup } from 'bits-ui'; import type { LaunchOption } from '$lib/types'; import { formatLaunchOptionName } from '$lib/util'; + import Icon from '@iconify/svelte'; interface Props { open: boolean; @@ -35,33 +36,32 @@

Select how you want to launch the game:

- + {#each options as option} - -
-
-
- {#if selectedOption === option.arguments} -
- {/if} -
+ +
+
+ {#if selectedOption === option.arguments} +
+ {/if}
-
-
- {formatLaunchOptionName(option.type, gameName, option.description)} -
+
+
+
+ {formatLaunchOptionName(option.type, gameName, option.description)}
@@ -73,7 +73,9 @@ You can disable this dialog by turning off "Show Steam launch options" in (open = false)} - class="text-primary-400 hover:text-primary-300 underline">Settings + Settings
From bb1eade36c9bd5c34b580e657da36fd8b6ecfea4 Mon Sep 17 00:00:00 2001 From: Kesomannen Date: Tue, 14 Oct 2025 16:13:50 +0200 Subject: [PATCH 10/11] Remove unneeded Icon import --- src/lib/components/dialogs/LaunchOptionsDialog.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/components/dialogs/LaunchOptionsDialog.svelte b/src/lib/components/dialogs/LaunchOptionsDialog.svelte index 6d03a1d3..3a0abb3e 100644 --- a/src/lib/components/dialogs/LaunchOptionsDialog.svelte +++ b/src/lib/components/dialogs/LaunchOptionsDialog.svelte @@ -4,7 +4,6 @@ import { RadioGroup } from 'bits-ui'; import type { LaunchOption } from '$lib/types'; import { formatLaunchOptionName } from '$lib/util'; - import Icon from '@iconify/svelte'; interface Props { open: boolean; From 916eb67e7faa63a560c3eecc2f880c9f790eb560 Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Tue, 14 Oct 2025 22:57:38 +0200 Subject: [PATCH 11/11] Fix options entries from other branches showing up --- src-tauri/src/profile/launch/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src-tauri/src/profile/launch/mod.rs b/src-tauri/src/profile/launch/mod.rs index ee7b73fe..42f1eea1 100644 --- a/src-tauri/src/profile/launch/mod.rs +++ b/src-tauri/src/profile/launch/mod.rs @@ -258,6 +258,14 @@ pub fn parse_steam_launch_options(steam_id: u32) -> Result> { if let Some(options_obj) = raw_options.as_object() { for (_, option_value) in options_obj.iter() { if let Some(option) = option_value.as_object() { + // TODO: Figure out how to properly filter by active beta branch. + // Need to find where Steam stores info about which beta branch is active for an app. + if let Some(config) = option.get("config") { + if config.get("BetaKey").is_some() { + continue; + } + } + let option_type = option .get("type") .and_then(|t| t.as_str())