Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added gh_assets/minecraft-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gh_assets/vanilla-integration-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gh_assets/vanilla-integration-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly-2024-11-01"
18 changes: 14 additions & 4 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ backon = { version = "1.3.0", default-features = false, features = ["tokio-sleep
# Generic
void = "1"
directories = "5.0"
dirs = "5.0"
once_cell = "1.16.0"

# FS libs
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/app/gui/commands/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ pub(crate) async fn run_client(
client,
client_account,
skip_advertisement,
vanilla_integration: options.start_options.vanilla_integration,
};

thread::spawn(move || {
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/app/gui/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ pub(crate) mod auth;
pub(crate) mod client;
pub(crate) mod data;
pub(crate) mod system;
pub(crate) mod vanilla;

pub(crate) use auth::*;
pub(crate) use client::*;
pub(crate) use data::*;
pub(crate) use system::*;
pub(crate) use vanilla::*;
81 changes: 81 additions & 0 deletions src-tauri/src/app/gui/commands/vanilla.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* This file is part of LiquidLauncher (https://github.com/CCBlueX/LiquidLauncher)
*
* Copyright (c) 2015 - 2024 CCBlueX
*
* LiquidLauncher is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidLauncher is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidLauncher. If not, see <https://www.gnu.org/licenses/>.
*/

use std::path::PathBuf;
use serde::Serialize;

#[derive(Serialize)]
pub struct VanillaStatus {
pub found: bool,
pub path: String,
pub saves_count: usize,
pub resource_packs_count: usize,
pub shader_packs_count: usize,
}

fn get_vanilla_minecraft_dir() -> Option<PathBuf> {
#[cfg(target_os = "windows")]
{
dirs::data_dir().map(|p| p.join(".minecraft"))
}
#[cfg(target_os = "macos")]
{
dirs::home_dir().map(|p| p.join("Library/Application Support/minecraft"))
}
#[cfg(target_os = "linux")]
{
dirs::home_dir().map(|p| p.join(".minecraft"))
}
}

fn count_entries(path: &PathBuf) -> usize {
path.read_dir().map(|r| r.count()).unwrap_or(0)
}

#[tauri::command]
pub(crate) async fn get_vanilla_status(custom_path: Option<String>) -> Result<VanillaStatus, String> {
let mc_dir = if let Some(ref path) = custom_path {
if !path.is_empty() {
Some(PathBuf::from(path))
} else {
get_vanilla_minecraft_dir()
}
} else {
get_vanilla_minecraft_dir()
};

match mc_dir {
Some(path) if path.exists() => {
Ok(VanillaStatus {
found: true,
path: path.to_string_lossy().to_string(),
saves_count: count_entries(&path.join("saves")),
resource_packs_count: count_entries(&path.join("resourcepacks")),
shader_packs_count: count_entries(&path.join("shaderpacks")),
})
}
_ => Ok(VanillaStatus {
found: false,
path: String::new(),
saves_count: 0,
resource_packs_count: 0,
shader_packs_count: 0,
}),
}
}
3 changes: 2 additions & 1 deletion src-tauri/src/app/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ pub fn gui_main() {
get_launcher_version,
get_custom_mods,
install_custom_mod,
delete_custom_mod
delete_custom_mod,
get_vanilla_status
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
16 changes: 16 additions & 0 deletions src-tauri/src/app/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ pub(crate) struct StartOptions {
pub jvm_args: Option<Vec<String>>,
#[serde(rename = "memory", default = "default_memory")]
pub memory: u64,
#[serde(rename = "vanillaIntegration", default)]
pub vanilla_integration: VanillaIntegration,
}

#[derive(Clone, Serialize, Deserialize, Default)]
pub struct VanillaIntegration {
#[serde(rename = "customPath", default)]
pub custom_path: String,
#[serde(rename = "useVanillaSaves", default)]
pub use_vanilla_saves: bool,
#[serde(rename = "useVanillaResourcePacks", default)]
pub use_vanilla_resource_packs: bool,
#[serde(rename = "useVanillaShaderPacks", default)]
pub use_vanilla_shader_packs: bool,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -118,6 +132,7 @@ impl Options {
minecraft_account: legacy.current_account,
jvm_args: None, // No equivalent in legacy format
memory: 4096, // No equivalent in legacy format - default to 4GB
vanilla_integration: VanillaIntegration::default(),
},
version_options: VersionOptions {
branch_name: None, // Force recommended branch
Expand Down Expand Up @@ -153,6 +168,7 @@ impl Default for StartOptions {
custom_data_path: String::new(),
jvm_args: None,
memory: 4096,
vanilla_integration: VanillaIntegration::default(),
}
}
}
Expand Down
76 changes: 75 additions & 1 deletion src-tauri/src/minecraft/launcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

use std::collections::HashSet;
use std::path::Path;
use std::fs;
use std::path::{Path, PathBuf};

use std::process::exit;

Expand Down Expand Up @@ -103,6 +104,9 @@ pub async fn launch<D: Send + Sync>(
let assets_folder = join_and_mkdir!(data, "assets");
let game_dir = join_and_mkdir_vec!(data, vec!["gameDir", &*manifest.build.branch]);

// Setup vanilla integration symlinks
setup_vanilla_integration(&game_dir, &launching_parameter.vanilla_integration, &launcher_data)?;

let java_bin = load_jre(
&runtimes_folder,
&manifest,
Expand Down Expand Up @@ -276,8 +280,11 @@ pub struct StartParameter {
pub client: Client,
pub client_account: Option<ClientAccount>,
pub skip_advertisement: bool,
pub vanilla_integration: VanillaIntegration,
}

use crate::app::options::VanillaIntegration;

fn process_templates<F: Fn(&mut String, &str) -> Result<()>>(
input: &String,
retriever: F,
Expand Down Expand Up @@ -325,3 +332,70 @@ fn process_templates<F: Fn(&mut String, &str) -> Result<()>>(

Ok(output)
}

fn setup_vanilla_integration<D: Send + Sync>(
game_dir: &Path,
integration: &VanillaIntegration,
launcher_data: &LauncherData<D>,
) -> Result<()> {
let vanilla_dir = if !integration.custom_path.is_empty() {
let custom = PathBuf::from(&integration.custom_path);
if custom.exists() { Some(custom) } else { None }
} else {
get_vanilla_minecraft_dir().filter(|p| p.exists())
};

let vanilla_dir = match vanilla_dir {
Some(p) => p,
None => return Ok(()),
};

let links = [
("saves", integration.use_vanilla_saves),
("resourcepacks", integration.use_vanilla_resource_packs),
("shaderpacks", integration.use_vanilla_shader_packs),
];

for (folder, enabled) in links {
let target = game_dir.join(folder);
let source = vanilla_dir.join(folder);

if enabled && source.exists() {
if target.exists() {
if target.is_symlink() {
continue;
}
std::fs::remove_dir_all(&target).ok();
}

#[cfg(unix)]
std::os::unix::fs::symlink(&source, &target)?;

#[cfg(windows)]
std::os::windows::fs::symlink_dir(&source, &target)?;

launcher_data.log(&format!("Linked vanilla {} folder", folder));
} else if !enabled && target.is_symlink() {
fs::remove_file(&target).ok();
fs::create_dir_all(&target)?;
launcher_data.log(&format!("Unlinked vanilla {} folder", folder));
}
}

Ok(())
}

fn get_vanilla_minecraft_dir() -> Option<PathBuf> {
#[cfg(target_os = "windows")]
{
dirs::data_dir().map(|p| p.join(".minecraft"))
}
#[cfg(target_os = "macos")]
{
dirs::home_dir().map(|p| p.join("Library/Application Support/minecraft"))
}
#[cfg(target_os = "linux")]
{
dirs::home_dir().map(|p| p.join(".minecraft"))
}
}
7 changes: 6 additions & 1 deletion src/lib/main/settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {createEventDispatcher} from "svelte";
import GeneralSettings from "./GeneralSettings.svelte";
import PremiumSettings from "./PremiumSettings.svelte";
import VanillaIntegration from "./VanillaIntegration.svelte";
import SettingsContainer from "../../settings/SettingsContainer.svelte";
import Tabs from "../../settings/tab/Tabs.svelte";

Expand All @@ -17,7 +18,7 @@
on:hideSettings={() => dispatch('hide')}
>
<Tabs
tabs={["General", "Premium"]}
tabs={["General", "Minecraft", "Premium"]}
bind:activeTab={activeSettingsTab}
slot="tabs"
/>
Expand All @@ -26,6 +27,10 @@
<GeneralSettings
bind:options
/>
{:else if activeSettingsTab === "Minecraft"}
<VanillaIntegration
bind:options
/>
{:else if activeSettingsTab === "Premium"}
<PremiumSettings
{client}
Expand Down
Loading