Compare commits
5 Commits
2.1.0
...
9468194718
| Author | SHA1 | Date | |
|---|---|---|---|
| 9468194718 | |||
| 69f67d303e | |||
| 6d05440d98 | |||
| 972c310673 | |||
| 90b703ee30 |
@@ -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"
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ use druid::{
|
|||||||
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 +18,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());
|
||||||
|
|
||||||
@@ -144,9 +156,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);
|
||||||
|
|||||||
55
src/main.rs
55
src/main.rs
@@ -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,25 @@ use druid::{
|
|||||||
WidgetPod, WindowDesc, WindowId,
|
WidgetPod, WindowDesc, WindowId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[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 +57,7 @@ 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
static AMONG_US_APPID: &str = "945360";
|
static AMONG_US_APPID: &str = "945360";
|
||||||
@@ -126,7 +147,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,18 +172,20 @@ 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);
|
||||||
|
}
|
||||||
|
} 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) =
|
let ver_url: (String, String, bool) =
|
||||||
determine_town_of_us_url(among_us_version.to_string().clone()).unwrap();
|
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()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -171,7 +194,7 @@ impl AppDelegate<AppData> for Delegate {
|
|||||||
copy_folder_to_target(data.among_us_path.clone(), data.installs_path.clone());
|
copy_folder_to_target(data.among_us_path.clone(), data.installs_path.clone());
|
||||||
|
|
||||||
let among_us_path: PathBuf =
|
let among_us_path: PathBuf =
|
||||||
[data.installs_path.as_str(), "Among Us\\"].iter().collect();
|
[data.installs_path.as_str(), "Among Us"].iter().collect();
|
||||||
|
|
||||||
if !among_us_path.to_str().unwrap().contains("Among Us") {
|
if !among_us_path.to_str().unwrap().contains("Among Us") {
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
@@ -230,8 +253,8 @@ impl AppDelegate<AppData> for Delegate {
|
|||||||
new_installed_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;
|
||||||
}
|
}
|
||||||
@@ -284,6 +307,7 @@ 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),
|
||||||
};
|
};
|
||||||
|
|
||||||
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 +410,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,20 +476,25 @@ fn _detect_epic() -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn detect_among_us_folder() -> Option<String> {
|
fn detect_among_us_folder() -> Option<String> {
|
||||||
|
if cfg!(windows) {
|
||||||
|
let mut library_folder_path: PathBuf =
|
||||||
|
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(
|
||||||
r"SOFTWARE\WOW6432Node\Valve\Steam",
|
r"SOFTWARE\WOW6432Node\Valve\Steam",
|
||||||
registry::Security::Read,
|
registry::Security::Read,
|
||||||
) {
|
) {
|
||||||
if let Ok(steam_folder) = steam_regkey.value("InstallPath") {
|
if let Ok(steam_folder) = steam_regkey.value("InstallPath") {
|
||||||
|
library_folder_path = PathBuf::from(steam_folder.to_string());
|
||||||
|
library_folder_path.push("steamapps\\libraryfolders.vdf");
|
||||||
println!("{:?}", steam_folder);
|
println!("{:?}", steam_folder);
|
||||||
|
println!("{:?}", library_folder_path.to_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let library_folder =
|
let library_folder =
|
||||||
fs::read_to_string("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");
|
fs::read_to_string(library_folder_path.to_str().expect("Path invalid"));
|
||||||
|
|
||||||
if library_folder.is_ok() {
|
if library_folder.is_ok() {
|
||||||
println!("Steam is on C:\\ drive!");
|
|
||||||
let mut library_folder_string: String = library_folder.unwrap();
|
let mut library_folder_string: String = library_folder.unwrap();
|
||||||
let appid_index = library_folder_string.find(AMONG_US_APPID);
|
let appid_index = library_folder_string.find(AMONG_US_APPID);
|
||||||
if appid_index.is_none() {
|
if appid_index.is_none() {
|
||||||
@@ -481,11 +510,13 @@ fn detect_among_us_folder() -> Option<String> {
|
|||||||
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!(
|
||||||
"{}\\\\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()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user