Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63b58bbe05 | |||
| 399b975aaf | |||
| ed50979397 | |||
| 762b2f61aa |
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "town-of-us-updater"
|
name = "town-of-us-updater"
|
||||||
version = "4.0.0"
|
version = "4.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "src/build.rs"
|
build = "src/build.rs"
|
||||||
|
|
||||||
@@ -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"]}
|
||||||
@@ -19,6 +20,7 @@ registry = "1"
|
|||||||
egui = "0.20.1"
|
egui = "0.20.1"
|
||||||
eframe = "0.20.1"
|
eframe = "0.20.1"
|
||||||
rfd = "0.10"
|
rfd = "0.10"
|
||||||
|
tasklist = "0.2.12"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
embed-resource = "1.6"
|
embed-resource = "1.6"
|
||||||
|
|||||||
636
src/app_data.rs
Normal file
636
src/app_data.rs
Normal file
@@ -0,0 +1,636 @@
|
|||||||
|
// Crate imports
|
||||||
|
use crate::among_us_version::*;
|
||||||
|
use crate::config;
|
||||||
|
use crate::config::*;
|
||||||
|
use crate::semver::*;
|
||||||
|
|
||||||
|
// Other imports
|
||||||
|
use eframe::egui;
|
||||||
|
use std::thread::JoinHandle;
|
||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process, thread,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
pub enum InitializingState {
|
||||||
|
StartingGUI,
|
||||||
|
FindingAmongUs,
|
||||||
|
DeterminingVersion,
|
||||||
|
DeterminingToUVersion,
|
||||||
|
CopyingAmongUs,
|
||||||
|
UnmoddingAmongUs,
|
||||||
|
DownloadingZip,
|
||||||
|
Unzipping,
|
||||||
|
ModdingAmongUs,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
pub enum GlobalAppState {
|
||||||
|
Initializing(InitializingState),
|
||||||
|
Initialized,
|
||||||
|
Installing,
|
||||||
|
Playing,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct AppData {
|
||||||
|
pub among_us_path: String,
|
||||||
|
pub installs_path: String,
|
||||||
|
pub version: SemVer,
|
||||||
|
pub delete_mode: bool,
|
||||||
|
pub among_us_version: AmongUsVersion,
|
||||||
|
pub data_path: String,
|
||||||
|
pub app_state: GlobalAppState,
|
||||||
|
pub blessed_version: String,
|
||||||
|
pub update_installs_list: bool,
|
||||||
|
pub installs_last_update_time: std::time::Instant,
|
||||||
|
pub installs_list: Vec<PathBuf>,
|
||||||
|
pub init_install_path: Option<PathBuf>,
|
||||||
|
pub init_download_url: Option<String>,
|
||||||
|
pub launcher_running: bool,
|
||||||
|
pub config: AppConfig,
|
||||||
|
pub among_us_launched: bool,
|
||||||
|
pub among_us_running: bool,
|
||||||
|
|
||||||
|
// Thread handles
|
||||||
|
pub find_among_us_handle: Option<JoinHandle<Option<(String, LauncherType)>>>,
|
||||||
|
pub determine_au_version_handle: Option<JoinHandle<Option<AmongUsVersion>>>,
|
||||||
|
pub determine_tou_version_handle: Option<JoinHandle<Option<(String, String, bool)>>>,
|
||||||
|
pub copy_au_handle: Option<JoinHandle<()>>,
|
||||||
|
pub download_tou_handle: Option<JoinHandle<()>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppData {
|
||||||
|
fn default() -> AppData {
|
||||||
|
AppData {
|
||||||
|
among_us_path: String::new(),
|
||||||
|
installs_path: String::new(),
|
||||||
|
version: SemVer {
|
||||||
|
major: 0,
|
||||||
|
minor: 0,
|
||||||
|
patch: 0,
|
||||||
|
},
|
||||||
|
delete_mode: false,
|
||||||
|
among_us_version: AmongUsVersion::default(),
|
||||||
|
data_path: String::new(),
|
||||||
|
app_state: GlobalAppState::Initialized,
|
||||||
|
blessed_version: String::new(),
|
||||||
|
update_installs_list: true,
|
||||||
|
installs_last_update_time: std::time::Instant::now(),
|
||||||
|
installs_list: Vec::new(),
|
||||||
|
init_install_path: None,
|
||||||
|
init_download_url: None,
|
||||||
|
launcher_running: false,
|
||||||
|
config: AppConfig::default(),
|
||||||
|
among_us_launched: false,
|
||||||
|
among_us_running: false,
|
||||||
|
find_among_us_handle: None,
|
||||||
|
determine_au_version_handle: None,
|
||||||
|
determine_tou_version_handle: None,
|
||||||
|
copy_au_handle: None,
|
||||||
|
download_tou_handle: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppData {
|
||||||
|
pub fn detect_running_stores(&mut self) {
|
||||||
|
if cfg!(windows) {
|
||||||
|
unsafe {
|
||||||
|
let tl = tasklist::Tasklist::new();
|
||||||
|
self.launcher_running = false;
|
||||||
|
for i in tl {
|
||||||
|
if i.get_pname() == "steam.exe" {
|
||||||
|
self.launcher_running = true;
|
||||||
|
// println!("Steam running!");
|
||||||
|
} else if i.get_pname() == "EpicGamesLauncher.exe" {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn on_path_added(&mut self) {
|
||||||
|
if self.among_us_path.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(among_us_version) =
|
||||||
|
crate::determine_among_us_version(String::from(self.among_us_path.clone()))
|
||||||
|
{
|
||||||
|
self.among_us_version = among_us_version.clone();
|
||||||
|
println!("AmongUsVersion: {}", among_us_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.app_state = GlobalAppState::Initializing(InitializingState::DeterminingVersion);
|
||||||
|
let ver_url: (String, String, bool) =
|
||||||
|
crate::determine_town_of_us_url(self.among_us_version.to_string().clone()).unwrap();
|
||||||
|
|
||||||
|
let version_smash = format!("{}-{}", self.among_us_version, ver_url.0.clone());
|
||||||
|
let new_installed_path: PathBuf = [self.installs_path.as_str(), version_smash.as_str()]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if !Path::exists(&new_installed_path) {
|
||||||
|
println!("Copying Among Us to cache location...");
|
||||||
|
crate::copy_folder_to_target(self.among_us_path.clone(), self.installs_path.clone());
|
||||||
|
|
||||||
|
let among_us_path: PathBuf = [self.installs_path.as_str(), "Among Us"].iter().collect();
|
||||||
|
|
||||||
|
if !among_us_path.to_str().unwrap().contains("Among Us") {
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un-mod whatever we found if it's modded
|
||||||
|
crate::unmod_among_us_folder(&among_us_path);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Renaming {} to {}",
|
||||||
|
among_us_path.to_str().unwrap(),
|
||||||
|
new_installed_path.to_str().unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut perms = fs::metadata(among_us_path.clone()).unwrap().permissions();
|
||||||
|
perms.set_readonly(false);
|
||||||
|
fs::set_permissions(among_us_path.clone(), perms).unwrap();
|
||||||
|
|
||||||
|
fs::rename(among_us_path, new_installed_path.clone()).unwrap();
|
||||||
|
let mut download_path: PathBuf = [self.data_path.as_str()].iter().collect();
|
||||||
|
let downloaded_filename: &str = ver_url.1.rsplit('/').next().unwrap();
|
||||||
|
download_path.push(downloaded_filename);
|
||||||
|
|
||||||
|
if !download_path.exists() {
|
||||||
|
// println!("{:?}", download_path);
|
||||||
|
println!(
|
||||||
|
"Downloading Town of Us... Please be patient! [{}]",
|
||||||
|
ver_url.1.clone()
|
||||||
|
);
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
.timeout(None)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
let zip_request = client.get(ver_url.1.clone()).build().unwrap();
|
||||||
|
let zip = client.execute(zip_request).unwrap().bytes().unwrap();
|
||||||
|
fs::write(download_path.clone(), zip).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let opened_zip = fs::File::open(download_path.clone()).unwrap();
|
||||||
|
println!("Extracting mod zip file...");
|
||||||
|
let mut archive = zip::ZipArchive::new(opened_zip).unwrap();
|
||||||
|
archive.extract(self.data_path.clone()).unwrap();
|
||||||
|
|
||||||
|
fs::remove_file(download_path).unwrap();
|
||||||
|
|
||||||
|
let mut root_folder_path = String::new();
|
||||||
|
for i in archive.file_names() {
|
||||||
|
root_folder_path = String::from(i.split('/').next().unwrap());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let extracted_path: PathBuf = [self.data_path.as_str(), root_folder_path.as_str(), "."]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
|
println!("{}", extracted_path.to_str().unwrap());
|
||||||
|
crate::copy_folder_contents_to_target(
|
||||||
|
extracted_path.to_str().unwrap(),
|
||||||
|
new_installed_path.to_str().unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
self.app_state = GlobalAppState::Initialized;
|
||||||
|
self.update_installs_list = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn detect_installs(&mut self) {
|
||||||
|
let install_iter = fs::read_dir(self.installs_path.clone());
|
||||||
|
if let Ok(iter) = install_iter {
|
||||||
|
self.installs_list = iter
|
||||||
|
.map(|elem| PathBuf::from(elem.unwrap().file_name()))
|
||||||
|
.collect();
|
||||||
|
} else {
|
||||||
|
self.installs_list.clear();
|
||||||
|
}
|
||||||
|
self.installs_last_update_time = std::time::Instant::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_layout(&mut self, ui: &mut egui::Ui) {
|
||||||
|
let now = std::time::Instant::now();
|
||||||
|
if now.duration_since(self.installs_last_update_time) > std::time::Duration::from_secs(10) {
|
||||||
|
self.detect_installs();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut collection = self.installs_list.clone();
|
||||||
|
|
||||||
|
if collection.is_empty() {
|
||||||
|
if ui.button("Locate your Among Us Directory").clicked() {
|
||||||
|
if let Some(mut path) = rfd::FileDialog::new().pick_file() {
|
||||||
|
path.pop();
|
||||||
|
self.among_us_path = path.display().to_string();
|
||||||
|
self.on_path_added();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.reverse();
|
||||||
|
let mut auv_array: Vec<AmongUsVersion> = Vec::new();
|
||||||
|
|
||||||
|
for i in &collection {
|
||||||
|
let existing_ver_smash = i;
|
||||||
|
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
|
||||||
|
let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
|
||||||
|
if !auv_array.contains(&among_us_version) {
|
||||||
|
auv_array.push(among_us_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auv_array.sort();
|
||||||
|
auv_array.reverse();
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
for i in &auv_array {
|
||||||
|
ui.label(
|
||||||
|
egui::RichText::new(format!("Among Us {}", i.as_american_string())).size(35.0),
|
||||||
|
);
|
||||||
|
for j in &collection {
|
||||||
|
let existing_ver_smash = j;
|
||||||
|
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
|
||||||
|
let mut blessed_split = self.blessed_version.as_str().split('-');
|
||||||
|
let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
|
||||||
|
let tou_version = ver_smash_split.next().unwrap();
|
||||||
|
let blessed_version = AmongUsVersion::from(blessed_split.next().unwrap());
|
||||||
|
let blessed_tou_version = blessed_split.next().unwrap();
|
||||||
|
let button_string: String = format!("Town of Us {}", tou_version);
|
||||||
|
if i == &among_us_version {
|
||||||
|
let mut clone: PathBuf = PathBuf::from(self.installs_path.clone());
|
||||||
|
clone.push(existing_ver_smash.clone());
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if i == &blessed_version && tou_version == blessed_tou_version {
|
||||||
|
let button_text = egui::RichText::new(button_string.clone())
|
||||||
|
.size(25.0)
|
||||||
|
.color(egui::Color32::GREEN);
|
||||||
|
|
||||||
|
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);
|
||||||
|
self.among_us_launched = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let button_text = egui::RichText::new(button_string.clone()).size(25.0);
|
||||||
|
if ui
|
||||||
|
.add_enabled(!self.among_us_running, egui::Button::new(button_text))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
crate::attempt_run_among_us(&clone);
|
||||||
|
self.among_us_launched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.set_enabled(true);
|
||||||
|
|
||||||
|
if !self.delete_mode {
|
||||||
|
ui.set_visible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
let button_text = egui::RichText::new("DELETE")
|
||||||
|
.size(25.0)
|
||||||
|
.color(egui::Color32::RED);
|
||||||
|
|
||||||
|
if ui.button(button_text).clicked() {
|
||||||
|
if i != &blessed_version || tou_version != blessed_tou_version {
|
||||||
|
crate::attempt_delete_among_us(&clone);
|
||||||
|
self.update_installs_list = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.set_visible(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl eframe::App for AppData {
|
||||||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
|
match &mut self.app_state {
|
||||||
|
GlobalAppState::Initializing(sub_state) => match sub_state {
|
||||||
|
InitializingState::StartingGUI => {
|
||||||
|
if !self.among_us_path.is_empty() {
|
||||||
|
// If we pulled in a cached location, skip straight to ToU version check
|
||||||
|
self.app_state =
|
||||||
|
GlobalAppState::Initializing(InitializingState::DeterminingVersion);
|
||||||
|
} else {
|
||||||
|
self.app_state =
|
||||||
|
GlobalAppState::Initializing(InitializingState::FindingAmongUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Initializing...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
InitializingState::FindingAmongUs => {
|
||||||
|
// if !self.among_us_path.is_empty() {
|
||||||
|
// self.app_state =
|
||||||
|
// GlobalAppState::Initializing(InitializingState::DeterminingVersion);
|
||||||
|
// }
|
||||||
|
if self.find_among_us_handle.as_ref().is_some() {
|
||||||
|
if self.find_among_us_handle.as_ref().unwrap().is_finished() {
|
||||||
|
if let Some(handle) = self.find_among_us_handle.take() {
|
||||||
|
println!("Thread done, retrieving data...");
|
||||||
|
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(
|
||||||
|
InitializingState::DeterminingVersion,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Spawning thread...");
|
||||||
|
self.find_among_us_handle = Some(thread::spawn(|| {
|
||||||
|
return crate::detect_among_us_folder();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Finding Among Us...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
InitializingState::DeterminingVersion => {
|
||||||
|
if self.among_us_version != AmongUsVersion::default() {
|
||||||
|
self.app_state =
|
||||||
|
GlobalAppState::Initializing(InitializingState::DeterminingToUVersion);
|
||||||
|
} else {
|
||||||
|
if self.determine_au_version_handle.as_ref().is_some() {
|
||||||
|
if self
|
||||||
|
.determine_au_version_handle
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.is_finished()
|
||||||
|
{
|
||||||
|
if let Some(handle) = self.determine_au_version_handle.take() {
|
||||||
|
println!("Thread done, retrieving data...");
|
||||||
|
self.among_us_version = handle.join().unwrap().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Spawning thread...");
|
||||||
|
let path = self.among_us_path.clone();
|
||||||
|
self.determine_au_version_handle = Some(thread::spawn(move || {
|
||||||
|
return crate::determine_among_us_version(path);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Determining Among Us Version...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
InitializingState::DeterminingToUVersion => {
|
||||||
|
if self.determine_tou_version_handle.as_ref().is_some() {
|
||||||
|
if self
|
||||||
|
.determine_tou_version_handle
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.is_finished()
|
||||||
|
{
|
||||||
|
if let Some(handle) = self.determine_tou_version_handle.take() {
|
||||||
|
println!("Thread done, retrieving data...");
|
||||||
|
let result = handle.join().unwrap().unwrap();
|
||||||
|
let version_smash =
|
||||||
|
format!("{}-{}", self.among_us_version, result.0.clone());
|
||||||
|
let new_path: PathBuf =
|
||||||
|
[self.installs_path.as_str(), version_smash.as_str()]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
|
self.init_install_path = Some(new_path.clone());
|
||||||
|
self.init_download_url = Some(result.1.clone());
|
||||||
|
|
||||||
|
if !Path::exists(&new_path) {
|
||||||
|
self.app_state = GlobalAppState::Initializing(
|
||||||
|
InitializingState::CopyingAmongUs,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
self.app_state = GlobalAppState::Initialized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Spawning thread...");
|
||||||
|
let ver = self.among_us_version.clone();
|
||||||
|
self.determine_tou_version_handle = Some(thread::spawn(move || {
|
||||||
|
return crate::determine_town_of_us_url(ver.to_string());
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Determining Among Us Version...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
InitializingState::CopyingAmongUs => {
|
||||||
|
if self.copy_au_handle.as_ref().is_some() {
|
||||||
|
if self.copy_au_handle.as_ref().unwrap().is_finished() {
|
||||||
|
self.copy_au_handle = None;
|
||||||
|
self.app_state =
|
||||||
|
GlobalAppState::Initializing(InitializingState::UnmoddingAmongUs);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Spawning thread...");
|
||||||
|
let among_us_path = self.among_us_path.clone();
|
||||||
|
let installs_path = self.installs_path.clone();
|
||||||
|
self.copy_au_handle = Some(thread::spawn(move || {
|
||||||
|
println!("Copying Among Us to cache location...");
|
||||||
|
crate::copy_folder_to_target(among_us_path, installs_path);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Copying Among Us...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
InitializingState::UnmoddingAmongUs => {
|
||||||
|
if self.copy_au_handle.as_ref().is_some() {
|
||||||
|
if self.copy_au_handle.as_ref().unwrap().is_finished() {
|
||||||
|
self.copy_au_handle = None;
|
||||||
|
self.app_state =
|
||||||
|
GlobalAppState::Initializing(InitializingState::DownloadingZip);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: This sucks
|
||||||
|
let new_installed_path = self.init_install_path.as_ref().unwrap().clone();
|
||||||
|
let installs_path = self.installs_path.clone();
|
||||||
|
self.copy_au_handle = Some(thread::spawn(move || {
|
||||||
|
let among_us_path: PathBuf =
|
||||||
|
[installs_path.as_str(), "Among Us"].iter().collect();
|
||||||
|
// Un-mod whatever we found if it's modded
|
||||||
|
crate::unmod_among_us_folder(&among_us_path);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Renaming {} to {}",
|
||||||
|
among_us_path.to_str().unwrap(),
|
||||||
|
new_installed_path.to_str().unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut perms =
|
||||||
|
fs::metadata(among_us_path.clone()).unwrap().permissions();
|
||||||
|
perms.set_readonly(false);
|
||||||
|
fs::set_permissions(among_us_path.clone(), perms).unwrap();
|
||||||
|
|
||||||
|
fs::rename(among_us_path, new_installed_path.clone()).unwrap();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Unmodding Among Us...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
InitializingState::DownloadingZip => {
|
||||||
|
if self.download_tou_handle.as_ref().is_some() {
|
||||||
|
if self.download_tou_handle.as_ref().unwrap().is_finished() {
|
||||||
|
self.download_tou_handle = None;
|
||||||
|
self.app_state =
|
||||||
|
GlobalAppState::Initializing(InitializingState::Unzipping);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let data_path = self.data_path.clone();
|
||||||
|
let download_url = self.init_download_url.as_ref().unwrap().clone();
|
||||||
|
self.download_tou_handle = Some(thread::spawn(move || {
|
||||||
|
let mut download_path: PathBuf = [data_path.as_str()].iter().collect();
|
||||||
|
let downloaded_filename: &str =
|
||||||
|
download_url.rsplit('/').next().unwrap();
|
||||||
|
download_path.push(downloaded_filename);
|
||||||
|
|
||||||
|
if !download_path.exists() {
|
||||||
|
println!(
|
||||||
|
"Downloading Town of Us... Please be patient! [{}]",
|
||||||
|
download_url.clone()
|
||||||
|
);
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
.timeout(None)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
let zip_request = client.get(download_url.clone()).build().unwrap();
|
||||||
|
let zip = client.execute(zip_request).unwrap().bytes().unwrap();
|
||||||
|
fs::write(download_path.clone(), zip).unwrap();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Downloading Town of Us...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
InitializingState::Unzipping => {
|
||||||
|
if self.download_tou_handle.as_ref().is_some() {
|
||||||
|
if self.download_tou_handle.as_ref().unwrap().is_finished() {
|
||||||
|
self.download_tou_handle = None;
|
||||||
|
self.app_state = GlobalAppState::Initialized;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let data_path = self.data_path.clone();
|
||||||
|
let download_url = self.init_download_url.as_ref().unwrap().clone();
|
||||||
|
let new_installed_path = self.init_install_path.as_ref().unwrap().clone();
|
||||||
|
self.download_tou_handle = Some(thread::spawn(move || {
|
||||||
|
let mut download_path: PathBuf = [data_path.as_str()].iter().collect();
|
||||||
|
let downloaded_filename: &str =
|
||||||
|
download_url.rsplit('/').next().unwrap();
|
||||||
|
download_path.push(downloaded_filename);
|
||||||
|
let opened_zip = fs::File::open(download_path.clone()).unwrap();
|
||||||
|
println!("Extracting mod zip file...");
|
||||||
|
let mut archive = zip::ZipArchive::new(opened_zip).unwrap();
|
||||||
|
archive.extract(data_path.clone()).unwrap();
|
||||||
|
|
||||||
|
fs::remove_file(download_path).unwrap();
|
||||||
|
|
||||||
|
let mut root_folder_path = String::new();
|
||||||
|
for i in archive.file_names() {
|
||||||
|
root_folder_path = String::from(i.split('/').next().unwrap());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let extracted_path: PathBuf =
|
||||||
|
[data_path.as_str(), root_folder_path.as_str(), "."]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
|
println!("{}", extracted_path.to_str().unwrap());
|
||||||
|
crate::copy_folder_contents_to_target(
|
||||||
|
extracted_path.to_str().unwrap(),
|
||||||
|
new_installed_path.to_str().unwrap(),
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.heading("Extracting Town of Us...");
|
||||||
|
ui.heading("Modding Among Us...");
|
||||||
|
});
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
GlobalAppState::Initialized => {
|
||||||
|
self.detect_running_stores();
|
||||||
|
self.detect_running_among_us();
|
||||||
|
if self.update_installs_list {
|
||||||
|
self.detect_installs();
|
||||||
|
self.update_installs_list = false;
|
||||||
|
}
|
||||||
|
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||||
|
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| {
|
||||||
|
if !self.launcher_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)
|
||||||
|
.color(egui::Color32::RED);
|
||||||
|
ui.heading(warning_text);
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
self.draw_layout(ui);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
// app_data.on_path_added();
|
||||||
|
// app_data.detect_installs(); // Initial check since we only update every 10s
|
||||||
|
}
|
||||||
|
}
|
||||||
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();
|
||||||
|
}
|
||||||
343
src/main.rs
343
src/main.rs
@@ -1,17 +1,22 @@
|
|||||||
// Modules
|
// Module definitions
|
||||||
mod among_us_version;
|
mod among_us_version;
|
||||||
|
mod app_data;
|
||||||
|
mod config;
|
||||||
mod semver;
|
mod semver;
|
||||||
|
|
||||||
// Uses
|
// Crate imports
|
||||||
use among_us_version::*;
|
use among_us_version::*;
|
||||||
|
use app_data::*;
|
||||||
|
use config::LauncherType;
|
||||||
|
|
||||||
|
// Other imports
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
use semver::*;
|
use semver::*;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs, io,
|
fs, io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process, str,
|
process, str, thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
use fs_extra::{copy_items, dir};
|
use fs_extra::{copy_items, dir};
|
||||||
@@ -27,179 +32,7 @@ use eframe::egui;
|
|||||||
|
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
struct CombinedVersion(AmongUsVersion, SemVer);
|
||||||
pub enum InitializingState {
|
|
||||||
StartingGUI,
|
|
||||||
DeterminingVersion,
|
|
||||||
CopyingAmongUs,
|
|
||||||
UnmoddingAmongUs,
|
|
||||||
DownloadingZip,
|
|
||||||
Unzipping,
|
|
||||||
CopyingZipIn,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
|
||||||
pub enum GlobalAppState {
|
|
||||||
Initializing(InitializingState),
|
|
||||||
Initialized,
|
|
||||||
Installing,
|
|
||||||
Playing,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct AppData {
|
|
||||||
pub among_us_path: String,
|
|
||||||
pub installs_path: String,
|
|
||||||
pub version: SemVer,
|
|
||||||
pub initialized: bool,
|
|
||||||
pub among_us_version: AmongUsVersion,
|
|
||||||
pub data_path: String,
|
|
||||||
pub app_state: GlobalAppState,
|
|
||||||
pub blessed_version: String,
|
|
||||||
pub update_installs_list: bool,
|
|
||||||
pub installs_last_update_time: std::time::Instant,
|
|
||||||
pub installs_list: Vec<PathBuf>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for AppData {
|
|
||||||
fn default() -> AppData {
|
|
||||||
AppData {
|
|
||||||
among_us_path: String::new(),
|
|
||||||
installs_path: String::new(),
|
|
||||||
version: SemVer {
|
|
||||||
major: 0,
|
|
||||||
minor: 0,
|
|
||||||
patch: 0,
|
|
||||||
},
|
|
||||||
initialized: false,
|
|
||||||
among_us_version: AmongUsVersion::default(),
|
|
||||||
data_path: String::new(),
|
|
||||||
app_state: GlobalAppState::Initialized,
|
|
||||||
blessed_version: String::new(),
|
|
||||||
update_installs_list: true,
|
|
||||||
installs_last_update_time: std::time::Instant::now(),
|
|
||||||
installs_list: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AppData {
|
|
||||||
fn detect_installs(&mut self) {
|
|
||||||
let install_iter = fs::read_dir(self.installs_path.clone());
|
|
||||||
if let Ok(iter) = install_iter {
|
|
||||||
self.installs_list = iter
|
|
||||||
.map(|elem| PathBuf::from(elem.unwrap().file_name()))
|
|
||||||
.collect();
|
|
||||||
} else {
|
|
||||||
self.installs_list.clear();
|
|
||||||
}
|
|
||||||
self.installs_last_update_time = std::time::Instant::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_layout(&mut self, ui: &mut egui::Ui) {
|
|
||||||
let now = std::time::Instant::now();
|
|
||||||
if now.duration_since(self.installs_last_update_time) > std::time::Duration::from_secs(10) {
|
|
||||||
self.detect_installs();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut collection = self.installs_list.clone();
|
|
||||||
|
|
||||||
if collection.is_empty() {
|
|
||||||
if ui.button("Locate your Among Us Directory").clicked() {
|
|
||||||
if let Some(mut path) = rfd::FileDialog::new().pick_file() {
|
|
||||||
path.pop();
|
|
||||||
self.among_us_path = path.display().to_string();
|
|
||||||
self.on_path_added();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
collection.reverse();
|
|
||||||
let mut auv_array: Vec<AmongUsVersion> = Vec::new();
|
|
||||||
|
|
||||||
for i in &collection {
|
|
||||||
let existing_ver_smash = i;
|
|
||||||
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
|
|
||||||
let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
|
|
||||||
if !auv_array.contains(&among_us_version) {
|
|
||||||
auv_array.push(among_us_version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auv_array.sort();
|
|
||||||
auv_array.reverse();
|
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
for i in &auv_array {
|
|
||||||
ui.label(
|
|
||||||
egui::RichText::new(format!("Among Us {}", i.as_american_string())).size(35.0),
|
|
||||||
);
|
|
||||||
for j in &collection {
|
|
||||||
let existing_ver_smash = j;
|
|
||||||
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
|
|
||||||
let mut blessed_split = self.blessed_version.as_str().split('-');
|
|
||||||
let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
|
|
||||||
let tou_version = ver_smash_split.next().unwrap();
|
|
||||||
let blessed_version = AmongUsVersion::from(blessed_split.next().unwrap());
|
|
||||||
let blessed_tou_version = blessed_split.next().unwrap();
|
|
||||||
let button_string: String = format!("Town of Us {}", tou_version);
|
|
||||||
if i == &among_us_version {
|
|
||||||
let mut clone: PathBuf = PathBuf::from(self.installs_path.clone());
|
|
||||||
clone.push(existing_ver_smash.clone());
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if i == &blessed_version && tou_version == blessed_tou_version {
|
|
||||||
let button_text = egui::RichText::new(button_string.clone())
|
|
||||||
.size(25.0)
|
|
||||||
.color(egui::Color32::GREEN);
|
|
||||||
if ui.button(button_text).clicked() {
|
|
||||||
crate::attempt_run_among_us(&clone);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let button_text = egui::RichText::new(button_string.clone()).size(25.0);
|
|
||||||
if ui.button(button_text).clicked() {
|
|
||||||
crate::attempt_run_among_us(&clone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.initialized {
|
|
||||||
ui.set_visible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let button_text = egui::RichText::new("DELETE")
|
|
||||||
.size(25.0)
|
|
||||||
.color(egui::Color32::RED);
|
|
||||||
|
|
||||||
if ui.button(button_text).clicked() {
|
|
||||||
if i != &blessed_version || tou_version != blessed_tou_version {
|
|
||||||
crate::attempt_delete_among_us(&clone);
|
|
||||||
self.update_installs_list = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.set_visible(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui.separator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl eframe::App for AppData {
|
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
||||||
if self.update_installs_list {
|
|
||||||
self.detect_installs();
|
|
||||||
self.update_installs_list = false;
|
|
||||||
}
|
|
||||||
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
|
||||||
ui.checkbox(&mut self.initialized, "DELETE MODE");
|
|
||||||
});
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
|
||||||
self.draw_layout(ui);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static AMONG_US_APPID: &str = "945360";
|
static AMONG_US_APPID: &str = "945360";
|
||||||
|
|
||||||
@@ -283,95 +116,8 @@ async fn _get_latest_updater_version() -> Result<(String, String), reqwest::Erro
|
|||||||
Ok((String::from("no"), String::from("yes")))
|
Ok((String::from("no"), String::from("yes")))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppData {
|
|
||||||
fn on_path_added(&mut self) {
|
|
||||||
if let Some(among_us_version) =
|
|
||||||
determine_among_us_version(String::from(self.among_us_path.clone()))
|
|
||||||
{
|
|
||||||
self.among_us_version = among_us_version.clone();
|
|
||||||
println!("AmongUsVersion: {}", among_us_version);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.app_state = GlobalAppState::Initializing(InitializingState::DeterminingVersion);
|
|
||||||
let ver_url: (String, String, bool) =
|
|
||||||
determine_town_of_us_url(self.among_us_version.to_string().clone()).unwrap();
|
|
||||||
|
|
||||||
let version_smash = format!("{}-{}", self.among_us_version, ver_url.0.clone());
|
|
||||||
let new_installed_path: PathBuf = [self.installs_path.as_str(), version_smash.as_str()]
|
|
||||||
.iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if !Path::exists(&new_installed_path) {
|
|
||||||
println!("Copying Among Us to cache location...");
|
|
||||||
copy_folder_to_target(self.among_us_path.clone(), self.installs_path.clone());
|
|
||||||
|
|
||||||
let among_us_path: PathBuf = [self.installs_path.as_str(), "Among Us"].iter().collect();
|
|
||||||
|
|
||||||
if !among_us_path.to_str().unwrap().contains("Among Us") {
|
|
||||||
process::exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Un-mod whatever we found if it's modded
|
|
||||||
unmod_among_us_folder(&among_us_path);
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"Renaming {} to {}",
|
|
||||||
among_us_path.to_str().unwrap(),
|
|
||||||
new_installed_path.to_str().unwrap()
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut perms = fs::metadata(among_us_path.clone()).unwrap().permissions();
|
|
||||||
perms.set_readonly(false);
|
|
||||||
fs::set_permissions(among_us_path.clone(), perms).unwrap();
|
|
||||||
|
|
||||||
fs::rename(among_us_path, new_installed_path.clone()).unwrap();
|
|
||||||
let mut download_path: PathBuf = [self.data_path.as_str()].iter().collect();
|
|
||||||
let downloaded_filename: &str = ver_url.1.rsplit('/').next().unwrap();
|
|
||||||
download_path.push(downloaded_filename);
|
|
||||||
|
|
||||||
if !download_path.exists() {
|
|
||||||
// println!("{:?}", download_path);
|
|
||||||
println!(
|
|
||||||
"Downloading Town of Us... Please be patient! [{}]",
|
|
||||||
ver_url.1.clone()
|
|
||||||
);
|
|
||||||
let client = reqwest::blocking::Client::builder()
|
|
||||||
.timeout(None)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
let zip_request = client.get(ver_url.1.clone()).build().unwrap();
|
|
||||||
let zip = client.execute(zip_request).unwrap().bytes().unwrap();
|
|
||||||
fs::write(download_path.clone(), zip).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let opened_zip = fs::File::open(download_path.clone()).unwrap();
|
|
||||||
println!("Extracting mod zip file...");
|
|
||||||
let mut archive = zip::ZipArchive::new(opened_zip).unwrap();
|
|
||||||
archive.extract(self.data_path.clone()).unwrap();
|
|
||||||
|
|
||||||
fs::remove_file(download_path).unwrap();
|
|
||||||
|
|
||||||
let mut root_folder_path = String::new();
|
|
||||||
for i in archive.file_names() {
|
|
||||||
root_folder_path = String::from(i.split('/').next().unwrap());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let extracted_path: PathBuf = [self.data_path.as_str(), root_folder_path.as_str(), "."]
|
|
||||||
.iter()
|
|
||||||
.collect();
|
|
||||||
println!("{}", extracted_path.to_str().unwrap());
|
|
||||||
copy_folder_contents_to_target(
|
|
||||||
extracted_path.to_str().unwrap(),
|
|
||||||
new_installed_path.to_str().unwrap(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
self.initialized = !self.initialized;
|
|
||||||
self.app_state = GlobalAppState::Initialized;
|
|
||||||
self.update_installs_list = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
||||||
@@ -500,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() {
|
||||||
@@ -511,10 +257,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut app_data: AppData = AppData {
|
let mut app_data: AppData = AppData {
|
||||||
among_us_path: String::from(among_us_folder.clone().to_str().unwrap()),
|
// among_us_path: String::from(among_us_folder.clone().to_str().unwrap()),
|
||||||
|
among_us_path: String::new(),
|
||||||
installs_path: String::from(installs_path.clone().to_str().unwrap()),
|
installs_path: String::from(installs_path.clone().to_str().unwrap()),
|
||||||
version: SemVer::from(version),
|
version: SemVer::from(version),
|
||||||
initialized: false,
|
delete_mode: false,
|
||||||
among_us_version: AmongUsVersion::default(),
|
among_us_version: AmongUsVersion::default(),
|
||||||
data_path: String::from(data_path.clone().to_str().unwrap()),
|
data_path: String::from(data_path.clone().to_str().unwrap()),
|
||||||
app_state: GlobalAppState::Initializing(InitializingState::StartingGUI),
|
app_state: GlobalAppState::Initializing(InitializingState::StartingGUI),
|
||||||
@@ -522,6 +269,17 @@ fn main() {
|
|||||||
update_installs_list: true,
|
update_installs_list: true,
|
||||||
installs_last_update_time: std::time::Instant::now(),
|
installs_last_update_time: std::time::Instant::now(),
|
||||||
installs_list: Vec::new(),
|
installs_list: Vec::new(),
|
||||||
|
init_install_path: None,
|
||||||
|
init_download_url: None,
|
||||||
|
launcher_running: false,
|
||||||
|
config: app_config,
|
||||||
|
among_us_launched: false,
|
||||||
|
among_us_running: false,
|
||||||
|
find_among_us_handle: None,
|
||||||
|
determine_au_version_handle: None,
|
||||||
|
determine_tou_version_handle: None,
|
||||||
|
copy_au_handle: None,
|
||||||
|
download_tou_handle: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// DETERMINE AMONG US VERSION
|
// DETERMINE AMONG US VERSION
|
||||||
@@ -539,14 +297,17 @@ fn main() {
|
|||||||
|
|
||||||
println!("Launching main window...");
|
println!("Launching main window...");
|
||||||
|
|
||||||
|
// Tell better crewlink to launch somewhere else
|
||||||
|
thread::spawn(|| {
|
||||||
launch_better_crewlink().unwrap_or(());
|
launch_better_crewlink().unwrap_or(());
|
||||||
|
});
|
||||||
|
|
||||||
// let app_launcher = AppLauncher::with_window(main_window).delegate(Delegate {});
|
|
||||||
// app_launcher.launch(app_data).unwrap();
|
|
||||||
let mut native_options = eframe::NativeOptions::default();
|
let mut native_options = eframe::NativeOptions::default();
|
||||||
native_options.min_window_size = Some(egui::vec2(425.0, 400.0));
|
native_options.min_window_size = Some(egui::vec2(425.0, 400.0));
|
||||||
native_options.initial_window_size = Some(egui::vec2(425.0, 400.0));
|
native_options.initial_window_size = Some(egui::vec2(425.0, 400.0));
|
||||||
app_data.detect_installs(); // Initial check since we only update every 10s
|
|
||||||
|
app_data.detect_running_stores();
|
||||||
|
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
title_string.as_str(),
|
title_string.as_str(),
|
||||||
native_options,
|
native_options,
|
||||||
@@ -668,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(
|
||||||
@@ -693,8 +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"));
|
|
||||||
|
|
||||||
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();
|
||||||
@@ -711,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