Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63b58bbe05 | |||
| 399b975aaf | |||
| ed50979397 | |||
| 762b2f61aa | |||
| 3bd05ba8dd | |||
| ff311475dc | |||
| 8e61c8a2f2 | |||
| 97cdf4829a | |||
| 7244c24fe4 | |||
| fbc4c747a5 | |||
| 7f1a6c6bc1 | |||
| 856cffd740 | |||
| 9468194718 | |||
| 69f67d303e | |||
| 6d05440d98 | |||
| 686d24f7b5 | |||
| 972c310673 | |||
| 90b703ee30 | |||
| 38c975b44c | |||
| 762d96baee | |||
| 81e8eaad0f | |||
| 84d206a87b | |||
| e59c25af25 | |||
| cf75410860 | |||
| 35828e4b5b | |||
| bac49bc766 | |||
| 9564c70a33 | |||
| c9e9cbc66d | |||
| 88f8ca7031 | |||
| 721e08cfc6 | |||
| d6e3a7133b | |||
| 9e90a18c6a | |||
| 9132afe917 | |||
| ebad7cb893 | |||
| b4c22cdc48 | |||
| 54b2b8b117 | |||
| 91579d333e | |||
| 0b940aea70 | |||
| 86d1e176d4 | |||
| b6221643e2 | |||
| 3150019b76 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
|||||||
16
Cargo.toml
16
Cargo.toml
@@ -1,7 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "town-of-us-updater"
|
name = "town-of-us-updater"
|
||||||
version = "0.1.0"
|
version = "4.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
build = "src/build.rs"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@@ -11,4 +12,15 @@ 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"]}
|
||||||
iui = "0.3.0"
|
serde = {version= "1.0.143", features = ["derive"]}
|
||||||
|
serde_json = "1.0"
|
||||||
|
md-5 = "0.10.5"
|
||||||
|
tokio = {version="1", features=["full"]}
|
||||||
|
registry = "1"
|
||||||
|
egui = "0.20.1"
|
||||||
|
eframe = "0.20.1"
|
||||||
|
rfd = "0.10"
|
||||||
|
tasklist = "0.2.12"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource = "1.6"
|
||||||
|
|||||||
21
README.md
21
README.md
@@ -1,2 +1,21 @@
|
|||||||
# town-of-us-updater
|
# Town of Us Updater
|
||||||
|
|
||||||
|
A tool to automatically install the **Town of Us R** mod for **Among Us**.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- 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
|
||||||
|
- Auto-detection of Among Us install directory
|
||||||
|
- Auto-launch of BetterCrewLink if installed
|
||||||
|
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
Help. I have no standards. Just look at the code.
|
||||||
|
|
||||||
|
## How to Build
|
||||||
|
|
||||||
|
- [Install Rust](https://www.rust-lang.org/learn/get-started)
|
||||||
|
- Download repository
|
||||||
|
- Navigate to repository
|
||||||
|
- `cargo build`
|
||||||
BIN
assets/icon.ico
Normal file
BIN
assets/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 142 KiB |
BIN
assets/logo.png
Normal file
BIN
assets/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
1
assets/main.rc
Normal file
1
assets/main.rc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1 ICON "icon.ico"
|
||||||
91
src/among_us_version.rs
Normal file
91
src/among_us_version.rs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Ord, PartialOrd, Eq, PartialEq, Clone, Debug)]
|
||||||
|
pub struct AmongUsVersion {
|
||||||
|
year: i32,
|
||||||
|
month: i32,
|
||||||
|
day: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AmongUsVersion {
|
||||||
|
pub fn as_american_string(&self) -> String {
|
||||||
|
format!("{}-{}-{}", self.month, self.day, self.year)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for AmongUsVersion {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}.{}.{}", self.year, self.month, self.day)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AmongUsVersion {
|
||||||
|
fn default() -> Self {
|
||||||
|
AmongUsVersion {
|
||||||
|
year: 0,
|
||||||
|
month: 0,
|
||||||
|
day: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for AmongUsVersion {
|
||||||
|
fn from(s: &str) -> AmongUsVersion {
|
||||||
|
// Ignore a prepending "v"
|
||||||
|
let tmp_str = s.replace("v", "");
|
||||||
|
|
||||||
|
let v: Vec<&str> = tmp_str.split('.').collect();
|
||||||
|
|
||||||
|
AmongUsVersion {
|
||||||
|
year: v[0].parse().unwrap(),
|
||||||
|
month: v[1].parse().unwrap(),
|
||||||
|
day: v[2].parse().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(i32, i32, i32)> for AmongUsVersion {
|
||||||
|
fn from(s: (i32, i32, i32)) -> AmongUsVersion {
|
||||||
|
AmongUsVersion {
|
||||||
|
year: s.0,
|
||||||
|
month: s.1,
|
||||||
|
day: s.2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ordering_test() {
|
||||||
|
let mut vec = Vec::new();
|
||||||
|
vec.push(AmongUsVersion {
|
||||||
|
year: 2019,
|
||||||
|
month: 1,
|
||||||
|
day: 25,
|
||||||
|
});
|
||||||
|
|
||||||
|
vec.push(AmongUsVersion {
|
||||||
|
year: 2022,
|
||||||
|
month: 12,
|
||||||
|
day: 25,
|
||||||
|
});
|
||||||
|
|
||||||
|
vec.push(AmongUsVersion {
|
||||||
|
year: 2022,
|
||||||
|
month: 12,
|
||||||
|
day: 14,
|
||||||
|
});
|
||||||
|
|
||||||
|
vec.push(AmongUsVersion {
|
||||||
|
year: 2022,
|
||||||
|
month: 12,
|
||||||
|
day: 8,
|
||||||
|
});
|
||||||
|
vec.sort();
|
||||||
|
assert_eq!(vec[0].year, 2019);
|
||||||
|
assert_eq!(vec[1].year, 2022);
|
||||||
|
assert_eq!(vec[1].day, 8);
|
||||||
|
assert_eq!(vec[2].year, 2022);
|
||||||
|
assert_eq!(vec[2].day, 14);
|
||||||
|
assert_eq!(vec[3].year, 2022);
|
||||||
|
assert_eq!(vec[3].day, 25);
|
||||||
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/build.rs
Normal file
5
src/build.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
extern crate embed_resource;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
embed_resource::compile("assets/main.rc");
|
||||||
|
}
|
||||||
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();
|
||||||
|
}
|
||||||
617
src/main.rs
617
src/main.rs
@@ -1,48 +1,57 @@
|
|||||||
use std::path::{Path, PathBuf};
|
// Module definitions
|
||||||
use std::str;
|
mod among_us_version;
|
||||||
use std::*;
|
mod app_data;
|
||||||
|
mod config;
|
||||||
|
mod semver;
|
||||||
|
|
||||||
|
// Crate imports
|
||||||
|
use among_us_version::*;
|
||||||
|
use app_data::*;
|
||||||
|
use config::LauncherType;
|
||||||
|
|
||||||
|
// Other imports
|
||||||
|
use md5::{Digest, Md5};
|
||||||
|
use semver::*;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
fs, io,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process, str, thread,
|
||||||
|
};
|
||||||
|
|
||||||
use fs_extra::{copy_items, dir};
|
use fs_extra::{copy_items, dir};
|
||||||
use iui::controls::{Button, Group, Label, VerticalBox};
|
|
||||||
use iui::prelude::*;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
static AMONG_US_APPID: &'static str = "945360";
|
#[cfg(target_os = "windows")]
|
||||||
|
use registry::Hive;
|
||||||
|
|
||||||
struct AmongUsVersion {
|
// GUI stuff
|
||||||
year: i32,
|
|
||||||
month: i32,
|
|
||||||
day: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for AmongUsVersion {
|
use eframe::egui;
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "{}.{}.{}", self.year, self.month, self.day)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&str> for AmongUsVersion {
|
use reqwest::StatusCode;
|
||||||
fn from(s: &str) -> AmongUsVersion {
|
|
||||||
let v: Vec<&str> = s.split(".").collect();
|
struct CombinedVersion(AmongUsVersion, SemVer);
|
||||||
AmongUsVersion {
|
|
||||||
year: i32::from_str_radix(v[0], 10).unwrap(),
|
static AMONG_US_APPID: &str = "945360";
|
||||||
month: i32::from_str_radix(v[1], 10).unwrap(),
|
|
||||||
day: i32::from_str_radix(v[2], 10).unwrap(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn attempt_run_among_us(install_path: &Path) {
|
fn attempt_run_among_us(install_path: &Path) {
|
||||||
let executable_path: path::PathBuf = [install_path.to_str().unwrap(), "Among Us.exe"]
|
let executable_path: PathBuf = [install_path.to_str().unwrap(), "Among Us.exe"]
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
std::process::Command::new(executable_path.to_str().unwrap())
|
process::Command::new(executable_path.to_str().unwrap())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn attempt_delete_among_us(install_path: &Path) {
|
||||||
|
fs::remove_dir_all(install_path).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn unmod_among_us_folder(folder_path: &Path) {
|
fn unmod_among_us_folder(folder_path: &Path) {
|
||||||
|
println!("Unmodding Among Us...");
|
||||||
let doorstop_path: PathBuf = [folder_path.to_str().unwrap(), "doorstop_config.ini"]
|
let doorstop_path: PathBuf = [folder_path.to_str().unwrap(), "doorstop_config.ini"]
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
@@ -52,6 +61,7 @@ fn unmod_among_us_folder(folder_path: &Path) {
|
|||||||
let winhttp_path: PathBuf = [folder_path.to_str().unwrap(), "winhttp.dll"]
|
let winhttp_path: PathBuf = [folder_path.to_str().unwrap(), "winhttp.dll"]
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let bepinex_path: PathBuf = [folder_path.to_str().unwrap(), "BepInEx"].iter().collect();
|
let bepinex_path: PathBuf = [folder_path.to_str().unwrap(), "BepInEx"].iter().collect();
|
||||||
let mono_path: PathBuf = [folder_path.to_str().unwrap(), "mono"].iter().collect();
|
let mono_path: PathBuf = [folder_path.to_str().unwrap(), "mono"].iter().collect();
|
||||||
fs::remove_file(doorstop_path).unwrap_or_default();
|
fs::remove_file(doorstop_path).unwrap_or_default();
|
||||||
@@ -61,7 +71,65 @@ fn unmod_among_us_folder(folder_path: &Path) {
|
|||||||
fs::remove_dir_all(mono_path).unwrap_or_default();
|
fs::remove_dir_all(mono_path).unwrap_or_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn _get_latest_updater_version() -> Result<(String, String), reqwest::Error> {
|
||||||
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
let local_sem_ver = SemVer::from(version);
|
||||||
|
|
||||||
|
let body =
|
||||||
|
reqwest::get("https://git.dormedas.com/api/v1/repos/dormedas/town-of-us-updater/releases");
|
||||||
|
let root: serde_json::Value = serde_json::from_str(&body.await?.text().await?).unwrap();
|
||||||
|
|
||||||
|
for i in root.as_array().unwrap() {
|
||||||
|
let tag_name = i["tag_name"].as_str().unwrap();
|
||||||
|
if let Some(trimmed_str) = tag_name.strip_prefix('v') {
|
||||||
|
let remote_sem_ver = SemVer::from(trimmed_str);
|
||||||
|
if remote_sem_ver > local_sem_ver {
|
||||||
|
for j in i["assets"].as_array().unwrap() {
|
||||||
|
if j["name"].as_str().unwrap().contains(".exe") {
|
||||||
|
// let url = j["browser_download_url"].as_str().unwrap();
|
||||||
|
// let data = reqwest::get(url).await?.bytes().await?;
|
||||||
|
// let mut exe_dir = std::env::current_dir().unwrap();
|
||||||
|
// exe_dir.push("town-of-us-updater-new.exe");
|
||||||
|
// fs::write(exe_dir, data).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("New version ({}) of the updater detected!", remote_sem_ver);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let remote_sem_ver = SemVer::from(tag_name);
|
||||||
|
if remote_sem_ver > local_sem_ver {
|
||||||
|
for j in i["assets"].as_array().unwrap() {
|
||||||
|
if j["name"].as_str().unwrap().contains(".exe") {
|
||||||
|
// let url = j["browser_download_url"].as_str().unwrap();
|
||||||
|
// let data = reqwest::get(url).await?.bytes().await?;
|
||||||
|
// let mut exe_dir = std::env::current_dir().unwrap();
|
||||||
|
// exe_dir.push("town-of-us-updater-new.exe");
|
||||||
|
// fs::write(exe_dir, data).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("New version ({}) of the updater detected!", remote_sem_ver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((String::from("no"), String::from("yes")))
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let app_config = config::load_config().unwrap_or_default();
|
||||||
|
let version = env!("CARGO_PKG_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);
|
||||||
|
|
||||||
// CREATE PROGRAM DIRECTORY
|
// CREATE PROGRAM DIRECTORY
|
||||||
let mut data_path = dirs::data_dir().unwrap();
|
let mut data_path = dirs::data_dir().unwrap();
|
||||||
data_path.push("town-of-us-updater");
|
data_path.push("town-of-us-updater");
|
||||||
@@ -71,163 +139,198 @@ fn main() {
|
|||||||
installs_path.push("installs");
|
installs_path.push("installs");
|
||||||
fs::create_dir(installs_path.clone()).unwrap_or(());
|
fs::create_dir(installs_path.clone()).unwrap_or(());
|
||||||
|
|
||||||
let ui = UI::init().expect("UI failed to init");
|
let mut true_env = false;
|
||||||
|
for argument in std::env::args() {
|
||||||
|
if argument == "true" {
|
||||||
|
true_env = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut win = Window::new(&ui, "Town of Us Updater", 600, 400, WindowType::NoMenubar);
|
if !true_env {
|
||||||
|
let mut exe_path = data_path.clone();
|
||||||
|
if cfg!(windows) {
|
||||||
|
exe_path.push("town-of-us-updater.exe");
|
||||||
|
} else if cfg!(unix) {
|
||||||
|
exe_path.push("town-of-us-updater");
|
||||||
|
}
|
||||||
|
|
||||||
let mut vbox = VerticalBox::new(&ui);
|
let mut updated_exe_hash = String::new();
|
||||||
|
|
||||||
vbox.set_padded(&ui, true);
|
if let Ok(response) = reqwest::blocking::get("https://tou.dormedas.com/release/hash") {
|
||||||
|
if let Ok(text) = response.text() {
|
||||||
|
updated_exe_hash = text;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Failed to get hash. Running local version.")
|
||||||
|
}
|
||||||
|
|
||||||
let mut button = Button::new(&ui, "Button");
|
// If we heard back, try to update, otherwise run normally
|
||||||
button.on_clicked(&ui, {
|
if !updated_exe_hash.is_empty() {
|
||||||
let ui = ui.clone();
|
let mut our_hash = String::new();
|
||||||
move |btn| {
|
let mut try_continue = false;
|
||||||
let folder_opt = detect_among_us_folder();
|
match fs::read(&exe_path) {
|
||||||
if folder_opt.is_some() {
|
Ok(bytes) => {
|
||||||
btn.set_text(&ui, "Amogus");
|
let mut hasher = Md5::new();
|
||||||
ui.quit();
|
hasher.update(bytes);
|
||||||
|
let finalized = hasher.finalize();
|
||||||
|
our_hash = format!("{finalized:x}");
|
||||||
|
try_continue = true;
|
||||||
|
}
|
||||||
|
Err(e) => match e.kind() {
|
||||||
|
io::ErrorKind::NotFound => try_continue = true,
|
||||||
|
_ => {
|
||||||
|
println!("{}", e.to_string());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !our_hash.is_empty() {
|
||||||
|
println!("{} vs {}", our_hash, updated_exe_hash);
|
||||||
|
} else {
|
||||||
|
println!("Local executable didn't exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
if try_continue {
|
||||||
|
if our_hash != updated_exe_hash {
|
||||||
|
println!("Newer version detected, downloading...");
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
.timeout(None)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
let updated_exe_data_req = client
|
||||||
|
.get("https://tou.dormedas.com/release")
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let updated_exe_data = client.execute(updated_exe_data_req);
|
||||||
|
|
||||||
|
if let Ok(response) = updated_exe_data {
|
||||||
|
if response.status() == StatusCode::OK {
|
||||||
|
if let Ok(file_bytes) = response.bytes() {
|
||||||
|
match fs::write(&exe_path, file_bytes) {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Successfully updated executable");
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Failed to update executable");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can fail to download a good binary, just continue with our current executable
|
||||||
|
if exe_path.exists() {
|
||||||
|
process::Command::new(&exe_path)
|
||||||
|
.arg("true")
|
||||||
|
.stdout(process::Stdio::null())
|
||||||
|
.stderr(process::Stdio::null())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
let mut among_us_folder = PathBuf::new();
|
||||||
|
|
||||||
|
let mut existing_file_path = data_path.clone();
|
||||||
|
existing_file_path.push("existing_among_us_dir.txt");
|
||||||
|
let existing_found_folder = fs::read_to_string(existing_file_path.clone());
|
||||||
|
|
||||||
|
if let Ok(existing_folder) = existing_found_folder {
|
||||||
|
among_us_folder.push(existing_folder);
|
||||||
|
} else {
|
||||||
|
let folder_opt: Option<(String, LauncherType)> = detect_among_us_folder();
|
||||||
|
if folder_opt.is_some() {
|
||||||
|
among_us_folder.push(folder_opt.unwrap().0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if among_us_folder.exists() {
|
||||||
|
fs::write(existing_file_path, among_us_folder.to_str().unwrap()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut app_data: AppData = AppData {
|
||||||
|
// 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()),
|
||||||
|
version: SemVer::from(version),
|
||||||
|
delete_mode: false,
|
||||||
|
among_us_version: AmongUsVersion::default(),
|
||||||
|
data_path: String::from(data_path.clone().to_str().unwrap()),
|
||||||
|
app_state: GlobalAppState::Initializing(InitializingState::StartingGUI),
|
||||||
|
blessed_version,
|
||||||
|
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: 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
|
||||||
|
|
||||||
|
if let Some(among_us_folder_str) = among_us_folder.to_str() {
|
||||||
|
if among_us_folder_str.len() > 0 {
|
||||||
|
println!("Among Us Folder: {}", among_us_folder_str);
|
||||||
|
} else {
|
||||||
|
println!("Among Us Folder not automatically determined");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Auto launch latest sanctioned if the user has a setting like that
|
||||||
|
// Auto launch latest experimental as well
|
||||||
|
|
||||||
|
println!("Launching main window...");
|
||||||
|
|
||||||
|
// Tell better crewlink to launch somewhere else
|
||||||
|
thread::spawn(|| {
|
||||||
|
launch_better_crewlink().unwrap_or(());
|
||||||
});
|
});
|
||||||
|
|
||||||
let folder_opt = detect_among_us_folder();
|
let mut native_options = eframe::NativeOptions::default();
|
||||||
let mut among_us_folder = path::PathBuf::new();
|
native_options.min_window_size = Some(egui::vec2(425.0, 400.0));
|
||||||
if folder_opt.is_some() {
|
native_options.initial_window_size = Some(egui::vec2(425.0, 400.0));
|
||||||
among_us_folder.push(folder_opt.unwrap());
|
|
||||||
|
app_data.detect_running_stores();
|
||||||
|
|
||||||
|
eframe::run_native(
|
||||||
|
title_string.as_str(),
|
||||||
|
native_options,
|
||||||
|
Box::new(|_cc| Box::new(app_data)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn launch_better_crewlink() -> std::result::Result<(), String> {
|
||||||
|
let mut dir = dirs::data_local_dir().unwrap();
|
||||||
|
dir.push("Programs");
|
||||||
|
dir.push("bettercrewlink");
|
||||||
|
dir.push("Better-CrewLink.exe");
|
||||||
|
println!("Attempting to launch Better Crew Link");
|
||||||
|
if dir.exists() {
|
||||||
|
process::Command::new(dir.as_path().to_str().unwrap())
|
||||||
|
.stdout(process::Stdio::null())
|
||||||
|
.stderr(process::Stdio::null())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
win.modal_msg(&ui, "Find Among Us", "On the following Open File dialog, navigate to your Among Us folder and select Among Us.exe");
|
Err("Better Crew Link not found".to_string())
|
||||||
let open_window = win.open_file(&ui);
|
|
||||||
// println!("{}", open_window.unwrap().to_str().unwrap());
|
|
||||||
among_us_folder = open_window.unwrap().clone();
|
|
||||||
among_us_folder.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Among Us Folder: {}", among_us_folder.to_str().unwrap());
|
|
||||||
|
|
||||||
let among_us_version =
|
|
||||||
determine_among_us_version(String::from(among_us_folder.to_str().unwrap())).unwrap();
|
|
||||||
let ver_url: (String, String, bool) =
|
|
||||||
determine_town_of_us_url(among_us_version.clone()).unwrap();
|
|
||||||
|
|
||||||
let version_smash = format!("{}-{}", among_us_version.clone(), ver_url.0.clone());
|
|
||||||
let new_installed_path: path::PathBuf =
|
|
||||||
[installs_path.to_str().unwrap(), version_smash.as_str()]
|
|
||||||
.iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if !path::Path::exists(&new_installed_path) {
|
|
||||||
copy_folder_to_target(
|
|
||||||
among_us_folder.to_str().unwrap(),
|
|
||||||
installs_path.to_str().unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let among_us_path: path::PathBuf = [installs_path.to_str().unwrap(), "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!(
|
|
||||||
"Rename {} 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 = data_path.clone();
|
|
||||||
let downloaded_filename = ver_url.1.rsplit("/").nth(0).unwrap();
|
|
||||||
download_path.push(downloaded_filename.clone());
|
|
||||||
|
|
||||||
if !path::Path::exists(&download_path) {
|
|
||||||
println!("{:?}", download_path);
|
|
||||||
println!("Downloading Town of Us [{}]", 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).unwrap();
|
|
||||||
println!("Extracting...");
|
|
||||||
let mut archive = zip::ZipArchive::new(opened_zip).unwrap();
|
|
||||||
archive.extract(data_path.clone()).unwrap();
|
|
||||||
|
|
||||||
let mut root_folder_path = String::new();
|
|
||||||
for i in archive.file_names() {
|
|
||||||
root_folder_path = String::from(i.split("/").nth(0).unwrap());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let extracted_path: path::PathBuf =
|
|
||||||
[data_path.to_str().unwrap(), 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(),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
println!("Modded install already found");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find existing installs, make buttons for them
|
|
||||||
let install_iter = fs::read_dir(installs_path.clone());
|
|
||||||
|
|
||||||
match install_iter {
|
|
||||||
Ok(iter) => {
|
|
||||||
let mut collection: Vec<Result<fs::DirEntry, io::Error>> = iter.collect();
|
|
||||||
collection.reverse();
|
|
||||||
for i in collection {
|
|
||||||
// for i in iter {
|
|
||||||
let existing_ver_smash = i.unwrap().file_name();
|
|
||||||
let mut button = Button::new(&ui, existing_ver_smash.clone().to_str().unwrap());
|
|
||||||
button.on_clicked(&ui, {
|
|
||||||
let ui = ui.clone();
|
|
||||||
let installs_path = installs_path.clone();
|
|
||||||
let existing_ver_smash = existing_ver_smash.clone();
|
|
||||||
move |btn| {
|
|
||||||
let mut new_path = installs_path.clone();
|
|
||||||
new_path.push(existing_ver_smash.clone());
|
|
||||||
println!("{}", new_path.clone().to_str().unwrap());
|
|
||||||
attempt_run_among_us(&new_path);
|
|
||||||
btn.set_text(&ui, "Launching...");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
vbox.append(&ui, button, LayoutStrategy::Stretchy);
|
|
||||||
println!("{}", existing_ver_smash.clone().to_str().unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
win.set_child(&ui, vbox);
|
|
||||||
win.show(&ui);
|
|
||||||
ui.main();
|
|
||||||
// let mut install_folder_path = installs_path.clone();
|
|
||||||
// install_folder_path.push(version_smash);
|
|
||||||
// fs::create_dir(install_folder_path.clone()).unwrap_or(());
|
|
||||||
|
|
||||||
// Copy Among Us Out
|
|
||||||
// Create destination path
|
|
||||||
|
|
||||||
// let executable_path: path::PathBuf = [new_installed_path.to_str().unwrap(), "Among Us.exe"]
|
|
||||||
// .iter()
|
|
||||||
// .collect();
|
|
||||||
|
|
||||||
// std::process::Command::new(executable_path.to_str().unwrap())
|
|
||||||
// .spawn()
|
|
||||||
// .unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns (Version, URL)
|
// Returns (Version, URL)
|
||||||
@@ -238,33 +341,17 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String,
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.text()
|
.text()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut line = markdown.find(&among_us_version);
|
let mut line = markdown.find(&among_us_version);
|
||||||
let mut line_offset = 0;
|
let mut line_offset = 0;
|
||||||
let mut official_compatibility = false;
|
let mut official_compatibility = false;
|
||||||
if line.is_some() {
|
if line.is_some() {
|
||||||
println!("Found official version!");
|
println!("Found sanctioned version!");
|
||||||
official_compatibility = true;
|
official_compatibility = true;
|
||||||
} else {
|
} else {
|
||||||
println!("Official version cannot be determined, installing experimental latest...");
|
println!("Sanctioned version cannot be determined, installing experimental latest...");
|
||||||
line = markdown.find("[Download]");
|
line = markdown.find("[Download]");
|
||||||
line_offset = 15;
|
line_offset = 15;
|
||||||
// println!("At this point, there are two options:");
|
|
||||||
// println!(" [1] Revert Among Us to public-previous in Steam THEN select this option.");
|
|
||||||
// println!(" [2] Attempt to use the latest version of Town of Us anyway");
|
|
||||||
// let mut input = String::new();
|
|
||||||
// io::stdin().read_line(&mut input).unwrap();
|
|
||||||
// match input.trim() {
|
|
||||||
// "1" => {
|
|
||||||
// println!("Re-attempting...");
|
|
||||||
// return None;
|
|
||||||
// }
|
|
||||||
// "2" => {
|
|
||||||
// println!("Continuing...");
|
|
||||||
// line = markdown.find("[Download]");
|
|
||||||
// line_offset = 15;
|
|
||||||
// }
|
|
||||||
// _ => return None,
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
// 100% scientific "-15" here to get the correct version since we find to [Download] above which is after the version number for that line
|
// 100% scientific "-15" here to get the correct version since we find to [Download] above which is after the version number for that line
|
||||||
let splits = markdown.split_at(line.unwrap() - line_offset);
|
let splits = markdown.split_at(line.unwrap() - line_offset);
|
||||||
@@ -273,7 +360,7 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String,
|
|||||||
let captures = url_regex.captures(splits.1).unwrap();
|
let captures = url_regex.captures(splits.1).unwrap();
|
||||||
let capture = captures.get(captures.len() - 1).unwrap();
|
let capture = captures.get(captures.len() - 1).unwrap();
|
||||||
let url = splits.1.get(capture.start()..capture.end()).unwrap();
|
let url = splits.1.get(capture.start()..capture.end()).unwrap();
|
||||||
println!("Official URL is: {}", url);
|
println!("Mod URL is: {}", url);
|
||||||
let ver_regex = Regex::new(r#"\| (v\d\.\d\.\d) \|"#).unwrap();
|
let ver_regex = Regex::new(r#"\| (v\d\.\d\.\d) \|"#).unwrap();
|
||||||
let ver_captures = ver_regex.captures(splits.1).unwrap();
|
let ver_captures = ver_regex.captures(splits.1).unwrap();
|
||||||
let ver_capture = ver_captures.get(ver_captures.len() - 1).unwrap();
|
let ver_capture = ver_captures.get(ver_captures.len() - 1).unwrap();
|
||||||
@@ -281,66 +368,49 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String,
|
|||||||
.1
|
.1
|
||||||
.get(ver_capture.start()..ver_capture.end())
|
.get(ver_capture.start()..ver_capture.end())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("Matching version is: {}", ver);
|
println!("Installing Town of Us version: {}", ver);
|
||||||
Some((String::from(ver), String::from(url), official_compatibility))
|
Some((String::from(ver), String::from(url), official_compatibility))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn determine_among_us_version(folder_root: String) -> Option<String> {
|
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;
|
||||||
|
|
||||||
let target_bytes: [u8; TARGET_BYTES_LEN] = [3, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0];
|
let target_bytes: [u8; TARGET_BYTES_LEN] = [3, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0];
|
||||||
|
|
||||||
let file_bytes = fs::read(asset_file).unwrap();
|
if let Ok(file_bytes) = fs::read(asset_file) {
|
||||||
//println!("{:?}", file_bytes);
|
let mut bytes_str = String::new();
|
||||||
|
let mut target_head = 0;
|
||||||
|
let mut file_index = 0;
|
||||||
|
for i in &file_bytes {
|
||||||
|
if target_head == TARGET_BYTES_LEN {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let mut bytes_str = String::new();
|
if *i == target_bytes[target_head] {
|
||||||
let mut target_head = 0;
|
target_head += 1;
|
||||||
let mut file_index = 0;
|
} else {
|
||||||
for i in &file_bytes {
|
target_head = 0;
|
||||||
if target_head == TARGET_BYTES_LEN {
|
}
|
||||||
break;
|
file_index += 1;
|
||||||
|
bytes_str += &format!("{i:x}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if *i == target_bytes[target_head] {
|
let offset: usize = usize::from(file_bytes[file_index]);
|
||||||
target_head += 1;
|
file_index += 4;
|
||||||
} else {
|
|
||||||
target_head = 0;
|
Some(AmongUsVersion::from(
|
||||||
}
|
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(),
|
||||||
file_index += 1;
|
))
|
||||||
bytes_str += &format!("{i:x}");
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset: usize = usize::from(file_bytes[file_index]);
|
//println!("{:?}", file_bytes);
|
||||||
file_index += 4;
|
|
||||||
|
|
||||||
// let mut offset = 10;
|
|
||||||
|
|
||||||
// if file_bytes[file_index + 9] == 0 {
|
|
||||||
// offset -= 1;
|
|
||||||
// }
|
|
||||||
// if file_bytes[file_index + 8] == 0 {
|
|
||||||
// offset -= 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"|{}|",
|
|
||||||
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap()
|
|
||||||
);
|
|
||||||
let ver = AmongUsVersion::from(
|
|
||||||
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(),
|
|
||||||
);
|
|
||||||
println!("AmongUsVersion: {}", ver);
|
|
||||||
Some(String::from(
|
|
||||||
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(),
|
|
||||||
))
|
|
||||||
//println!("{}", bytes_str);
|
|
||||||
|
|
||||||
//None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_folder_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
|
fn copy_folder_to_target<T: AsRef<Path>>(source: T, dest: T) {
|
||||||
let mut copy_opts = dir::CopyOptions::new();
|
let mut copy_opts = dir::CopyOptions::new();
|
||||||
copy_opts.overwrite = true;
|
copy_opts.overwrite = true;
|
||||||
copy_opts.skip_exist = true;
|
copy_opts.skip_exist = true;
|
||||||
@@ -350,7 +420,7 @@ fn copy_folder_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
|
|||||||
copy_items(&from_paths, dest, ©_opts).unwrap();
|
copy_items(&from_paths, dest, ©_opts).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_folder_contents_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
|
fn copy_folder_contents_to_target<T: AsRef<Path>>(source: T, dest: T) {
|
||||||
let mut copy_opts = dir::CopyOptions::new();
|
let mut copy_opts = dir::CopyOptions::new();
|
||||||
copy_opts.overwrite = true;
|
copy_opts.overwrite = true;
|
||||||
copy_opts.skip_exist = true;
|
copy_opts.skip_exist = true;
|
||||||
@@ -358,12 +428,25 @@ fn copy_folder_contents_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
|
|||||||
copy_opts.content_only = true;
|
copy_opts.content_only = true;
|
||||||
fs_extra::dir::copy(source, dest, ©_opts).unwrap();
|
fs_extra::dir::copy(source, dest, ©_opts).unwrap();
|
||||||
}
|
}
|
||||||
fn detect_among_us_folder() -> Option<String> {
|
|
||||||
let library_folder =
|
fn detect_steam() -> Option<(String, LauncherType)> {
|
||||||
fs::read_to_string("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");
|
let mut library_folder_path: PathBuf =
|
||||||
|
PathBuf::from("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");
|
||||||
|
if let Ok(steam_regkey) = Hive::LocalMachine.open(
|
||||||
|
r"SOFTWARE\WOW6432Node\Valve\Steam",
|
||||||
|
registry::Security::Read,
|
||||||
|
) {
|
||||||
|
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!("{:?}", library_folder_path.to_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let library_folder = 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() {
|
||||||
@@ -372,27 +455,43 @@ fn detect_among_us_folder() -> Option<String> {
|
|||||||
} else {
|
} else {
|
||||||
library_folder_string.truncate(appid_index.unwrap());
|
library_folder_string.truncate(appid_index.unwrap());
|
||||||
}
|
}
|
||||||
//println!("{}", library_folder_string);
|
|
||||||
|
|
||||||
let path_regex = Regex::new(r#"path"\s+"([Z-a\w\d\s\\\(\):]+)""#).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 caps: regex::CaptureMatches = path_regex.captures_iter(&library_folder_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();
|
||||||
/*
|
|
||||||
println!(
|
|
||||||
"{}",
|
|
||||||
library_folder_string
|
|
||||||
.get(start.start()..start.end())
|
|
||||||
.unwrap()
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return Some(format!(
|
return Some((
|
||||||
"{}\\\\steamapps\\\\common\\\\Among Us\\\\",
|
format!(
|
||||||
library_folder_string
|
r"{}\\steamapps\\common\\Among Us\\",
|
||||||
.get(start.start()..start.end())
|
library_folder_string
|
||||||
.unwrap()
|
.get(start.start()..start.end())
|
||||||
|
.unwrap()
|
||||||
|
),
|
||||||
|
LauncherType::Steam,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
None
|
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 {
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|||||||
31
src/semver.rs
Normal file
31
src/semver.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
//! # SemVer
|
||||||
|
|
||||||
|
//! A simple Semantic Versioning struct to handle comparisons and ordering
|
||||||
|
|
||||||
|
// Uses
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
||||||
|
pub struct SemVer {
|
||||||
|
pub major: i32,
|
||||||
|
pub minor: i32,
|
||||||
|
pub patch: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for SemVer {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for SemVer {
|
||||||
|
fn from(s: &str) -> SemVer {
|
||||||
|
let v: Vec<&str> = s.split('.').collect();
|
||||||
|
|
||||||
|
SemVer {
|
||||||
|
major: v[0].parse().unwrap(),
|
||||||
|
minor: v[1].parse().unwrap(),
|
||||||
|
patch: v[2].parse().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user