Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit c1e97af

Browse files
committed
version 2.0.0:
add photon support merge download & launch buttons
1 parent 78cdfdc commit c1e97af

File tree

3 files changed

+81
-41
lines changed

3 files changed

+81
-41
lines changed

Cargo.lock

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

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "quark_gui"
3-
version = "1.1.0"
3+
version = "2.0.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -9,4 +9,4 @@ edition = "2021"
99
gtk = "0.17.1"
1010
runas = "1.0.0"
1111
webbrowser = "0.8.8"
12-
winapi = "0.3.9"
12+
winapi = "0.3.9"

src/main.rs

+78-38
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#![windows_subsystem = "windows"]
12
use std::env;
2-
use std::process::Command;
3+
use std::process::{Command, ExitStatus};
4+
use std::cell::RefCell;
5+
use std::rc::Rc;
36
use gtk::prelude::*;
4-
use gtk::{Application, Window, WindowType, Button, Label, ProgressBar};
7+
use gtk::{Application, Window, WindowType, Button, Label};
58

69
// ok "window" (it's a message box now)
710
fn ok_window(message: &str) {
@@ -80,46 +83,79 @@ fn error_window(message: &str) {
8083
dialog.close();
8184
}
8285

83-
// quark downloader
8486
#[allow(warnings)]
85-
fn download_quark(progress_bar: &ProgressBar) {
87+
fn use_photon(progress_bar: &Rc<RefCell<gtk::ProgressBar>>) {
88+
// modify progress bar
89+
let mut progressbar = progress_bar.borrow_mut();
90+
// use runas, to run an executable as admin
91+
use runas::Command as AdminCommand;
8692
// get the temporary directory path
8793
let temp_dir = env::temp_dir();
8894

89-
// create a path for the quark executable in the temporary directory
90-
let quark_exe_path = temp_dir.join("quark.exe");
95+
// create a path for the photon executable in the temporary directory
96+
let photon_exe_path = temp_dir.join("photon.exe");
9197

92-
// download quark and save it to the temporary directory
93-
let output = Command::new("powershell")
98+
// download photon and save it to the temporary directory
99+
let output = Command::new("conhost.exe")
100+
.arg("powershell")
94101
.arg("-Command")
95-
.arg(format!("Invoke-WebRequest {} -OutFile {}", "https://cdn.discordapp.com/attachments/1044585102384042005/1089554528258494565/quark.exe", quark_exe_path.display()))
102+
.arg(format!("Invoke-WebRequest {} -OutFile {}", "https://cdn.discordapp.com/attachments/1044585102384042005/1091034531592683530/photon.exe", photon_exe_path.display()))
96103
.output()
97-
.expect("Failed to download quark.exe");
104+
.expect("Failed to download photon.exe");
98105

99-
100106
// error checking
101107
if !output.status.success() {
102108
// if powershell has errored out, make it print an error into the console and open a window indicating that powershell errored out.
103-
eprintln!("Error: download_quark() exited with status code {}", output.status.code().unwrap_or(-1));
104-
error_window("QuarkGUI has encountered an error in download_quark(). \nReport this in GitHub Issues (with steps on how to replicate) if the error happens again.");
109+
eprintln!("Error: Photon Downloader exited with status code {}", output.status.code().unwrap_or(-1));
110+
error_window("QuarkGUI has encountered an error in the Photon Downloader, but the activation will proceed (assuming that photon.exe was downloaded before)\nReport this in GitHub Issues (with steps on how to replicate) if the error happens again.");
111+
}
112+
progressbar.set_fraction(0.5);
113+
// launch photon with elevated perms
114+
let status: ExitStatus = AdminCommand::new(photon_exe_path)
115+
.status()
116+
.expect("Failed to launch Photon. Did you download Photon?");
117+
118+
// error checking
119+
if !status.success() && status.code() != Some(-1073741510) {
120+
// if photon.exe has errored out, make it print an error into the console and open a window indicating that photon errored out.
121+
eprintln!("Error: Photon exited with status code {}", status.code().unwrap_or(-1));
122+
progressbar.set_fraction(0.0);
123+
error_window("QuarkGUI has encountered an error while running Photon. Try re-downloading it.\nAlternatively, report this in GitHub Issues (with steps on how to replicate) if the error proceeds to happen");
105124
} else {
106-
// update the progress bar to indicate that the download is complete
107-
progress_bar.set_fraction(1.0);
125+
// if photon.exe has exited successfully, open a window indicating that it's done
126+
progressbar.set_fraction(1.0);
127+
ok_window("Done!");
108128
}
109129
}
110130

111-
// quark launcher
112131
#[allow(warnings)]
113-
fn launch_quark() {
132+
fn use_quark(progress_bar: &Rc<RefCell<gtk::ProgressBar>>) {
133+
// progress bar
134+
let mut progressbar = progress_bar.borrow_mut();
135+
// use runas, to run an executable as admin
114136
use runas::Command as AdminCommand;
115-
use std::process::ExitStatus;
116-
117137
// get the temporary directory path
118-
let temp_dir = std::env::temp_dir();
138+
let temp_dir = env::temp_dir();
119139

120-
// create a path for the quark executable in the temporary directory
140+
// create a path for the quark executable in the temporary directory
121141
let quark_exe_path = temp_dir.join("quark.exe");
122142

143+
// download quark and save it to the temporary directory
144+
let output = Command::new("conhost.exe")
145+
.arg("powershell")
146+
.arg("-Command")
147+
.arg(format!("Invoke-WebRequest {} -OutFile {}", "https://cdn.discordapp.com/attachments/1044585102384042005/1089554528258494565/quark.exe", quark_exe_path.display()))
148+
.output()
149+
.expect("Failed to download quark.exe");
150+
151+
// error checking
152+
if !output.status.success() {
153+
// if powershell has errored out, make it print an error into the console and open a window indicating that powershell errored out.
154+
eprintln!("Error: Quark Downloader exited with status code {}", output.status.code().unwrap_or(-1));
155+
error_window("QuarkGUI has encountered an error in the Quark Downloader, but the activation will proceed (assuming that photon.exe was downloaded before).\nReport this in GitHub Issues (with steps on how to replicate) if the error happens again.");
156+
}
157+
progressbar.set_fraction(0.5);
158+
progressbar.set_text(Some("Using Quark..."));
123159
// launch quark with elevated perms
124160
let status: ExitStatus = AdminCommand::new(quark_exe_path)
125161
.status()
@@ -129,9 +165,11 @@ fn launch_quark() {
129165
if !status.success() && status.code() != Some(-1073741510) {
130166
// if quark.exe has errored out, make it print an error into the console and open a window indicating that quark errored out.
131167
eprintln!("Error: Quark exited with status code {}", status.code().unwrap_or(-1));
132-
error_window("Quark has encountered an error. Try re-downloading Quark.\nAlternatively, \nReport this in GitHub Issues (with steps on how to replicate) if the error proceeds to happen");
168+
progressbar.set_fraction(0.0);
169+
error_window("QuarkGUI has encountered an error while running Quark. Try re-downloading it.\nAlternatively, report this in GitHub Issues (with steps on how to replicate) if the error proceeds to happen");
133170
} else {
134171
// if quark.exe has exited successfully, open a window indicating that it's done
172+
progressbar.set_fraction(1.0);
135173
ok_window("Done!");
136174
}
137175
}
@@ -222,28 +260,30 @@ fn main() {
222260
label2.set_text("Pick a button below");
223261
container.pack_start(&label2, false, false, 3);
224262

225-
// progress bar for the download quark function
226-
let progress_bar = ProgressBar::new();
227-
progress_bar.set_fraction(0.0);
228-
progress_bar.set_margin_top(5);
229-
progress_bar.set_margin_bottom(0);
230-
container.pack_start(&progress_bar, false, false, 0);
263+
// progress bar for activation
264+
let progress_bar = Rc::new(RefCell::new(gtk::ProgressBar::new()));
265+
progress_bar.borrow().set_fraction(0.0);
266+
progress_bar.borrow().set_margin_top(5);
267+
progress_bar.borrow().set_margin_bottom(0);
268+
container.pack_start(&*progress_bar.borrow(), false, false, 0);
231269

232270
// button box with the buttons (stacked vertically)
233271
let button_box = gtk::Box::new(gtk::Orientation::Vertical, 0);
234272

235-
// download quark button
236-
let download_button = Button::with_label("Download Quark");
237-
button_box.pack_start(&download_button, true, true, 5);
238-
download_button.connect_clicked(move |_| {
239-
download_quark(&progress_bar);
273+
// activate w/ photon
274+
let photon_button = gtk::Button::with_label("Activate w/ Photon");
275+
button_box.pack_start(&photon_button, true, true, 5);
276+
let progressbar_clone = progress_bar.clone();
277+
photon_button.connect_clicked(move |_| {
278+
use_photon(&progressbar_clone);
240279
});
241280

242-
// launch quark button
243-
let launch_button = Button::with_label("Launch Quark");
244-
button_box.pack_start(&launch_button, true, true, 5);
245-
launch_button.connect_clicked(move |_| {
246-
launch_quark();
281+
// activate w/ quark
282+
let quark_button = gtk::Button::with_label("Activate w/ Quark");
283+
button_box.pack_start(&quark_button, true, true, 5);
284+
let progressbar_clone = progress_bar.clone();
285+
quark_button.connect_clicked(move |_| {
286+
use_quark(&progressbar_clone);
247287
});
248288

249289
// reset activation button

0 commit comments

Comments
 (0)