Skip to content

Commit ce0a310

Browse files
Merge pull request #7 from Zalexanninev15/version-1.5
2 parents 7b68fe8 + 6ff9336 commit ce0a310

8 files changed

+2240
-1892
lines changed

Cargo.lock

+2,195-1,747
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gru"
3-
version = "1.4.0"
3+
version = "1.5.0"
44
edition = "2021"
55
authors = ["Zalexanninev15 <blue.shark@disroot.org>"]
66
license = "MIT License"
@@ -16,19 +16,17 @@ winapi = { version = "0.3.9", features = [
1616
"handleapi",
1717
"processthreadsapi",
1818
"winnt",
19-
"securitybaseapi",
20-
"impl-default",
19+
"securitybaseapi"
2120
] }
22-
arguments = "0.6.2"
23-
#pelite = "0.9.1"
24-
isahc = "1.0.0"
25-
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
26-
trauma = "2.0.0"
27-
console = "0.15.1"
28-
tokio = "1.0.0"
21+
arguments = "0.7.1"
22+
isahc = "1.7.2"
23+
serde_json = { version = "1.0.95", default-features = false, features = ["alloc"] }
24+
trauma = "2.2.1"
25+
console = "0.15.5"
26+
tokio = "1.27.0"
2927

3028
[profile.release]
31-
strip = true # Comment this if cargo-bloat: cargo bloat --release --crates
29+
strip = true
3230
opt-level = "z"
3331
lto = true
34-
codegen-units = 1
32+
codegen-units = 1

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Zalexanninev15
3+
Copyright (c) 2022-2023 Zalexanninev15
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Updater for applications from GitHub
2222

2323
## System requirements
2424

25-
- **OS:** Windows 7 or higher
25+
- **OS:** Windows 10 (x64) or higher (may work on Windows 7/8/8.1, but the correct display of characters in the console is not guaranteed). The latest version for Windows 7/8/8.1 (x32 and x64) is [version 1.4-1 (1.4.0.1)](https://github.com/Zalexanninev15/GRU/releases/tag/1.4.0.1)
2626

2727
## Usage
2828

src/downloader.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::{fs, path::PathBuf};
1+
use std::{fs, path::{PathBuf, Path}};
2+
use console::style;
23
use tokio;
34
use trauma::{
45
download::Download,
5-
downloader::{DownloaderBuilder, StyleOptions},
6-
Error,
6+
downloader::{DownloaderBuilder, StyleOptions, ProgressBarOpts},
7+
Error
78
};
89

910
// Download the asset
@@ -19,16 +20,36 @@ pub async fn download(
1920
"https://github.com/{}/releases/download/{}/{}",
2021
repo, ver_tag, file
2122
));
23+
let d_file = String::from(format!("{}\\{}", application_path, file));
24+
if Path::new(&d_file).exists() {
25+
fs::remove_file(&d_file).expect("\n");
26+
}
2227
let downloads = vec![Download::try_from(asset).unwrap()];
23-
let style_opts = StyleOptions::default();
28+
let style_opts = StyleOptions::new(
29+
ProgressBarOpts::new(
30+
Some(ProgressBarOpts::TEMPLATE_BAR_WITH_POSITION.into()),
31+
Some(ProgressBarOpts::CHARS_FINE.into()),
32+
true,
33+
false,
34+
),
35+
ProgressBarOpts::new(
36+
Some(format!(
37+
"{{bar:40.cyan}} {{bytes_per_sec:>13.green}} {{percent:>2.cyan}}{} {{bytes:>11.green}}/{{total_bytes:<11.green}}",
38+
style("%").cyan(),
39+
)),
40+
Some("████ ".into()),
41+
true,
42+
false,
43+
)
44+
);
2445
let downloader = DownloaderBuilder::new()
2546
.directory(PathBuf::from(application_path))
2647
.style_options(style_opts)
2748
.build();
2849
downloader.download(&downloads).await;
2950
fs::rename(
30-
String::from(format!("{}\\{}", application_path, file)),
51+
&d_file,
3152
String::from(format!("{}\\app.dat", application_path)),
3253
)?;
3354
Ok(())
34-
}
55+
}

src/get_version.rs

+2-62
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use std::fs::File;
22
use std::io::Read;
33
use std::path::Path;
4-
// use pelite::FileMap;
54

