Added config file
Added Steam and Among Us process detection Added ability to auto-run the blessed build
This commit is contained in:
@@ -12,6 +12,7 @@ regex = "1.5"
|
|||||||
fs_extra = "1.2.0"
|
fs_extra = "1.2.0"
|
||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
reqwest = {version = "0.11.11", features = ["blocking"]}
|
reqwest = {version = "0.11.11", features = ["blocking"]}
|
||||||
|
serde = {version= "1.0.143", features = ["derive"]}
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
md-5 = "0.10.5"
|
md-5 = "0.10.5"
|
||||||
tokio = {version="1", features=["full"]}
|
tokio = {version="1", features=["full"]}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// Crate imports
|
// Crate imports
|
||||||
use crate::among_us_version::*;
|
use crate::among_us_version::*;
|
||||||
|
use crate::config;
|
||||||
|
use crate::config::*;
|
||||||
use crate::semver::*;
|
use crate::semver::*;
|
||||||
|
|
||||||
// Other imports
|
// Other imports
|
||||||
@@ -47,10 +49,13 @@ pub struct AppData {
|
|||||||
pub installs_list: Vec<PathBuf>,
|
pub installs_list: Vec<PathBuf>,
|
||||||
pub init_install_path: Option<PathBuf>,
|
pub init_install_path: Option<PathBuf>,
|
||||||
pub init_download_url: Option<String>,
|
pub init_download_url: Option<String>,
|
||||||
pub steam_running: bool,
|
pub launcher_running: bool,
|
||||||
|
pub config: AppConfig,
|
||||||
|
pub among_us_launched: bool,
|
||||||
|
pub among_us_running: bool,
|
||||||
|
|
||||||
// Thread handles
|
// Thread handles
|
||||||
pub find_among_us_handle: Option<JoinHandle<Option<String>>>,
|
pub find_among_us_handle: Option<JoinHandle<Option<(String, LauncherType)>>>,
|
||||||
pub determine_au_version_handle: Option<JoinHandle<Option<AmongUsVersion>>>,
|
pub determine_au_version_handle: Option<JoinHandle<Option<AmongUsVersion>>>,
|
||||||
pub determine_tou_version_handle: Option<JoinHandle<Option<(String, String, bool)>>>,
|
pub determine_tou_version_handle: Option<JoinHandle<Option<(String, String, bool)>>>,
|
||||||
pub copy_au_handle: Option<JoinHandle<()>>,
|
pub copy_au_handle: Option<JoinHandle<()>>,
|
||||||
@@ -77,7 +82,10 @@ impl Default for AppData {
|
|||||||
installs_list: Vec::new(),
|
installs_list: Vec::new(),
|
||||||
init_install_path: None,
|
init_install_path: None,
|
||||||
init_download_url: None,
|
init_download_url: None,
|
||||||
steam_running: false,
|
launcher_running: false,
|
||||||
|
config: AppConfig::default(),
|
||||||
|
among_us_launched: false,
|
||||||
|
among_us_running: false,
|
||||||
find_among_us_handle: None,
|
find_among_us_handle: None,
|
||||||
determine_au_version_handle: None,
|
determine_au_version_handle: None,
|
||||||
determine_tou_version_handle: None,
|
determine_tou_version_handle: None,
|
||||||
@@ -92,12 +100,28 @@ impl AppData {
|
|||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let tl = tasklist::Tasklist::new();
|
let tl = tasklist::Tasklist::new();
|
||||||
|
self.launcher_running = false;
|
||||||
for i in tl {
|
for i in tl {
|
||||||
if i.get_pname() == "steam.exe" {
|
if i.get_pname() == "steam.exe" {
|
||||||
self.steam_running = true;
|
self.launcher_running = true;
|
||||||
println!("Steam running!");
|
// println!("Steam running!");
|
||||||
} else if i.get_pname() == "EpicGamesLauncher.exe" {
|
} else if i.get_pname() == "EpicGamesLauncher.exe" {
|
||||||
println!("Epic is running!");
|
// println!("Epic is running!");
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn detect_running_among_us(&mut self) {
|
||||||
|
if cfg!(windows) {
|
||||||
|
unsafe {
|
||||||
|
let tl = tasklist::Tasklist::new();
|
||||||
|
self.among_us_running = false;
|
||||||
|
for i in tl {
|
||||||
|
if i.get_pname() == "Among Us.exe" {
|
||||||
|
self.among_us_running = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,16 +285,32 @@ impl AppData {
|
|||||||
let button_text = egui::RichText::new(button_string.clone())
|
let button_text = egui::RichText::new(button_string.clone())
|
||||||
.size(25.0)
|
.size(25.0)
|
||||||
.color(egui::Color32::GREEN);
|
.color(egui::Color32::GREEN);
|
||||||
if ui.button(button_text).clicked() {
|
|
||||||
|
let auto_run = self.config.auto_run_blessed
|
||||||
|
&& !self.among_us_launched
|
||||||
|
&& self.launcher_running;
|
||||||
|
|
||||||
|
if ui
|
||||||
|
.add_enabled(!self.among_us_running, egui::Button::new(button_text))
|
||||||
|
.clicked()
|
||||||
|
|| auto_run
|
||||||
|
{
|
||||||
crate::attempt_run_among_us(&clone);
|
crate::attempt_run_among_us(&clone);
|
||||||
|
self.among_us_launched = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let button_text = egui::RichText::new(button_string.clone()).size(25.0);
|
let button_text = egui::RichText::new(button_string.clone()).size(25.0);
|
||||||
if ui.button(button_text).clicked() {
|
if ui
|
||||||
|
.add_enabled(!self.among_us_running, egui::Button::new(button_text))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
crate::attempt_run_among_us(&clone);
|
crate::attempt_run_among_us(&clone);
|
||||||
|
self.among_us_launched = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.set_enabled(true);
|
||||||
|
|
||||||
if !self.delete_mode {
|
if !self.delete_mode {
|
||||||
ui.set_visible(false);
|
ui.set_visible(false);
|
||||||
}
|
}
|
||||||
@@ -323,7 +363,11 @@ impl eframe::App for AppData {
|
|||||||
if self.find_among_us_handle.as_ref().unwrap().is_finished() {
|
if self.find_among_us_handle.as_ref().unwrap().is_finished() {
|
||||||
if let Some(handle) = self.find_among_us_handle.take() {
|
if let Some(handle) = self.find_among_us_handle.take() {
|
||||||
println!("Thread done, retrieving data...");
|
println!("Thread done, retrieving data...");
|
||||||
self.among_us_path = handle.join().unwrap().unwrap();
|
let (path, launcher_type) = handle.join().unwrap().unwrap();
|
||||||
|
self.among_us_path = path.clone();
|
||||||
|
self.config.among_us_path = Some(PathBuf::from(path));
|
||||||
|
self.config.launcher_type = launcher_type;
|
||||||
|
config::save_config(&self.config);
|
||||||
self.app_state = GlobalAppState::Initializing(
|
self.app_state = GlobalAppState::Initializing(
|
||||||
InitializingState::DeterminingVersion,
|
InitializingState::DeterminingVersion,
|
||||||
);
|
);
|
||||||
@@ -553,20 +597,32 @@ impl eframe::App for AppData {
|
|||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
GlobalAppState::Initialized => {
|
GlobalAppState::Initialized => {
|
||||||
|
self.detect_running_stores();
|
||||||
|
self.detect_running_among_us();
|
||||||
if self.update_installs_list {
|
if self.update_installs_list {
|
||||||
self.detect_installs();
|
self.detect_installs();
|
||||||
self.update_installs_list = false;
|
self.update_installs_list = false;
|
||||||
}
|
}
|
||||||
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||||
ui.checkbox(&mut self.delete_mode, "DELETE MODE");
|
ui.checkbox(&mut self.delete_mode, "DELETE MODE");
|
||||||
|
if ui
|
||||||
|
.checkbox(&mut self.config.auto_run_blessed, "Auto run blessed build")
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
config::save_config(&self.config);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
if !self.steam_running {
|
if !self.launcher_running {
|
||||||
let warning_text = egui::RichText::new("STEAM IS NOT RUNNING")
|
let warning_string = match self.config.launcher_type {
|
||||||
|
LauncherType::Steam => "STEAM IS NOT RUNNING",
|
||||||
|
LauncherType::Epic => "EPIC IS NOT RUNNING",
|
||||||
|
_ => "UNKNOWN LAUNCHER USED",
|
||||||
|
};
|
||||||
|
let warning_text = egui::RichText::new(warning_string)
|
||||||
// .size(25.0)
|
// .size(25.0)
|
||||||
.color(egui::Color32::RED);
|
.color(egui::Color32::RED);
|
||||||
ui.heading(warning_text);
|
ui.heading(warning_text);
|
||||||
self.detect_running_stores();
|
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
}
|
}
|
||||||
self.draw_layout(ui);
|
self.draw_layout(ui);
|
||||||
|
|||||||
39
src/config.rs
Normal file
39
src/config.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Default, Debug)]
|
||||||
|
pub enum LauncherType {
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
Steam,
|
||||||
|
Epic,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Default, Debug)]
|
||||||
|
pub struct AppConfig {
|
||||||
|
pub launcher_type: LauncherType,
|
||||||
|
pub among_us_path: Option<PathBuf>,
|
||||||
|
pub auto_run_blessed: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_config() -> Option<AppConfig> {
|
||||||
|
let mut config_path = dirs::data_dir().unwrap();
|
||||||
|
config_path.push("town-of-us-updater");
|
||||||
|
config_path.push("settings.json");
|
||||||
|
if let Ok(string) = fs::read_to_string(config_path) {
|
||||||
|
let app_config: AppConfig = serde_json::from_str(string.as_str()).unwrap();
|
||||||
|
return Some(app_config);
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save_config(app_data: &AppConfig) {
|
||||||
|
println!("Saving config");
|
||||||
|
let mut config_path = dirs::data_dir().unwrap();
|
||||||
|
config_path.push("town-of-us-updater");
|
||||||
|
config_path.push("settings.json");
|
||||||
|
|
||||||
|
let json = serde_json::to_string_pretty(app_data).unwrap();
|
||||||
|
fs::write(config_path, json).unwrap();
|
||||||
|
}
|
||||||
56
src/main.rs
56
src/main.rs
@@ -1,11 +1,13 @@
|
|||||||
// Module definitions
|
// Module definitions
|
||||||
mod among_us_version;
|
mod among_us_version;
|
||||||
mod app_data;
|
mod app_data;
|
||||||
|
mod config;
|
||||||
mod semver;
|
mod semver;
|
||||||
|
|
||||||
// Crate imports
|
// Crate imports
|
||||||
use among_us_version::*;
|
use among_us_version::*;
|
||||||
use app_data::*;
|
use app_data::*;
|
||||||
|
use config::LauncherType;
|
||||||
|
|
||||||
// Other imports
|
// Other imports
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
@@ -15,7 +17,6 @@ use std::{
|
|||||||
fs, io,
|
fs, io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process, str, thread,
|
process, str, thread,
|
||||||
time::Duration,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use fs_extra::{copy_items, dir};
|
use fs_extra::{copy_items, dir};
|
||||||
@@ -31,6 +32,8 @@ use eframe::egui;
|
|||||||
|
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
|
struct CombinedVersion(AmongUsVersion, SemVer);
|
||||||
|
|
||||||
static AMONG_US_APPID: &str = "945360";
|
static AMONG_US_APPID: &str = "945360";
|
||||||
|
|
||||||
fn attempt_run_among_us(install_path: &Path) {
|
fn attempt_run_among_us(install_path: &Path) {
|
||||||
@@ -114,6 +117,7 @@ async fn _get_latest_updater_version() -> Result<(String, String), reqwest::Erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let app_config = config::load_config().unwrap_or_default();
|
||||||
let version = env!("CARGO_PKG_VERSION");
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
let title_string: String = format!("Town of Us Updater - {}", version);
|
let title_string: String = format!("Town of Us Updater - {}", version);
|
||||||
let blessed_body = reqwest::blocking::get("https://tou.dormedas.com/blessed");
|
let blessed_body = reqwest::blocking::get("https://tou.dormedas.com/blessed");
|
||||||
@@ -242,9 +246,9 @@ fn main() {
|
|||||||
if let Ok(existing_folder) = existing_found_folder {
|
if let Ok(existing_folder) = existing_found_folder {
|
||||||
among_us_folder.push(existing_folder);
|
among_us_folder.push(existing_folder);
|
||||||
} else {
|
} else {
|
||||||
let folder_opt: Option<String> = detect_among_us_folder();
|
let folder_opt: Option<(String, LauncherType)> = detect_among_us_folder();
|
||||||
if folder_opt.is_some() {
|
if folder_opt.is_some() {
|
||||||
among_us_folder.push(folder_opt.unwrap());
|
among_us_folder.push(folder_opt.unwrap().0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if among_us_folder.exists() {
|
if among_us_folder.exists() {
|
||||||
@@ -267,7 +271,10 @@ fn main() {
|
|||||||
installs_list: Vec::new(),
|
installs_list: Vec::new(),
|
||||||
init_install_path: None,
|
init_install_path: None,
|
||||||
init_download_url: None,
|
init_download_url: None,
|
||||||
steam_running: false,
|
launcher_running: false,
|
||||||
|
config: app_config,
|
||||||
|
among_us_launched: false,
|
||||||
|
among_us_running: false,
|
||||||
find_among_us_handle: None,
|
find_among_us_handle: None,
|
||||||
determine_au_version_handle: None,
|
determine_au_version_handle: None,
|
||||||
determine_tou_version_handle: None,
|
determine_tou_version_handle: None,
|
||||||
@@ -422,17 +429,7 @@ fn copy_folder_contents_to_target<T: AsRef<Path>>(source: T, dest: T) {
|
|||||||
fs_extra::dir::copy(source, dest, ©_opts).unwrap();
|
fs_extra::dir::copy(source, dest, ©_opts).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _detect_steam() -> Option<String> {
|
fn detect_steam() -> Option<(String, LauncherType)> {
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn _detect_epic() -> Option<String> {
|
|
||||||
let _default_folder = String::from("C:\\Program Files\\Epic Games\\AmongUs");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn detect_among_us_folder() -> Option<String> {
|
|
||||||
if cfg!(windows) {
|
|
||||||
let mut library_folder_path: PathBuf =
|
let mut library_folder_path: PathBuf =
|
||||||
PathBuf::from("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");
|
PathBuf::from("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");
|
||||||
if let Ok(steam_regkey) = Hive::LocalMachine.open(
|
if let Ok(steam_regkey) = Hive::LocalMachine.open(
|
||||||
@@ -447,9 +444,7 @@ fn detect_among_us_folder() -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let library_folder =
|
let library_folder = fs::read_to_string(library_folder_path.to_str().expect("Path invalid"));
|
||||||
fs::read_to_string(library_folder_path.to_str().expect("Path invalid"));
|
|
||||||
// thread::sleep(Duration::from_secs(5));
|
|
||||||
|
|
||||||
if library_folder.is_ok() {
|
if library_folder.is_ok() {
|
||||||
let mut library_folder_string: String = library_folder.unwrap();
|
let mut library_folder_string: String = library_folder.unwrap();
|
||||||
@@ -466,13 +461,36 @@ fn detect_among_us_folder() -> Option<String> {
|
|||||||
let last_path = caps.last().unwrap();
|
let last_path = caps.last().unwrap();
|
||||||
let start = last_path.get(last_path.len() - 1).unwrap();
|
let start = last_path.get(last_path.len() - 1).unwrap();
|
||||||
|
|
||||||
return Some(format!(
|
return Some((
|
||||||
|
format!(
|
||||||
r"{}\\steamapps\\common\\Among Us\\",
|
r"{}\\steamapps\\common\\Among Us\\",
|
||||||
library_folder_string
|
library_folder_string
|
||||||
.get(start.start()..start.end())
|
.get(start.start()..start.end())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
),
|
||||||
|
LauncherType::Steam,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detect_epic() -> Option<(String, LauncherType)> {
|
||||||
|
let default_folder = Path::new("C:\\Program Files\\Epic Games\\AmongUs");
|
||||||
|
if default_folder.exists() {
|
||||||
|
return Some((default_folder.to_string_lossy().into(), LauncherType::Epic));
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detect_among_us_folder() -> Option<(String, LauncherType)> {
|
||||||
|
if cfg!(windows) {
|
||||||
|
// Default to Steam
|
||||||
|
let return_val = detect_steam();
|
||||||
|
if return_val.is_none() {
|
||||||
|
return detect_epic();
|
||||||
|
} else {
|
||||||
|
return return_val;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in New Issue
Block a user