Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 762b2f61aa | |||
| 3bd05ba8dd | |||
| ff311475dc | |||
| 8e61c8a2f2 | |||
| fbc4c747a5 | |||
| 9468194718 | |||
| 69f67d303e | |||
| 6d05440d98 | |||
| 972c310673 | |||
| 90b703ee30 |
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "town-of-us-updater"
|
||||
version = "2.3.0"
|
||||
version = "4.0.1"
|
||||
edition = "2021"
|
||||
build = "src/build.rs"
|
||||
|
||||
@@ -12,11 +12,13 @@ regex = "1.5"
|
||||
fs_extra = "1.2.0"
|
||||
dirs = "4.0.0"
|
||||
reqwest = {version = "0.11.11", features = ["blocking"]}
|
||||
iui = "0.3.0"
|
||||
serde_json = "1.0"
|
||||
md-5 = "0.10.5"
|
||||
tokio = {version="1", features=["full"]}
|
||||
druid = "0.7.0"
|
||||
registry = "1"
|
||||
egui = "0.20.1"
|
||||
eframe = "0.20.1"
|
||||
rfd = "0.10"
|
||||
|
||||
[build-dependencies]
|
||||
embed-resource = "1.6"
|
||||
|
||||
@@ -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
|
||||
- GUI to select which build to play
|
||||
- Auto-detection of Among Us install directory
|
||||
- Auto-launch of BetterCrewLink if installed
|
||||
|
||||
# Contributing
|
||||
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
use crate::AmongUsVersion;
|
||||
use crate::AppData;
|
||||
use druid::{
|
||||
widget::*, BoxConstraints, Env, Event, EventCtx, FileDialogOptions, LayoutCtx, LifeCycle,
|
||||
LifeCycleCtx, PaintCtx, Selector, Size, UpdateCtx, WidgetExt, WidgetPod,
|
||||
};
|
||||
use std::{fs, io, path::PathBuf};
|
||||
|
||||
pub const ATTEMPT_INSTALL: Selector = Selector::new("town-of-us-updater.attempt_install");
|
||||
|
||||
pub struct AmongUsLauncherWidget {
|
||||
pub root: WidgetPod<AppData, Flex<AppData>>,
|
||||
}
|
||||
|
||||
impl AmongUsLauncherWidget {
|
||||
pub fn build_widget(&mut self, data: &AppData) {
|
||||
let mut flex: Flex<AppData> = Flex::column();
|
||||
|
||||
// Find existing installs, make buttons for them
|
||||
let install_iter = fs::read_dir(data.installs_path.clone());
|
||||
|
||||
if let Ok(iter) = install_iter {
|
||||
let mut collection: Vec<Result<fs::DirEntry, io::Error>> = iter.collect();
|
||||
collection.reverse();
|
||||
|
||||
if collection.is_empty() {
|
||||
if data.among_us_path.is_empty() {
|
||||
// We did not find an install path, let's add a button to prompt the user
|
||||
// to find their install path
|
||||
let open_button = Button::new("Locate Among Us")
|
||||
.fix_height(45.0)
|
||||
.on_click(move |ctx, _: &mut AppData, _| {
|
||||
ctx.submit_command(
|
||||
druid::commands::SHOW_OPEN_PANEL.with(FileDialogOptions::new()),
|
||||
);
|
||||
})
|
||||
.center();
|
||||
flex.add_flex_child(open_button, 1.0);
|
||||
} else {
|
||||
let label: druid::widget::Label<AppData> =
|
||||
druid::widget::Label::new("We found Among Us but you have no installs");
|
||||
flex.add_flex_child(label, 1.0);
|
||||
}
|
||||
} else {
|
||||
// Iterate first to find labels:
|
||||
|
||||
let mut flexbox_array: Vec<druid::widget::Flex<AppData>> = Vec::new();
|
||||
let mut auv_array: Vec<AmongUsVersion> = Vec::new();
|
||||
|
||||
for i in &collection {
|
||||
let existing_ver_smash = i.as_ref().unwrap().file_name();
|
||||
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();
|
||||
|
||||
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:");
|
||||
|
||||
for i in collection {
|
||||
let existing_ver_smash = i.unwrap().file_name();
|
||||
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
|
||||
let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
|
||||
let button_string: String =
|
||||
format!("Town of Us {}", ver_smash_split.next().unwrap());
|
||||
|
||||
for (index, j) in auv_array.iter().enumerate() {
|
||||
if j == &among_us_version {
|
||||
let mut clone: PathBuf = PathBuf::from(data.installs_path.clone());
|
||||
clone.push(existing_ver_smash.clone());
|
||||
|
||||
let mut button_row: Flex<AppData> = Flex::row();
|
||||
|
||||
let fybutton = druid::widget::Button::new(button_string.as_str())
|
||||
.fix_height(45.0)
|
||||
.center()
|
||||
.on_click(move |_, _: &mut AppData, _| {
|
||||
crate::attempt_run_among_us(&clone);
|
||||
// crate::launch_better_crewlink().unwrap();
|
||||
});
|
||||
|
||||
button_row.add_flex_child(fybutton, 1.0);
|
||||
|
||||
// TODO: Uncomment
|
||||
// let delete_button = druid::widget::Button::new("Delete")
|
||||
// .fix_height(45.0)
|
||||
// .on_click(move |_, _: &mut AppData, _| {});
|
||||
|
||||
// button_row.add_flex_child(delete_button, 1.0);
|
||||
|
||||
flexbox_array
|
||||
.get_mut(index)
|
||||
.unwrap()
|
||||
.add_flex_child(button_row, 1.0);
|
||||
|
||||
println!("- {}", existing_ver_smash.clone().to_str().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flexbox_array.reverse();
|
||||
|
||||
for i in flexbox_array {
|
||||
flex.add_flex_child(i, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.root = WidgetPod::new(flex);
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget<AppData> for AmongUsLauncherWidget {
|
||||
fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut AppData, env: &Env) {
|
||||
// println!("{:?}", event);
|
||||
// println!("{:?}", data);
|
||||
match event {
|
||||
Event::MouseDown(_a) => {
|
||||
// println!("Mouse Down!");
|
||||
self.root.event(ctx, event, data, env);
|
||||
}
|
||||
Event::WindowConnected => {
|
||||
self.build_widget(data);
|
||||
ctx.children_changed();
|
||||
}
|
||||
Event::KeyDown(evt) => {
|
||||
if evt.code == druid::Code::F5 {
|
||||
ctx.submit_command(ATTEMPT_INSTALL);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.root.event(ctx, event, data, env);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &AppData, env: &Env) {
|
||||
self.root.lifecycle(ctx, event, data, env);
|
||||
// println!("Lifecycle!")
|
||||
}
|
||||
fn update(&mut self, ctx: &mut UpdateCtx, old_data: &AppData, data: &AppData, env: &Env) {
|
||||
self.root.update(ctx, data, env);
|
||||
if old_data.among_us_path.is_empty() && !data.among_us_path.is_empty() {
|
||||
ctx.submit_command(ATTEMPT_INSTALL);
|
||||
// println!("Detect Stuff");
|
||||
}
|
||||
// println!("Update!");
|
||||
self.build_widget(data);
|
||||
ctx.children_changed();
|
||||
}
|
||||
fn layout(
|
||||
&mut self,
|
||||
ctx: &mut LayoutCtx,
|
||||
bc: &BoxConstraints,
|
||||
data: &AppData,
|
||||
env: &Env,
|
||||
) -> Size {
|
||||
self.root.layout(ctx, bc, data, env);
|
||||
// println!("Layout!");
|
||||
bc.constrain((400.0, 400.0))
|
||||
}
|
||||
|
||||
fn paint(&mut self, ctx: &mut PaintCtx, data: &AppData, env: &Env) {
|
||||
self.root.paint(ctx, data, env);
|
||||
// println!("Paint!");
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
use druid::Data;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Clone, Debug, Data)]
|
||||
#[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)
|
||||
@@ -48,3 +53,39 @@ impl From<(i32, i32, i32)> for AmongUsVersion {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
|
||||
420
src/main.rs
420
src/main.rs
@@ -1,16 +1,15 @@
|
||||
// Modules
|
||||
mod among_us_launcher_widget;
|
||||
mod among_us_version;
|
||||
mod semver;
|
||||
|
||||
// Uses
|
||||
use among_us_launcher_widget::*;
|
||||
use among_us_version::*;
|
||||
|
||||
use md5::{Digest, Md5};
|
||||
use semver::*;
|
||||
|
||||
use std::{
|
||||
fs,
|
||||
fs, io,
|
||||
path::{Path, PathBuf},
|
||||
process, str,
|
||||
};
|
||||
@@ -19,17 +18,35 @@ use fs_extra::{copy_items, dir};
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use registry::Hive;
|
||||
|
||||
// GUI stuff
|
||||
use druid::{
|
||||
commands, widget::*, AppDelegate, AppLauncher, Data, DelegateCtx, Env, Handled, Target,
|
||||
WidgetPod, WindowDesc, WindowId,
|
||||
};
|
||||
|
||||
struct Delegate;
|
||||
use eframe::egui;
|
||||
|
||||
#[derive(Data, Clone, Debug)]
|
||||
use reqwest::StatusCode;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub enum InitializingState {
|
||||
StartingGUI,
|
||||
DeterminingVersion,
|
||||
CopyingAmongUs,
|
||||
UnmoddingAmongUs,
|
||||
DownloadingZip,
|
||||
Unzipping,
|
||||
CopyingZipIn,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub enum GlobalAppState {
|
||||
Initializing(InitializingState),
|
||||
Initialized,
|
||||
Installing,
|
||||
Playing,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AppData {
|
||||
pub among_us_path: String,
|
||||
pub installs_path: String,
|
||||
@@ -37,6 +54,151 @@ pub struct AppData {
|
||||
pub initialized: bool,
|
||||
pub among_us_version: AmongUsVersion,
|
||||
pub data_path: String,
|
||||
pub app_state: GlobalAppState,
|
||||
pub blessed_version: String,
|
||||
pub update_installs_list: bool,
|
||||
pub installs_last_update_time: std::time::Instant,
|
||||
pub installs_list: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl Default for AppData {
|
||||
fn default() -> AppData {
|
||||
AppData {
|
||||
among_us_path: String::new(),
|
||||
installs_path: String::new(),
|
||||
version: SemVer {
|
||||
major: 0,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
},
|
||||
initialized: false,
|
||||
among_us_version: AmongUsVersion::default(),
|
||||
data_path: String::new(),
|
||||
app_state: GlobalAppState::Initialized,
|
||||
blessed_version: String::new(),
|
||||
update_installs_list: true,
|
||||
installs_last_update_time: std::time::Instant::now(),
|
||||
installs_list: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppData {
|
||||
fn detect_installs(&mut self) {
|
||||
let install_iter = fs::read_dir(self.installs_path.clone());
|
||||
if let Ok(iter) = install_iter {
|
||||
self.installs_list = iter
|
||||
.map(|elem| PathBuf::from(elem.unwrap().file_name()))
|
||||
.collect();
|
||||
} else {
|
||||
self.installs_list.clear();
|
||||
}
|
||||
self.installs_last_update_time = std::time::Instant::now();
|
||||
}
|
||||
|
||||
fn draw_layout(&mut self, ui: &mut egui::Ui) {
|
||||
let now = std::time::Instant::now();
|
||||
if now.duration_since(self.installs_last_update_time) > std::time::Duration::from_secs(10) {
|
||||
self.detect_installs();
|
||||
}
|
||||
|
||||
let mut collection = self.installs_list.clone();
|
||||
|
||||
if collection.is_empty() {
|
||||
if ui.button("Locate your Among Us Directory").clicked() {
|
||||
if let Some(mut path) = rfd::FileDialog::new().pick_file() {
|
||||
path.pop();
|
||||
self.among_us_path = path.display().to_string();
|
||||
self.on_path_added();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
collection.reverse();
|
||||
let mut auv_array: Vec<AmongUsVersion> = Vec::new();
|
||||
|
||||
for i in &collection {
|
||||
let existing_ver_smash = i;
|
||||
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
|
||||
let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
|
||||
if !auv_array.contains(&among_us_version) {
|
||||
auv_array.push(among_us_version);
|
||||
}
|
||||
}
|
||||
|
||||
auv_array.sort();
|
||||
auv_array.reverse();
|
||||
|
||||
ui.separator();
|
||||
for i in &auv_array {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Among Us {}", i.as_american_string())).size(35.0),
|
||||
);
|
||||
for j in &collection {
|
||||
let existing_ver_smash = j;
|
||||
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split('-');
|
||||
let mut blessed_split = self.blessed_version.as_str().split('-');
|
||||
let among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
|
||||
let tou_version = ver_smash_split.next().unwrap();
|
||||
let blessed_version = AmongUsVersion::from(blessed_split.next().unwrap());
|
||||
let blessed_tou_version = blessed_split.next().unwrap();
|
||||
let button_string: String = format!("Town of Us {}", tou_version);
|
||||
if i == &among_us_version {
|
||||
let mut clone: PathBuf = PathBuf::from(self.installs_path.clone());
|
||||
clone.push(existing_ver_smash.clone());
|
||||
ui.horizontal(|ui| {
|
||||
if i == &blessed_version && tou_version == blessed_tou_version {
|
||||
let button_text = egui::RichText::new(button_string.clone())
|
||||
.size(25.0)
|
||||
.color(egui::Color32::GREEN);
|
||||
if ui.button(button_text).clicked() {
|
||||
crate::attempt_run_among_us(&clone);
|
||||
}
|
||||
} else {
|
||||
let button_text = egui::RichText::new(button_string.clone()).size(25.0);
|
||||
if ui.button(button_text).clicked() {
|
||||
crate::attempt_run_among_us(&clone);
|
||||
}
|
||||
}
|
||||
|
||||
if !self.initialized {
|
||||
ui.set_visible(false);
|
||||
}
|
||||
|
||||
let button_text = egui::RichText::new("DELETE")
|
||||
.size(25.0)
|
||||
.color(egui::Color32::RED);
|
||||
|
||||
if ui.button(button_text).clicked() {
|
||||
if i != &blessed_version || tou_version != blessed_tou_version {
|
||||
crate::attempt_delete_among_us(&clone);
|
||||
self.update_installs_list = true;
|
||||
}
|
||||
}
|
||||
|
||||
ui.set_visible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for AppData {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
if self.update_installs_list {
|
||||
self.detect_installs();
|
||||
self.update_installs_list = false;
|
||||
}
|
||||
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||
ui.checkbox(&mut self.initialized, "DELETE MODE");
|
||||
});
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
self.draw_layout(ui);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static AMONG_US_APPID: &str = "945360";
|
||||
@@ -51,6 +213,10 @@ fn attempt_run_among_us(install_path: &Path) {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn attempt_delete_among_us(install_path: &Path) {
|
||||
fs::remove_dir_all(install_path).unwrap();
|
||||
}
|
||||
|
||||
fn unmod_among_us_folder(folder_path: &Path) {
|
||||
println!("Unmodding Among Us...");
|
||||
let doorstop_path: PathBuf = [folder_path.to_str().unwrap(), "doorstop_config.ini"]
|
||||
@@ -117,61 +283,33 @@ async fn _get_latest_updater_version() -> Result<(String, String), reqwest::Erro
|
||||
Ok((String::from("no"), String::from("yes")))
|
||||
}
|
||||
|
||||
impl AppDelegate<AppData> for Delegate {
|
||||
fn window_added(
|
||||
&mut self,
|
||||
_id: WindowId,
|
||||
data: &mut AppData,
|
||||
_env: &Env,
|
||||
ctx: &mut DelegateCtx,
|
||||
) {
|
||||
if !data.among_us_path.is_empty() {
|
||||
ctx.submit_command(ATTEMPT_INSTALL);
|
||||
impl AppData {
|
||||
fn on_path_added(&mut self) {
|
||||
if self.among_us_path.is_empty() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fn command(
|
||||
&mut self,
|
||||
_ctx: &mut DelegateCtx,
|
||||
_target: Target,
|
||||
cmd: &druid::Command,
|
||||
data: &mut AppData,
|
||||
_env: &Env,
|
||||
) -> Handled {
|
||||
// println!("Command!");
|
||||
if let Some(file_info) = cmd.get(commands::OPEN_FILE) {
|
||||
let among_us_folder = file_info.path();
|
||||
let mut buf = among_us_folder.to_path_buf();
|
||||
buf.pop();
|
||||
data.among_us_path = String::from(buf.to_str().unwrap());
|
||||
|
||||
// Pop the selected file off the end of the path
|
||||
// among_us_folder.pop();
|
||||
println!("{}", buf.to_str().unwrap());
|
||||
// println!("Handled!");
|
||||
//Application::global().quit();
|
||||
|
||||
return Handled::Yes;
|
||||
} else if let Some(_a) = cmd.get(among_us_launcher_widget::ATTEMPT_INSTALL) {
|
||||
if let Some(among_us_version) =
|
||||
determine_among_us_version(String::from(data.among_us_path.clone()))
|
||||
determine_among_us_version(String::from(self.among_us_path.clone()))
|
||||
{
|
||||
data.among_us_version = among_us_version.clone();
|
||||
self.among_us_version = among_us_version.clone();
|
||||
println!("AmongUsVersion: {}", among_us_version);
|
||||
let ver_url: (String, String, bool) =
|
||||
determine_town_of_us_url(among_us_version.to_string().clone()).unwrap();
|
||||
}
|
||||
|
||||
let version_smash = format!("{}-{}", among_us_version, ver_url.0.clone());
|
||||
let new_installed_path: PathBuf =
|
||||
[data.installs_path.as_str(), version_smash.as_str()]
|
||||
self.app_state = GlobalAppState::Initializing(InitializingState::DeterminingVersion);
|
||||
let ver_url: (String, String, bool) =
|
||||
determine_town_of_us_url(self.among_us_version.to_string().clone()).unwrap();
|
||||
|
||||
let version_smash = format!("{}-{}", self.among_us_version, ver_url.0.clone());
|
||||
let new_installed_path: PathBuf = [self.installs_path.as_str(), version_smash.as_str()]
|
||||
.iter()
|
||||
.collect();
|
||||
|
||||
if !Path::exists(&new_installed_path) {
|
||||
println!("Copying Among Us to cache location...");
|
||||
copy_folder_to_target(data.among_us_path.clone(), data.installs_path.clone());
|
||||
copy_folder_to_target(self.among_us_path.clone(), self.installs_path.clone());
|
||||
|
||||
let among_us_path: PathBuf =
|
||||
[data.installs_path.as_str(), "Among Us\\"].iter().collect();
|
||||
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);
|
||||
@@ -191,7 +329,7 @@ impl AppDelegate<AppData> for Delegate {
|
||||
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 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);
|
||||
|
||||
@@ -213,7 +351,7 @@ impl AppDelegate<AppData> for Delegate {
|
||||
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();
|
||||
archive.extract(self.data_path.clone()).unwrap();
|
||||
|
||||
fs::remove_file(download_path).unwrap();
|
||||
|
||||
@@ -222,8 +360,7 @@ impl AppDelegate<AppData> for Delegate {
|
||||
root_folder_path = String::from(i.split('/').next().unwrap());
|
||||
break;
|
||||
}
|
||||
let extracted_path: PathBuf =
|
||||
[data.data_path.as_str(), root_folder_path.as_str(), "."]
|
||||
let extracted_path: PathBuf = [self.data_path.as_str(), root_folder_path.as_str(), "."]
|
||||
.iter()
|
||||
.collect();
|
||||
println!("{}", extracted_path.to_str().unwrap());
|
||||
@@ -232,22 +369,24 @@ impl AppDelegate<AppData> for Delegate {
|
||||
new_installed_path.to_str().unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
data.initialized = !data.initialized;
|
||||
|
||||
return Handled::Yes;
|
||||
}
|
||||
|
||||
Handled::No
|
||||
self.initialized = !self.initialized;
|
||||
self.app_state = GlobalAppState::Initialized;
|
||||
self.update_installs_list = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
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();
|
||||
|
||||
// println!("Updater Version: {}", version);
|
||||
// get_latest_updater_version().await.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
|
||||
let mut data_path = dirs::data_dir().unwrap();
|
||||
@@ -258,6 +397,102 @@ fn main() {
|
||||
installs_path.push("installs");
|
||||
fs::create_dir(installs_path.clone()).unwrap_or(());
|
||||
|
||||
let mut true_env = false;
|
||||
for argument in std::env::args() {
|
||||
if argument == "true" {
|
||||
true_env = true;
|
||||
}
|
||||
}
|
||||
|
||||
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 updated_exe_hash = String::new();
|
||||
|
||||
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.")
|
||||
}
|
||||
|
||||
// If we heard back, try to update, otherwise run normally
|
||||
if !updated_exe_hash.is_empty() {
|
||||
let mut our_hash = String::new();
|
||||
let mut try_continue = false;
|
||||
match fs::read(&exe_path) {
|
||||
Ok(bytes) => {
|
||||
let mut hasher = Md5::new();
|
||||
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();
|
||||
@@ -279,17 +514,20 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let app_data: AppData = AppData {
|
||||
let mut app_data: AppData = AppData {
|
||||
among_us_path: String::from(among_us_folder.clone().to_str().unwrap()),
|
||||
installs_path: String::from(installs_path.clone().to_str().unwrap()),
|
||||
version: SemVer::from(version),
|
||||
initialized: 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(),
|
||||
};
|
||||
|
||||
let mut root_column: druid::widget::Flex<AppData> = druid::widget::Flex::column();
|
||||
|
||||
// DETERMINE AMONG US VERSION
|
||||
|
||||
if let Some(among_us_folder_str) = among_us_folder.to_str() {
|
||||
@@ -300,34 +538,23 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
// println!("Checking for updater updates...");
|
||||
// let vals: (String, String) = version_check_thread_handle.join().unwrap();
|
||||
|
||||
// TODO: Auto launch latest sanctioned if the user has a setting like that
|
||||
// Auto launch latest experimental as well
|
||||
|
||||
println!("Launching main window...");
|
||||
|
||||
let _main_menu: druid::MenuDesc<AppData> =
|
||||
druid::MenuDesc::empty().append(druid::MenuItem::new(
|
||||
druid::LocalizedString::new("File"),
|
||||
druid::Command::new(druid::Selector::new("test"), 0, Target::Auto),
|
||||
));
|
||||
|
||||
let widget: AmongUsLauncherWidget = AmongUsLauncherWidget {
|
||||
root: WidgetPod::new(Flex::column()),
|
||||
};
|
||||
|
||||
root_column.add_flex_child(widget, 1.0);
|
||||
launch_better_crewlink().unwrap_or(());
|
||||
|
||||
let main_window = WindowDesc::new(|| root_column)
|
||||
.title(title_string)
|
||||
// .menu(main_menu)
|
||||
.window_size((400.0, 400.0));
|
||||
let app_launcher = AppLauncher::with_window(main_window).delegate(Delegate {});
|
||||
let _external_handler = app_launcher.get_external_handle();
|
||||
app_launcher.launch(app_data).unwrap();
|
||||
let mut native_options = eframe::NativeOptions::default();
|
||||
native_options.min_window_size = Some(egui::vec2(425.0, 400.0));
|
||||
native_options.initial_window_size = Some(egui::vec2(425.0, 400.0));
|
||||
app_data.on_path_added();
|
||||
app_data.detect_installs(); // Initial check since we only update every 10s
|
||||
eframe::run_native(
|
||||
title_string.as_str(),
|
||||
native_options,
|
||||
Box::new(|_cc| Box::new(app_data)),
|
||||
);
|
||||
}
|
||||
|
||||
fn launch_better_crewlink() -> std::result::Result<(), String> {
|
||||
@@ -388,7 +615,7 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, 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;
|
||||
|
||||
@@ -454,20 +681,25 @@ fn _detect_epic() -> 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(
|
||||
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("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() {
|
||||
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() {
|
||||
@@ -483,11 +715,13 @@ fn detect_among_us_folder() -> Option<String> {
|
||||
let start = last_path.get(last_path.len() - 1).unwrap();
|
||||
|
||||
return Some(format!(
|
||||
"{}\\\\steamapps\\\\common\\\\Among Us\\\\",
|
||||
r"{}\\steamapps\\common\\Among Us\\",
|
||||
library_folder_string
|
||||
.get(start.start()..start.end())
|
||||
.unwrap()
|
||||
));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// Uses
|
||||
use std::fmt;
|
||||
|
||||
#[derive(druid::Data, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
||||
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
||||
pub struct SemVer {
|
||||
pub major: i32,
|
||||
pub minor: i32,
|
||||
|
||||
Reference in New Issue
Block a user