Skip to content

Commit 5d218bd

Browse files
committed
add not-yet-properly-functioning progress callback to install_geode
1 parent ced3412 commit 5d218bd

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

lib/src/install.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ use crate::VersionInfo;
66
use crate::InstallInfo;
77
use serde_json;
88

9+
use crate::ProgressCallback;
10+
use crate::string2c;
11+
912
pub fn install_geode(
1013
exe: &Path,
1114
nightly: bool,
12-
api: bool
15+
api: bool,
16+
callback: ProgressCallback
1317
) -> Result<InstallInfo, Box<dyn std::error::Error>> {
1418
let url = if nightly {
1519
"https://github.com/geode-sdk/suite/archive/refs/heads/nightly.zip"
@@ -23,7 +27,6 @@ pub fn install_geode(
2327
}
2428
fs::create_dir(&src_dir).unwrap();
2529

26-
2730
let mod_dir = if cfg!(windows) {
2831
src_dir.push("windows");
2932
exe.parent().unwrap().to_path_buf()
@@ -38,8 +41,17 @@ pub fn install_geode(
3841
exe.join("Contents").join("Frameworks")
3942
};
4043

44+
unsafe {
45+
callback(string2c("Downloading"), 0);
46+
}
47+
48+
// todo: figure out some way to gauge get progress
4149
let resp = get(url)?.bytes()?;
4250

51+
unsafe {
52+
callback(string2c("Installing"), 99);
53+
}
54+
4355
let mut archive = zip::ZipArchive::new(std::io::Cursor::new(resp))?;
4456
archive.extract(&src_dir).unwrap();
4557

lib/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
//pub mod font;
77
pub mod suite;
88
pub mod install;
9+
use std::os::raw::c_char;
910

1011
use std::path::Path;
1112

13+
pub type ProgressCallback = extern "stdcall" fn(*const c_char, i32) -> ();
14+
1215
#[repr(C)]
1316
pub struct VersionInfo {
1417
major: i32,
@@ -51,7 +54,6 @@ pub const GEODE_TARGET_VERSION: VersionInfo = VersionInfo {
5154
};
5255

5356
use std::ffi::CStr;
54-
use std::os::raw::c_char;
5557

5658
unsafe fn string2c<E>(err: E) -> *mut c_char
5759
where E: ToString {
@@ -79,7 +81,7 @@ pub unsafe extern "C" fn geode_target_version() -> VersionInfo {
7981
pub unsafe extern "C" fn geode_install_suite(
8082
location: *const c_char,
8183
nightly: bool,
82-
callback: suite::SuiteProgressCallback
84+
callback: ProgressCallback
8385
) -> *const c_char {
8486
match crate::suite::install_suite(
8587
Path::new(c2string(location)),
@@ -95,12 +97,14 @@ pub unsafe extern "C" fn geode_install_suite(
9597
pub unsafe extern "C" fn geode_install_geode(
9698
location: *const c_char,
9799
nightly: bool,
98-
api: bool
100+
api: bool,
101+
callback: ProgressCallback
99102
) -> *const c_char {
100103
match crate::install::install_geode(
101104
Path::new(c2string(location)),
102105
nightly,
103-
api
106+
api,
107+
callback
104108
) {
105109
Ok(_) => std::ptr::null(),
106110
Err(b) => string2c(b)

lib/src/suite.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ use git2::{FetchOptions, Repository, RemoteCallbacks, SubmoduleUpdateOptions, Pr
22

33
use std::io::{Result, Error, ErrorKind};
44
use std::path::Path;
5-
use std::os::raw::c_char;
65

6+
use crate::ProgressCallback;
77
use crate::string2c;
88

9-
pub type SuiteProgressCallback = extern "stdcall" fn(*const c_char, i32) -> ();
10-
119
pub fn install_suite(
1210
path: &Path,
1311
nightly: bool,
14-
callback: SuiteProgressCallback
12+
callback: ProgressCallback
1513
) -> Result<()> {
1614
let prog_fn = |info: &String, prog: Progress| {
1715
let percentage =

0 commit comments

Comments
 (0)