12 Commits
2.1.0 ... 3.0.0

Author SHA1 Message Date
ff311475dc Add blessed build text coloring 2023-01-15 14:31:55 -08:00
8e61c8a2f2 Merge branch 'hotfix-2.0.0' 2022-11-28 19:37:10 -08:00
97cdf4829a push to 2.3 2022-11-28 19:23:30 -08:00
7244c24fe4 Fix sorting 2022-11-28 19:20:05 -08:00
fbc4c747a5 Merge branch 'hotfix-2.0.0' 2022-11-14 18:37:53 -08:00
7f1a6c6bc1 Bump to 2.2.0 2022-11-14 18:20:32 -08:00
856cffd740 No timeouts while downloading 2022-11-14 18:15:24 -08:00
9468194718 Remove windows-only components
Attempt to divide initialization
2022-10-11 21:03:33 -07:00
69f67d303e Merge branch 'master' of http://git.dormedas.com/dormedas/town-of-us-updater 2022-09-26 19:08:26 -07:00
6d05440d98 Merge branch 'hotfix-2.0.0' 2022-09-26 19:07:54 -07:00
972c310673 Update 'README.md' 2022-09-26 14:47:01 -07:00
90b703ee30 Bump to 3.0.0 2022-09-26 08:15:17 -07:00
4 changed files with 206 additions and 125 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "town-of-us-updater" name = "town-of-us-updater"
version = "2.0.0" version = "3.0.0"
edition = "2021" edition = "2021"
build = "src/build.rs" build = "src/build.rs"

View File

@@ -7,6 +7,7 @@ A tool to automatically install the **Town of Us R** mod for **Among Us**.
- Caches old builds to allow you to continue playing the mod in case of a breaking Among Us update - Caches old builds to allow you to continue playing the mod in case of a breaking Among Us update
- GUI to select which build to play - GUI to select which build to play
- Auto-detection of Among Us install directory - Auto-detection of Among Us install directory
- Auto-launch of BetterCrewLink if installed
# Contributing # Contributing

View File

