Skip to content

Commit

Permalink
add not-yet-properly-functioning progress callback to install_geode
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed May 17, 2022
1 parent ced3412 commit 5d218bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
16 changes: 14 additions & 2 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ use crate::VersionInfo;
use crate::InstallInfo;
use serde_json;

use crate::ProgressCallback;
use crate::string2c;

pub fn install_geode(
exe: &Path,
nightly: bool,
api: bool
api: bool,
callback: ProgressCallback
) -> Result<InstallInfo, Box<dyn std::error::Error>> {
let url = if nightly {
"https://github.com/geode-sdk/suite/archive/refs/heads/nightly.zip"
Expand All @@ -23,7 +27,6 @@ pub fn install_geode(
}
fs::create_dir(&src_dir).unwrap();


let mod_dir = if cfg!(windows) {
src_dir.push("windows");
exe.parent().unwrap().to_path_buf()
Expand All @@ -38,8 +41,17 @@ pub fn install_geode(
exe.join("Contents").join("Frameworks")
};

unsafe {
callback(string2c("Downloading"), 0);
}

// todo: figure out some way to gauge get progress
let resp = get(url)?.bytes()?;

unsafe {
callback(string2c("Installing"), 99);
}

let mut archive = zip::ZipArchive::new(std::io::Cursor::new(resp))?;
archive.extract(&src_dir).unwrap();

Expand Down
12 changes: 8 additions & 4 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
//pub mod font;
pub mod suite;
pub mod install;
use std::os::raw::c_char;

use std::path::Path;

pub type ProgressCallback = extern "stdcall" fn(*const c_char, i32) -> ();

#[repr(C)]
pub struct VersionInfo {
major: i32,
Expand Down Expand Up @@ -51,7 +54,6 @@ pub const GEODE_TARGET_VERSION: VersionInfo = VersionInfo {
};

use std::ffi::CStr;
use std::os::raw::c_char;

unsafe fn string2c<E>(err: E) -> *mut c_char
where E: ToString {
Expand Down Expand Up @@ -79,7 +81,7 @@ pub unsafe extern "C" fn geode_target_version() -> VersionInfo {
pub unsafe extern "C" fn geode_install_suite(
location: *const c_char,
nightly: bool,
callback: suite::SuiteProgressCallback
callback: ProgressCallback
) -> *const c_char {
match crate::suite::install_suite(
Path::new(c2string(location)),
Expand All @@ -95,12 +97,14 @@ pub unsafe extern "C" fn geode_install_suite(
pub unsafe extern "C" fn geode_install_geode(
location: *const c_char,
nightly: bool,
api: bool
api: bool,
callback: ProgressCallback
) -> *const c_char {
match crate::install::install_geode(
Path::new(c2string(location)),
nightly,
api
api,
callback
) {
Ok(_) => std::ptr::null(),
Err(b) => string2c(b)
Expand Down
6 changes: 2 additions & 4 deletions lib/src/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ use git2::{FetchOptions, Repository, RemoteCallbacks, SubmoduleUpdateOptions, Pr

use std::io::{Result, Error, ErrorKind};
use std::path::Path;
use std::os::raw::c_char;

use crate::ProgressCallback;
use crate::string2c;

pub type SuiteProgressCallback = extern "stdcall" fn(*const c_char, i32) -> ();

pub fn install_suite(
path: &Path,
nightly: bool,
callback: SuiteProgressCallback
callback: ProgressCallback
) -> Result<()> {
let prog_fn = |info: &String, prog: Progress| {
let percentage =
Expand Down

0 comments on commit 5d218bd

Please sign in to comment.