65
// Checker for the versions
76
pub fn is_new_version(new_version: &str, application_path: &str) -> i32 {
8-
let mut real_version = "0.0.0.0".to_string();
97
if Path::new("app.version").exists() && Path::new(&application_path).exists() {
10-
real_version = get_version_from_file();
8+
let real_version = get_version_from_file();
119
println!("\nCurrent version of app: {}", real_version);
1210
if new_version == real_version {
1311
return 0;
@@ -18,34 +16,6 @@ pub fn is_new_version(new_version: &str, application_path: &str) -> i32 {
1816
println!("\nCurrent version of app: <not detected>");
1917
return 1;
2018
}
21-
// let mut current_version = parse_pe_version(application_path);
22-
// println!("\nCurrent version of app: {}", current_version);
23-
// current_version = current_version
24-
// .to_lowercase()
25-
// .replace(",", ".")
26-
// .replace(" ", "")
27-
// .replace(".", "")
28-
// .replace("build", "")
29-
// .replace("v", "")
30-
// .replace("-", "");
31-
// let new_version_c = &new_version
32-
// .to_lowercase()
33-
// .replace(".", "")
34-
// .replace("v", "")
35-
// .replace("build", "")
36-
// .replace("ersion", "")
37-
// .replace(" ", "")
38-
// .replace("_", "")
39-
// .replace("-", "");
40-
// if current_version.contains(new_version_c) {
41-
// 0
42-
// } else {
43-
// if current_version == "" {
44-
// -1
45-
// } else {
46-
// 1
47-
// }
48-
// }
4919
}
5020

5121
// Get version from file as GitHub release tag
@@ -57,34 +27,4 @@ fn get_version_from_file() -> String {
5727
.read_to_string(&mut file_data)
5828
.expect("Error reading file with version information!");
5929
file_data
60-
}
61-
62-
// Function for getting the file version from PE file
63-
// fn parse_pe_version(file_path: &str) -> String {
64-
// match FileMap::open(file_path) {
65-
// Err(_) => "".to_string(),
66-
// Ok(file_map) => {
67-
// let result = match pelite::PeFile::from_bytes(&file_map) {
68-
// Err(e) => Err(e),
69-
// Ok(f) => f.resources(),
70-
// };
71-
// match result {
72-
// Err(_) => "".to_string(),
73-
// Ok(resources) => match resources.version_info() {
74-
// Err(_) => "".to_string(),
75-
// Ok(version_info) => match version_info.fixed() {
76-
// None => "".to_string(),
77-
// Some(fixed_info) => {
78-
// let version = fixed_info.dwFileVersion.to_string();
79-
// if version.len() > 0 {
80-
// version
81-
// } else {
82-
// fixed_info.dwProductVersion.to_string()
83-
// }
84-
// }
85-
// },
86-
// },
87-
// }
88-
// }
89-
// }
90-
// }
30+
}

src/main.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fn main() {
1212
let current_dir = main_func::current_dir();
1313
let mut first_launch = false;
1414
let mut create_only_version_file = false;
15-
let mut version_status_code = 1;
1615
const VERSION: &str = env!("CARGO_PKG_VERSION");
1716
let mut update_now = true;
1817
if arguments.len() >= 3 {
@@ -89,7 +88,7 @@ fn main() {
8988
update_now = false;
9089
println!("\nNo updates detected!");
9190
} else {
92-
version_status_code = get_version::is_new_version(&v_list_version, &app_path);
91+
let version_status_code = get_version::is_new_version(&v_list_version, &app_path);
9392
if version_status_code != 0 && create_only_version_file == false {
9493
println!("\nNew version ({}) is available!", v_list_version);
9594
if version_status_code == -1 {
@@ -106,16 +105,13 @@ fn main() {
106105
// Deleting unnecessary data
107106
main_func::task_kill(&launcher_exe);
108107
main_func::delete_file(&current_dir, &is_leave_folders);
109-
110-
// Old downloader by redl
111-
// main_func::downloading_by_redl(&repo, &part);
112-
113-
// New native downloader
108+
109+
// Downloading the file
114110
println!("Downloading...");
115111
let result =
116112
downloader::download(&repo, &v_list_version, &v_list_asset, &current_dir);
117113
if result.is_err() {
118-
println!("Failed to download!");
114+
println!("Failed to download!");
119115
}
120116

121117
// The updating process itself

src/main_func.rs

-55
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ pub fn run_post_script(current_dir: &str) {
4242
for out in String::from_utf8(script.stdout).iter() {
4343
println!("{}", out);
4444
}
45-
46-
// script.arg(format!("/C {}", &script_file));
47-
// script.execute_output().unwrap();
4845
}
4946

5047
// Kill application processes
@@ -53,60 +50,8 @@ pub fn task_kill(application_exe: &str) {
5350
let mut command = Command::new(TASKKILL_TOOL);
5451
command.arg("/F").arg("/T").arg("/IM").arg(application_exe);
5552
command.execute().unwrap();
56-
57-
// let output = command.execute_output().unwrap();
58-
// if let Some(exit_code) = output.status.code() {
59-
// if exit_code == 0 {
60-
// println!("The application processes are killed. (this is good)");
61-
// } else {
62-
// eprintln!("The process was not found. (this is good)");
63-
// }
64-
// } else {
65-
// eprintln!("Interrupted!");
66-
// press_btn_continue::wait("Press any key to exit...").unwrap();
67-
// process::exit(1);
68-
// }
6953
}
7054

71-
// Downloading github release by redl
72-
// pub fn downloading_by_redl(github_repo_path: &str, part: &str) {
73-
// const EGET_PATH: &str = "redl.exe";
74-
// let mut command = Command::new(EGET_PATH);
75-
// // let download_path = String::from(format!("{}app.dat", current_dir));
76-
// if part.contains(" ") {
77-
// command
78-
// .arg("-r")
79-
// .arg(github_repo_path)
80-
// .arg("-p")
81-
// .args(part.split(" "))
82-
// .arg("-o")
83-
// .arg("app.dat");
84-
// } else {
85-
// command
86-
// .arg("-r")
87-
// .arg(github_repo_path)
88-
// .arg("-p")
89-
// .arg(part)
90-
// .arg("-o")
91-
// .arg("app.dat");
92-
// }
93-
94-
// let output = command.execute_output().unwrap();
95-
// if let Some(exit_code) = output.status.code() {
96-
// if exit_code == 0 {
97-
// println!("Downloaded.");
98-
// } else {
99-
// eprintln!("Failed.");
100-
// press_btn_continue::wait("Press any key to exit...").unwrap();
101-
// process::exit(1);
102-
// }
103-
// } else {
104-
// eprintln!("Interrupted!");
105-
// press_btn_continue::wait("Press any key to exit...").unwrap();
106-
// process::exit(1);
107-
// }
108-
// }
109-
11055
// Update by rename file
11156
pub fn updating(current_dir: &str, launcher_exe: &str) -> std::io::Result<()> {
11257
fs::rename(

0 commit comments

Comments
 (0)