pub fn init_oc_build(
    resources: &mut Resources,
    settings: &mut Settings,
    stdout: &mut Stdout,
) -> Result<(), Box<dyn Error>> {
    settings.oc_build_version_res_index = Default::default(); // reset oc_build_version to top of dortania
                                                              //    settings.resource_ver_indexes = Default::default(); // this will clear out resource version indexes for dortania

    // test if version selected is latest version, don't try to download zip of latest
    // it doesn't exist yet
    let latest_ver = resources.dortania["OpenCorePkg"]["versions"][0]["version"]
        .as_str()
        .unwrap();
    if latest_ver == &settings.oc_build_version {
        settings.oc_build_version = "latest".to_owned();
    }

    if settings.oc_build_version == "latest" {
        settings.oc_build_version = resources.dortania["OpenCorePkg"]["versions"][0]["version"]
            .as_str()
            .unwrap()
            .to_owned();
        let path = Path::new(
            resources.octool_config["opencorepkg_path"]
                .as_str()
                .unwrap(),
        );
        resources.open_core_source_path = Path::new(&path).to_path_buf();
        let path = path.join("Docs");
        if !path.exists() {
            std::fs::create_dir_all(&path)?;
        }
        let url = resources.octool_config["current_configuration_tex"]
            .as_str()
            .unwrap();
        res::curl_file(&url, &path.join(&url.split('/').last().unwrap()))?;
        let url = resources.octool_config["current_sample_plist"]
            .as_str()
            .unwrap();
        res::curl_file(&url, &path.join(&url.split('/').last().unwrap()))?;
    } else {
        loop {
            if let Some(v) = resources.dortania["OpenCorePkg"]["versions"]
                [settings.oc_build_version_res_index]["version"]
                .as_str()
            {
                if v == settings.oc_build_version {
                    break;
                }
            } else {
                write!(
                    stdout,
                    "\r\n\x1b[33mERROR:\x1b[0m Version \x1b[32m{}\x1b[0m of OpenCorePkg not found in repos, please check your input\x1b[0K\r\n\x1b[0K\ne.g. './octool -o \x1b[4m0.7.4\x1b[0m'\x1b[0K\n",
                    settings.oc_build_version
                )
                .unwrap();
                settings.oc_build_version = "not found".to_owned();
                return Ok(());
            }
            settings.oc_build_version_res_index += 1;
        }
        let mut path = "resources/OpenCorePkg-".to_owned();
        path.push_str(&settings.oc_build_version);
        resources.open_core_source_path = Path::new(&path).to_path_buf();
        path.push_str(".zip");
        let path = Path::new(&path).to_path_buf();

        let mut url = "https://github.com/acidanthera/OpenCorePkg/archive/refs/tags/".to_owned();
        url.push_str(&settings.oc_build_version);
        url.push_str(".zip");
        write!(
            stdout,
            "\x1B[32mChecking\x1B[0m OpenCorePkg {} source\r\n",
            settings.oc_build_version
        )?;
        if !resources.open_core_source_path.exists() {
            write!(
                stdout,
                "\x1B[32mDownloading\x1B[0m OpenCorePkg {} source from Acidanthera ... ",
                settings.oc_build_version
            )?;
            stdout.flush()?;
            res::get_file_and_unzip(&url, "", &path, stdout)?;
            write!(stdout, "\x1B[32mDone\x1B[0m\r\n")?;
        } else {
            write!(stdout, "Already up to date.\r\n")?;
        }
    }

    settings.resource_ver_indexes.insert(
        "OpenCorePkg".to_owned(),
        Manifest(
            settings.oc_build_version_res_index,
            resources.dortania["OpenCorePkg"]["versions"][settings.oc_build_version_res_index]
                ["commit"]["sha"]
                .as_str()
                .unwrap_or("")
                .to_string(),
        ),
    );
    settings.oc_build_date = resources.dortania["OpenCorePkg"]["versions"]
        [settings.oc_build_version_res_index]["date_built"]
        .as_str()
        .unwrap_or("")
        .to_owned();

    let sample_plist = &resources.open_core_source_path.join("Docs/Sample.plist");
    resources.sample_plist = Value::from_file(sample_plist)
        .expect(format!("Didn't find Sample.plist at {:?}", sample_plist).as_str());

    write!(
        stdout,
        "\r\n\x1B[32mChecking\x1B[0m local OpenCorePkg {} binaries\r\n",
        settings.oc_build_version
    )?;
    let path = res::get_or_update_local_parent(
        "OpenCorePkg",
        &resources.dortania,
        &settings.build_type,
        &settings.resource_ver_indexes.get("OpenCorePkg").unwrap().0,
        true,
        true,
        stdout,
    )?;

    match path {
        Some(p) => resources.open_core_binaries_path = p.parent().unwrap().to_path_buf(),
        _ => panic!("no OpenCorePkg found"),
    }

    Ok(())
}
/// load OpenCore binary packages and support files based on the version of
/// OpenCore that is selected, will change resources used on the fly if user
/// uses the 'V' command to change OC version #
load OpenCore binary packages and support files based on the version of
OpenCore that is selected, will change resources used on the fly if user
uses the 'V' command to change OC version
load OpenCore binary packages and support files based on the version of OpenCore that is selected will change resources used on the fly if user uses the ' V ' command to change OC version
pub fn init_oc_build(
    resources: &mut Resources,
    settings: &mut Settings,
    stdout: &mut Stdout,
) -> Result<(), Box<dyn Error>> {
    settings.oc_build_version_res_index = Default::default(); // reset oc_build_version to top of dortania
                                                              //    settings.resource_ver_indexes = Default::default(); // this will clear out resource version indexes for dortania
    // test if version selected is latest version, don't try to download zip of latest
    // it doesn't exist yet
    let latest_ver = resources.dortania["OpenCorePkg"]["versions"][0]["version"]
        .as_str()
        .unwrap();
    if latest_ver == &settings.oc_build_version {
        settings.oc_build_version = "latest".to_owned();
    }
    if settings.oc_build_version == "latest" {
        settings.oc_build_version = resources.dortania["OpenCorePkg"]["versions"][0]["version"]
            .as_str()
            .unwrap()
            .to_owned();
        let path = Path::new(
            resources.octool_config["opencorepkg_path"]
                .as_str()
                .unwrap(),
        );
        resources.open_core_source_path = Path::new(&path).to_path_buf();
        let path = path.join("Docs");
        if !path.exists() {
            std::fs::create_dir_all(&path)?;
        }
        let url = resources.octool_config["current_configuration_tex"]
            .as_str()
            .unwrap();
        res::curl_file(&url, &path.join(&url.split('/').last().unwrap()))?;
        let url = resources.octool_config["current_sample_plist"]
            .as_str()
            .unwrap();
        res::curl_file(&url, &path.join(&url.split('/').last().unwrap()))?;
    } else {
        loop {
            if let Some(v) = resources.dortania["OpenCorePkg"]["versions"]
                [settings.oc_build_version_res_index]["version"]
                .as_str()
            {
                if v == settings.oc_build_version {
                    break;
                }
            } else {
                write!(
                    stdout,
                    "\r\n\x1b[33mERROR:\x1b[0m Version \x1b[32m{}\x1b[0m of OpenCorePkg not found in repos, please check your input\x1b[0K\r\n\x1b[0K\ne.g. './octool -o \x1b[4m0.7.4\x1b[0m'\x1b[0K\n",
                    settings.oc_build_version
                )
                .unwrap();
                settings.oc_build_version = "not found".to_owned();
                return Ok(());
            }
            settings.oc_build_version_res_index += 1;
        }
        let mut path = "resources/OpenCorePkg-".to_owned();
        path.push_str(&settings.oc_build_version);
        resources.open_core_source_path = Path::new(&path).to_path_buf();
        path.push_str(".zip");
        let path = Path::new(&path).to_path_buf();
        let mut url = "https://github.com/acidanthera/OpenCorePkg/archive/refs/tags/".to_owned();
        url.push_str(&settings.oc_build_version);
        url.push_str(".zip");
        write!(
            stdout,
            "\x1B[32mChecking\x1B[0m OpenCorePkg {} source\r\n",
            settings.oc_build_version
        )?;
        if !resources.open_core_source_path.exists() {
            write!(
                stdout,
                "\x1B[32mDownloading\x1B[0m OpenCorePkg {} source from Acidanthera ... ",
                settings.oc_build_version
            )?;
            stdout.flush()?;
            res::get_file_and_unzip(&url, "", &path, stdout)?;
            write!(stdout, "\x1B[32mDone\x1B[0m\r\n")?;
        } else {
            write!(stdout, "Already up to date.\r\n")?;
        }
    }
    settings.resource_ver_indexes.insert(
        "OpenCorePkg".to_owned(),
        Manifest(
            settings.oc_build_version_res_index,
            resources.dortania["OpenCorePkg"]["versions"][settings.oc_build_version_res_index]
                ["commit"]["sha"]
                .as_str()
                .unwrap_or("")
                .to_string(),
        ),
    );
    settings.oc_build_date = resources.dortania["OpenCorePkg"]["versions"]
        [settings.oc_build_version_res_index]["date_built"]
        .as_str()
        .unwrap_or("")
        .to_owned();
    let sample_plist = &resources.open_core_source_path.join("Docs/Sample.plist");
    resources.sample_plist = Value::from_file(sample_plist)
        .expect(format!("Didn't find Sample.plist at {:?}", sample_plist).as_str());
    write!(
        stdout,
        "\r\n\x1B[32mChecking\x1B[0m local OpenCorePkg {} binaries\r\n",
        settings.oc_build_version
    )?;
    let path = res::get_or_update_local_parent(
        "OpenCorePkg",
        &resources.dortania,
        &settings.build_type,
        &settings.resource_ver_indexes.get("OpenCorePkg").unwrap().0,
        true,
        true,
        stdout,
    )?;
    match path {
        Some(p) => resources.open_core_binaries_path = p.parent().unwrap().to_path_buf(),
        _ => panic!("no OpenCorePkg found"),
    }
    Ok(())
}
pub fn init_oc_build ( resources : & mut Resources , settings : & mut Settings , stdout : & mut Stdout , ) -> Result < ( ) , Box < dyn Error > > { settings . oc_build_version_res_index = Default :: default ( ) ; // reset oc_build_version to top of dortania //    settings.resource_ver_indexes = Default::default(); // this will clear out resource version indexes for dortania // test if version selected is latest version, don't try to download zip of latest // it doesn't exist yet let latest_ver = resources . dortania [ " " ] [ " " ] [ 0 ] [ " " ] . as_str ( ) . unwrap ( ) ; if latest_ver == & settings . oc_build_version { settings . oc_build_version = " " . to_owned ( ) ; } if settings . oc_build_version == " " { settings . oc_build_version = resources . dortania [ " " ] [ " " ] [ 0 ] [ " " ] . as_str ( ) . unwrap ( ) . to_owned ( ) ; let path = Path :: new ( resources . octool_config [ " " ] . as_str ( ) . unwrap ( ) , ) ; resources . open_core_source_path = Path :: new ( & path ) . to_path_buf ( ) ; let path = path . join ( " " ) ; if ! path . exists ( ) { std :: fs :: create_dir_all ( & path ) ? ; } let url = resources . octool_config [ " " ] . as_str ( ) . unwrap ( ) ; res :: curl_file ( & url , & path . join ( & url . split ( '/' ) . last ( ) . unwrap ( ) ) ) ? ; let url = resources . octool_config [ " " ] . as_str ( ) . unwrap ( ) ; res :: curl_file ( & url , & path . join ( & url . split ( '/' ) . last ( ) . unwrap ( ) ) ) ? ; } else { loop { if let Some ( v ) = resources . dortania [ " " ] [ " " ] [ settings . oc_build_version_res_index ] [ " " ] . as_str ( ) { if v == settings . oc_build_version { break ; } } else { write ! ( stdout " \r \n \x1b \x1b \x1b \x1b \x1b \r \n \x1b \n \x1b \x1b \x1b \n " settings oc_build_version ) . unwrap ( ) ; settings . oc_build_version = " " . to_owned ( ) ; return Ok ( ( ) ) ; } settings . oc_build_version_res_index += 1 ; } let mut path = " " . to_owned ( ) ; path . push_str ( & settings . oc_build_version ) ; resources . open_core_source_path = Path :: new ( & path ) . to_path_buf ( ) ; path . push_str ( " " ) ; let path = Path :: new ( & path ) . to_path_buf ( ) ; let mut url = " " . to_owned ( ) ; url . push_str ( & settings . oc_build_version ) ; url . push_str ( " " ) ; write ! ( stdout " \x1B \x1B \r \n " settings oc_build_version ) ? ; if ! resources . open_core_source_path . exists ( ) { write ! ( stdout " \x1B \x1B " settings oc_build_version ) ? ; stdout . flush ( ) ? ; res :: get_file_and_unzip ( & url , " " , & path , stdout ) ? ; write ! ( stdout " \x1B \x1B \r \n " ) ? ; } else { write ! ( stdout " \r \n " ) ? ; } } settings . resource_ver_indexes . insert ( " " . to_owned ( ) , Manifest ( settings . oc_build_version_res_index , resources . dortania [ " " ] [ " " ] [ settings . oc_build_version_res_index ] [ " " ] [ " " ] . as_str ( ) . unwrap_or ( " " ) . to_string ( ) , ) , ) ; settings . oc_build_date = resources . dortania [ " " ] [ " " ] [ settings . oc_build_version_res_index ] [ " " ] . as_str ( ) . unwrap_or ( " " ) . to_owned ( ) ; let sample_plist = & resources . open_core_source_path . join ( " " ) ; resources . sample_plist = Value :: from_file ( sample_plist ) . expect ( format ! ( " " sample_plist ) . as_str ( ) ) ; write ! ( stdout " \r \n \x1B \x1B \r \n " settings oc_build_version ) ? ; let path = res :: get_or_update_local_parent ( " " , & resources . dortania , & settings . build_type , & settings . resource_ver_indexes . get ( " " ) . unwrap ( ) . 0 , true , true , stdout , ) ? ; match path { Some ( p ) => resources . open_core_binaries_path = p . parent ( ) . unwrap ( ) . to_path_buf ( ) , _ => panic ! ( " " ) , } Ok ( ( ) ) }
load OpenCore binary packages and support files based on the version of
OpenCore that is selected, will change resources used on the fly if user
uses the 'V' command to change OC version
load OpenCore binary packages and support files based on the version of OpenCore that is selected will change resources used on the fly if user uses the ' V ' command to change OC version
resources
&mut Resources
settings
&mut Settings
stdout
&mut Stdout
resources
&mut Resources
settings
&mut Settings
stdout
&mut Stdout