@@ -1,11 +1,15 @@
use crate::AmongUsVersion;
use crate::AppData; use crate::AppData;
use druid::{ use druid::{
widget::*, BoxConstraints, Env, Event, EventCtx, FileDialogOptions, LayoutCtx, LifeCycle, widget::*, BoxConstraints, Color, Env, Event, EventCtx, FileDialogOptions, LayoutCtx,
LifeCycleCtx, PaintCtx, Selector, Size, UpdateCtx, WidgetExt, WidgetPod, LifeCycle, LifeCycleCtx, PaintCtx, Selector, Size, UpdateCtx, WidgetExt, WidgetPod,
}; };
use std::{fs, io, path::PathBuf}; use std::{fs, io, path::PathBuf};
pub const ATTEMPT_INSTALL: Selector = Selector::new("town-of-us-updater.attempt_install"); pub const ATTEMPT_INSTALL: Selector = Selector::new("town-of-us-updater.attempt_install");
pub const DETERMINE_AMONG_US_VERSION: Selector =
Selector::new("town-of-us-updater.determine_among_us_version");
pub const COPY_FOLDER: Selector = Selector::new("town-of-us-updater.copy_folder");
pub struct AmongUsLauncherWidget { pub struct AmongUsLauncherWidget {
pub root: WidgetPod<AppData, Flex<AppData>>, pub root: WidgetPod<AppData, Flex<AppData>>,
@@ -15,6 +19,15 @@ impl AmongUsLauncherWidget {
pub fn build_widget(&mut self, data: &AppData) { pub fn build_widget(&mut self, data: &AppData) {
let mut flex: Flex<AppData> = Flex::column(); let mut flex: Flex<AppData> = Flex::column();
match &data.app_state {
crate::GlobalAppState::Initializing(_a) => {
let label = Label::new("Initializing...").with_text_size(24.0).center();
flex.add_flex_child(label, 1.0);
self.root = WidgetPod::new(flex);
return;
}
_ => {}
}
// Find existing installs, make buttons for them // Find existing installs, make buttons for them
let install_iter = fs::read_dir(data.installs_path.clone()); let install_iter = fs::read_dir(data.installs_path.clone());
@@ -44,42 +57,58 @@ impl AmongUsLauncherWidget {
// Iterate first to find labels: // Iterate first to find labels:
let mut flexbox_array: Vec<druid::widget::Flex<AppData>> = Vec::new(); let mut flexbox_array: Vec<druid::widget::Flex<AppData>> = Vec::new();
let mut auv_array: Vec<String> = Vec::new(); let mut auv_array: Vec<AmongUsVersion> = Vec::new();
for i in &collection { for i in &collection {
let existing_ver_smash = i.as_ref().unwrap().file_name(); let existing_ver_smash = i.as_ref().unwrap().file_name();
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-'); let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
let auv = ver_smash_split.next().unwrap(); let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
if !auv_array.contains(&auv.to_string()) { if !auv_array.contains(&among_us_version) {
let label_text = format!("Among Us {}", auv); auv_array.push(among_us_version);
let flex: druid::widget::Flex<AppData> = druid::widget::Flex::column()
.with_flex_child(
druid::widget::Label::new(label_text.as_str()).with_text_size(24.0),
1.0,
)
.with_default_spacer();
flexbox_array.push(flex);
auv_array.push(auv.to_string());
} }
} }
auv_array.sort();
for among_us_version in &auv_array {
println!("{}", among_us_version);
let label_text = format!("Among Us {}", among_us_version);
let flex: druid::widget::Flex<AppData> = druid::widget::Flex::column()
.with_flex_child(
druid::widget::Label::new(label_text.as_str()).with_text_size(24.0),
1.0,
)
.with_default_spacer();
flexbox_array.push(flex);
}
println!("Installs list:"); println!("Installs list:");
for i in collection { for i in collection {
let existing_ver_smash = i.unwrap().file_name(); let existing_ver_smash = i.unwrap().file_name();
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-'); let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
let auv = ver_smash_split.next().unwrap(); let mut blessed_split = data.blessed_version.as_str().split('-');
let button_string: String = let blessed_version = AmongUsVersion::from(blessed_split.next().unwrap());
format!("Town of Us {}", ver_smash_split.next().unwrap()); let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
let tou_version = ver_smash_split.next().unwrap();
let blessed_tou_version = blessed_split.next().unwrap();
let button_string: String = format!("Town of Us {}", tou_version);
for (index, j) in auv_array.iter().enumerate() { for (index, j) in auv_array.iter().enumerate() {
if j == auv { if j == &among_us_version {
let mut clone: PathBuf = PathBuf::from(data.installs_path.clone()); let mut clone: PathBuf = PathBuf::from(data.installs_path.clone());
clone.push(existing_ver_smash.clone()); clone.push(existing_ver_smash.clone());
let mut button_label: Label<AppData> =
Label::new(button_string.as_str()).with_text_size(24.0);
if j == &blessed_version && tou_version == blessed_tou_version {
button_label.set_text_color(Color::GREEN);
}
let mut button_row: Flex<AppData> = Flex::row(); let mut button_row: Flex<AppData> = Flex::row();
let fybutton = druid::widget::Button::new(button_string.as_str()) let fybutton = druid::widget::Button::from_label(button_label)
.fix_height(45.0) .fix_height(45.0)
.center() .center()
.on_click(move |_, _: &mut AppData, _| { .on_click(move |_, _: &mut AppData, _| {
@@ -106,6 +135,8 @@ impl AmongUsLauncherWidget {
} }
} }
flexbox_array.reverse();
for i in flexbox_array { for i in flexbox_array {
flex.add_flex_child(i, 1.0); flex.add_flex_child(i, 1.0);
} }
@@ -144,9 +175,12 @@ impl Widget<AppData> for AmongUsLauncherWidget {
} }
fn update(&mut self, ctx: &mut UpdateCtx, old_data: &AppData, data: &AppData, env: &Env) { fn update(&mut self, ctx: &mut UpdateCtx, old_data: &AppData, data: &AppData, env: &Env) {
self.root.update(ctx, data, env); self.root.update(ctx, data, env);
println!("{:?}", data);
if old_data.among_us_path.is_empty() && !data.among_us_path.is_empty() { if old_data.among_us_path.is_empty() && !data.among_us_path.is_empty() {
ctx.submit_command(ATTEMPT_INSTALL); ctx.submit_command(DETERMINE_AMONG_US_VERSION);
// println!("Detect Stuff"); // println!("Detect Stuff");
} else if old_data.among_us_version != data.among_us_version {
ctx.submit_command(ATTEMPT_INSTALL);
} }
// println!("Update!"); // println!("Update!");
self.build_widget(data); self.build_widget(data);

View File

@@ -19,6 +19,7 @@ use fs_extra::{copy_items, dir};
use regex::Regex; use regex::Regex;
#[cfg(target_os = "windows")]
use registry::Hive; use registry::Hive;
// GUI stuff // GUI stuff
@@ -27,6 +28,27 @@ use druid::{
WidgetPod, WindowDesc, WindowId, WidgetPod, WindowDesc, WindowId,
}; };
use reqwest::StatusCode;
#[derive(PartialEq, Eq, Data, Clone, Debug)]
pub enum InitializingState {
StartingGUI,
DeterminingVersion,
CopyingAmongUs,
UnmoddingAmongUs,
DownloadingZip,
Unzipping,
CopyingZipIn,
}
#[derive(PartialEq, Eq, Data, Clone, Debug)]
pub enum GlobalAppState {
Initializing(InitializingState),
Initialized,
Installing,
Playing,
}
struct Delegate; struct Delegate;
#[derive(Data, Clone, Debug)] #[derive(Data, Clone, Debug)]
@@ -37,6 +59,8 @@ pub struct AppData {
pub initialized: bool, pub initialized: bool,
pub among_us_version: AmongUsVersion, pub among_us_version: AmongUsVersion,
pub data_path: String, pub data_path: String,
pub app_state: GlobalAppState,
pub blessed_version: String,
} }
static AMONG_US_APPID: &str = "945360"; static AMONG_US_APPID: &str = "945360";
@@ -126,7 +150,7 @@ impl AppDelegate<AppData> for Delegate {
ctx: &mut DelegateCtx, ctx: &mut DelegateCtx,
) { ) {
if !data.among_us_path.is_empty() { if !data.among_us_path.is_empty() {
ctx.submit_command(ATTEMPT_INSTALL); ctx.submit_command(DETERMINE_AMONG_US_VERSION);
} }
} }
fn command( fn command(
@@ -151,87 +175,91 @@ impl AppDelegate<AppData> for Delegate {
//Application::global().quit(); //Application::global().quit();
return Handled::Yes; return Handled::Yes;
} else if let Some(_a) = cmd.get(among_us_launcher_widget::ATTEMPT_INSTALL) { } else if let Some(_a) = cmd.get(among_us_launcher_widget::DETERMINE_AMONG_US_VERSION) {
if let Some(among_us_version) = if let Some(among_us_version) =
determine_among_us_version(String::from(data.among_us_path.clone())) determine_among_us_version(String::from(data.among_us_path.clone()))
{ {
data.among_us_version = among_us_version.clone(); data.among_us_version = among_us_version.clone();
println!("AmongUsVersion: {}", among_us_version); println!("AmongUsVersion: {}", among_us_version);
let ver_url: (String, String, bool) = }
determine_town_of_us_url(among_us_version.to_string().clone()).unwrap(); } else if let Some(_a) = cmd.get(among_us_launcher_widget::ATTEMPT_INSTALL) {
data.app_state = GlobalAppState::Initializing(InitializingState::DeterminingVersion);
let ver_url: (String, String, bool) =
determine_town_of_us_url(data.among_us_version.to_string().clone()).unwrap();
let version_smash = format!("{}-{}", among_us_version, ver_url.0.clone()); let version_smash = format!("{}-{}", data.among_us_version, ver_url.0.clone());
let new_installed_path: PathBuf = let new_installed_path: PathBuf = [data.installs_path.as_str(), version_smash.as_str()]
[data.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(data.among_us_path.clone(), data.installs_path.clone());
let among_us_path: PathBuf =
[data.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 = [data.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(data.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.data_path.as_str(), root_folder_path.as_str(), "."]
.iter() .iter()
.collect(); .collect();
println!("{}", extracted_path.to_str().unwrap());
if !Path::exists(&new_installed_path) { copy_folder_contents_to_target(
println!("Copying Among Us to cache location..."); extracted_path.to_str().unwrap(),
copy_folder_to_target(data.among_us_path.clone(), data.installs_path.clone()); new_installed_path.to_str().unwrap(),
);
let among_us_path: PathBuf =
[data.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 = [data.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 zip = reqwest::blocking::get(ver_url.1.clone())
.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(data.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.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(),
);
}
} }
data.initialized = !data.initialized; data.initialized = !data.initialized;
data.app_state = GlobalAppState::Initialized;
return Handled::Yes; return Handled::Yes;
} }
@@ -243,6 +271,15 @@ impl AppDelegate<AppData> for Delegate {
fn main() { fn main() {
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 response = blessed_body.unwrap();
let blessed_version: String = match response.status() {
StatusCode::OK => response.text().unwrap(),
_ => String::from("0.0.0-v0.0.0"),
};
println!("Blessed Version: {}", blessed_version);
// println!("Updater Version: {}", version); // println!("Updater Version: {}", version);
// get_latest_updater_version().await.unwrap(); // get_latest_updater_version().await.unwrap();
@@ -284,6 +321,8 @@ fn main() {
initialized: false, initialized: 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),
blessed_version,
}; };
let mut root_column: druid::widget::Flex<AppData> = druid::widget::Flex::column(); let mut root_column: druid::widget::Flex<AppData> = druid::widget::Flex::column();
@@ -386,7 +425,7 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String,
} }
fn determine_among_us_version(folder_root: String) -> Option<AmongUsVersion> { fn determine_among_us_version(folder_root: String) -> Option<AmongUsVersion> {
let asset_file = format!("{}\\Among Us_Data\\globalgamemanagers", folder_root); let asset_file = format!("{}/Among Us_Data/globalgamemanagers", folder_root);
const TARGET_BYTES_LEN: usize = 16; const TARGET_BYTES_LEN: usize = 16;
@@ -452,40 +491,47 @@ fn _detect_epic() -> Option<String> {
} }
fn detect_among_us_folder() -> Option<String> { fn detect_among_us_folder() -> Option<String> {
if let Ok(steam_regkey) = Hive::LocalMachine.open( if cfg!(windows) {
r"SOFTWARE\WOW6432Node\Valve\Steam", let mut library_folder_path: PathBuf =
registry::Security::Read, PathBuf::from("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");
) { if let Ok(steam_regkey) = Hive::LocalMachine.open(
if let Ok(steam_folder) = steam_regkey.value("InstallPath") { r"SOFTWARE\WOW6432Node\Valve\Steam",
println!("{:?}", steam_folder); registry::Security::Read,
} ) {
} if let Ok(steam_folder) = steam_regkey.value("InstallPath") {
library_folder_path = PathBuf::from(steam_folder.to_string());
let library_folder = library_folder_path.push("steamapps\\libraryfolders.vdf");
fs::read_to_string("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf"); println!("{:?}", steam_folder);
println!("{:?}", library_folder_path.to_str());
if library_folder.is_ok() { }
println!("Steam is on C:\\ drive!");
let mut library_folder_string: String = library_folder.unwrap();
let appid_index = library_folder_string.find(AMONG_US_APPID);
if appid_index.is_none() {
println!("Among Us not found!");
return None;
} else {
library_folder_string.truncate(appid_index.unwrap());
} }
let path_regex = Regex::new(r#"path"\s+"([Z-a\w\d\s\\\(\):]+)""#).unwrap(); let library_folder =
let caps: regex::CaptureMatches = path_regex.captures_iter(&library_folder_string); fs::read_to_string(library_folder_path.to_str().expect("Path invalid"));
let last_path = caps.last().unwrap();
let start = last_path.get(last_path.len() - 1).unwrap();
return Some(format!( if library_folder.is_ok() {
"{}\\\\steamapps\\\\common\\\\Among Us\\\\", let mut library_folder_string: String = library_folder.unwrap();
library_folder_string let appid_index = library_folder_string.find(AMONG_US_APPID);
.get(start.start()..start.end()) if appid_index.is_none() {
.unwrap() println!("Among Us not found!");
)); return None;
} else {
library_folder_string.truncate(appid_index.unwrap());
}
let path_regex = Regex::new(r#"path"\s+"([Z-a\w\d\s\\\(\):]+)""#).unwrap();
let caps: regex::CaptureMatches = path_regex.captures_iter(&library_folder_string);
let last_path = caps.last().unwrap();
let start = last_path.get(last_path.len() - 1).unwrap();
return Some(format!(
r"{}\\steamapps\\common\\Among Us\\",
library_folder_string
.get(start.start()..start.end())
.unwrap()
));
}
} else {
} }
None None
} }