Skip to content

Commit

Permalink
Add Azul Zulu to JRE swapper (#198)
Browse files Browse the repository at this point in the history
* Add Azul Zulu to JRE swapper
  • Loading branch information
atlanticaccent committed Apr 4, 2023
1 parent 7fdf14b commit 1d4fc5d
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 94 deletions.
34 changes: 11 additions & 23 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,9 @@ jobs:
runs-on: windows-latest
env:
VCPKG_DEFAULT_TRIPLET: x64-windows-static
VCPKG_ROOT: 'C:\vcpkg'
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal

- name: Cache vcpkg installed
uses: actions/cache@v1.0.3
with:
path: $VCPKG_ROOT/installed
key: windows-vcpkg-cache
env:
VCPKG_ROOT: 'C:\vcpkg'
- name: Cache vcpkg downloads
uses: actions/cache@v1.0.3
with:
path: $VCPKG_ROOT/downloads
key: windows-vcpkg-cache
env:
VCPKG_ROOT: 'C:\vcpkg'

- name: Install dependencies Windows
run: vcpkg integrate install; vcpkg install libarchive:x64-windows-static
env:
VCPKG_ROOT: 'C:\vcpkg'

- name: Check cache
uses: actions/cache@v2
Expand All @@ -54,6 +32,16 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Setup vcpkg
run: |
(cargo install cargo-vcpkg || true)
cargo vcpkg build
- uses: actions-rs/toolchain@v1
with:
profile: minimal

- uses: actions-rs/cargo@v1
with:
command: build
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ name = "Starsector Mod Manager"
id = "org.laird.starsector_mod_manager"
osx_minimum_system_version = "10.10"

[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
rev = "69efe9cc2df0015f0bb2d37d55acde4a75c9a25b"
dependencies = ["libarchive"]

[workspace]
members = [
"webview-subsystem",
Expand Down
38 changes: 38 additions & 0 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,44 @@ impl Settings {
.expand_width(),
1.,
)
.with_flex_child(
Card::new(
Flex::column()
.with_child(h2("Azul Zulu"))
.with_child(bold_text(
"JRE 8v362 (b09)",
theme::TEXT_SIZE_NORMAL,
druid::FontWeight::SEMI_BOLD,
druid::theme::TEXT_COLOR,
))
.with_child(bold_text(
"(RESEARCH)",
theme::TEXT_SIZE_NORMAL,
druid::FontWeight::MEDIUM,
druid::Color::rgb8(236, 188, 0),
))
.with_spacer(5.)
.with_child(
Button2::new(Label::new("Install").padding((10., 0.))).on_click(
|ctx, data: &mut Settings, _| {
data.jre_swap_in_progress = true;
if let Some(vmparams) = data.vmparams.as_mut() {
vmparams.verify_none = true;
let _ = vmparams.save(data.install_dir.as_ref().unwrap().clone());
}
tokio::runtime::Handle::current().spawn(Flavour::Azul.swap(
ctx.get_external_handle(),
data.install_dir.as_ref().unwrap().clone(),
data.jre_managed_mode
));
},
),
)
.main_axis_alignment(druid::widget::MainAxisAlignment::Center),
)
.expand_width(),
1.,
)
.expand_width(),
)
.with_child(
Expand Down
40 changes: 21 additions & 19 deletions src/app/settings/jre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum Flavour {
Coretto,
Hotspot,
Wisp,
Azul,
}

const ORIGINAL_JRE_BACKUP: &str = "jre7";
Expand Down Expand Up @@ -77,7 +78,7 @@ impl Flavour {

Ok(false)
});
if already_installed.is_ok_and(|val| *val) {
if let Ok(true) = already_installed {
return already_installed;
}

Expand Down Expand Up @@ -131,22 +132,21 @@ impl Flavour {
Ok(false)
}

fn get_url(&self) -> &'static str {
fn to_const(&self) -> (&'static str, FindBy) {
match self {
Flavour::Coretto => consts::CORETTO,
Flavour::Hotspot => consts::HOTSPOT,
Flavour::Wisp => consts::WISP,
Flavour::Azul => consts::AZUL,
}
.0
}

fn get_url(&self) -> &'static str {
self.to_const().0
}

fn get_search_strategy(&self) -> FindBy {
match self {
Flavour::Coretto => consts::CORETTO,
Flavour::Hotspot => consts::HOTSPOT,
Flavour::Wisp => consts::WISP,
}
.1
self.to_const().1
}

async fn unpack(&self, root: &Path) -> anyhow::Result<TempDir> {
Expand Down Expand Up @@ -191,17 +191,11 @@ impl Flavour {
while let Some(Ok(file)) = iter.next() {
if let Ok(file_type) = file.file_type() {
if file_type.is_dir() {
if matches!(search_strategy, FindBy::Bin)
if search_strategy == FindBy::Bin
&& file.file_name().eq_ignore_ascii_case("bin")
{
return Some(
file
.path()
.parent()
.expect("Get parent of bin")
.to_path_buf(),
);
} else if matches!(search_strategy, FindBy::Jre)
return Some(path);
} else if search_strategy == FindBy::Jre
&& file.file_name().eq_ignore_ascii_case("jre")
{
return Some(file.path());
Expand Down Expand Up @@ -289,7 +283,7 @@ async fn revert_jre(root: &Path) -> anyhow::Result<bool> {
}

#[allow(dead_code)]
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq)]
pub enum FindBy {
Bin,
Jre,
Expand All @@ -305,6 +299,7 @@ mod consts {
"https://drive.google.com/uc?export=download&id=155Lk0ml9AUGp5NwtTZGpdu7e7Ehdyeth&confirm=t",
FindBy::Bin,
);
pub const AZUL: (&str, FindBy) = ("https://cdn.azul.com/zulu/bin/zulu8.68.0.21-ca-jre8.0.362-win_x64.zip", FindBy::Bin);

pub const JRE_PATH: &str = "jre";
}
Expand All @@ -318,6 +313,7 @@ mod consts {
"https://drive.google.com/uc?export=download&id=1TRHjle6-MOpn1zJhtSA9yvwXIQip_F_n&confirm=t",
FindBy::Bin,
);
pub const AZUL: (&str, FindBy) = ("https://cdn.azul.com/zulu/bin/zulu8.68.0.21-ca-jre8.0.362-linux_x64.zip", FindBy::Bin);

pub const JRE_PATH: &'static str = "jre_linux";
}
Expand All @@ -331,6 +327,7 @@ mod consts {
"https://drive.google.com/uc?export=download&id=1PW9v_CL719buKHe69GaN9fCXcPIqDOIi&confirm=t",
FindBy::Bin,
);
pub const AZUL: (&str, FindBy) = ("https://cdn.azul.com/zulu/bin/zulu8.68.0.21-ca-jre8.0.362-macosx_x64.zip", FindBy::Bin);

pub const JRE_PATH: &'static str = "Contents/Home";
}
Expand Down Expand Up @@ -419,6 +416,11 @@ mod test {
base_test(Flavour::Wisp, true, None, None, false, false);
}

#[test]
fn azul() {
base_test(Flavour::Azul, true, None, None, false, false);
}

#[test]
fn installs_even_if_actual_is_missing_and_unmanaged() {
base_test(Flavour::Coretto, None, None, None, false, false);
Expand Down

0 comments on commit 1d4fc5d

Please sign in to comment.