You've already forked AstralRinth
forked from didirus/AstralRinth
Profile imports (#348)
* temporary switch * draft; working unmanaged + modrinth * working update * added checkerg * fixed io merge issue * Added api handling * tidying up * reverted playground changes * fixed js issue * fixed merge issues
This commit is contained in:
70
theseus_gui/src-tauri/src/api/import.rs
Normal file
70
theseus_gui/src-tauri/src/api/import.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::api::Result;
|
||||
use theseus::pack::import::ImportLauncherType;
|
||||
|
||||
use theseus::pack::import;
|
||||
use theseus::prelude::ProfilePathId;
|
||||
|
||||
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
||||
tauri::plugin::Builder::new("import")
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
import_get_importable_instances,
|
||||
import_import_instance,
|
||||
import_is_valid_importable_instance,
|
||||
import_get_default_launcher_path,
|
||||
])
|
||||
.build()
|
||||
}
|
||||
|
||||
/// Gets a list of importable instances from a launcher type and base path
|
||||
/// eg: get_importable_instances(ImportLauncherType::MultiMC, PathBuf::from("C:/MultiMC"))
|
||||
/// returns ["Instance 1", "Instance 2"]
|
||||
#[tauri::command]
|
||||
pub async fn import_get_importable_instances(
|
||||
launcher_type: ImportLauncherType,
|
||||
base_path: PathBuf,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(import::get_importable_instances(launcher_type, base_path).await?)
|
||||
}
|
||||
|
||||
/// Import an instance from a launcher type and base path
|
||||
/// eg: import_instance(ImportLauncherType::MultiMC, PathBuf::from("C:/MultiMC"), "Instance 1")
|
||||
#[tauri::command]
|
||||
pub async fn import_import_instance(
|
||||
profile_path: ProfilePathId,
|
||||
launcher_type: ImportLauncherType,
|
||||
base_path: PathBuf,
|
||||
instance_folder: String,
|
||||
) -> Result<()> {
|
||||
import::import_instance(
|
||||
profile_path,
|
||||
launcher_type,
|
||||
base_path,
|
||||
instance_folder,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks if this instance is valid for importing, given a certain launcher type
|
||||
/// eg: is_valid_importable_instance(PathBuf::from("C:/MultiMC/Instance 1"), ImportLauncherType::MultiMC)
|
||||
#[tauri::command]
|
||||
pub async fn import_is_valid_importable_instance(
|
||||
instance_folder: PathBuf,
|
||||
launcher_type: ImportLauncherType,
|
||||
) -> Result<bool> {
|
||||
Ok(
|
||||
import::is_valid_importable_instance(instance_folder, launcher_type)
|
||||
.await,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the default path for the given launcher type
|
||||
/// None if it can't be found or doesn't exist
|
||||
#[tauri::command]
|
||||
pub async fn import_get_default_launcher_path(
|
||||
launcher_type: ImportLauncherType,
|
||||
) -> Result<Option<PathBuf>> {
|
||||
Ok(import::get_default_launcher_path(launcher_type))
|
||||
}
|
||||
@@ -3,6 +3,7 @@ use serde::{Serialize, Serializer};
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod auth;
|
||||
pub mod import;
|
||||
pub mod jre;
|
||||
pub mod logs;
|
||||
pub mod metadata;
|
||||
|
||||
@@ -2,8 +2,8 @@ use crate::api::Result;
|
||||
|
||||
use theseus::{
|
||||
pack::{
|
||||
install::install_pack,
|
||||
install_from::{CreatePackLocation, CreatePackProfile},
|
||||
install_mrpack::install_zipped_mrpack,
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
@@ -22,7 +22,7 @@ pub async fn pack_install(
|
||||
location: CreatePackLocation,
|
||||
profile: ProfilePathId,
|
||||
) -> Result<ProfilePathId> {
|
||||
Ok(install_pack(location, profile).await?)
|
||||
Ok(install_zipped_mrpack(location, profile).await?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -118,6 +118,7 @@ fn main() {
|
||||
}
|
||||
let builder = builder
|
||||
.plugin(api::auth::init())
|
||||
.plugin(api::import::init())
|
||||
.plugin(api::logs::init())
|
||||
.plugin(api::jre::init())
|
||||
.plugin(api::metadata::init())
|
||||
|
||||
61
theseus_gui/src/helpers/import.js
Normal file
61
theseus_gui/src/helpers/import.js
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* All theseus API calls return serialized values (both return values and errors);
|
||||
* So, for example, addDefaultInstance creates a blank Profile object, where the Rust struct is serialized,
|
||||
* and deserialized into a usable JS object.
|
||||
*/
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { create } from './profile'
|
||||
|
||||
/*
|
||||
API for importing instances from other launchers
|
||||
launcherType can be one of the following:
|
||||
- MultiMC
|
||||
- GDLauncher
|
||||
- ATLauncher
|
||||
- Curseforge
|
||||
- PrismLauncher
|
||||
- Unknown (shouldn't be used, but is used internally if the launcher type isn't recognized)
|
||||
|
||||
For each launcher type, we can get a guess of the default path for the launcher, and a list of importable instances
|
||||
For most launchers, this will be the application's data directory, with two exceptions:
|
||||
- MultiMC: this goes to the app directory (wherever the app is)
|
||||
- Curseforge: this goes to the 'minecraft' subdirectory of the data directory, as Curseforge has multiple games
|
||||
|
||||
*/
|
||||
|
||||
/// Gets a list of importable instances from a launcher type and base path
|
||||
/// eg: get_importable_instances("MultiMC", "C:/MultiMC")
|
||||
/// returns ["Instance 1", "Instance 2"]
|
||||
export async function get_importable_instances(launcherType, basePath) {
|
||||
return await invoke('plugin:import|import_get_importable_instances', { launcherType, basePath })
|
||||
}
|
||||
|
||||
/// Import an instance from a launcher type and base path
|
||||
/// eg: import_instance("profile-name-to-go-to", "MultiMC", "C:/MultiMC", "Instance 1")
|
||||
export async function import_instance(launcherType, basePath, instanceFolder) {
|
||||
// create a basic, empty instance (most properties will be filled in by the import process)
|
||||
const profilePath = await create(instanceFolder, '1.19.4', 'vanilla', 'latest', null)
|
||||
|
||||
return await invoke('plugin:import|import_import_instance', {
|
||||
profilePath,
|
||||
launcherType,
|
||||
basePath,
|
||||
instanceFolder,
|
||||
})
|
||||
}
|
||||
|
||||
/// Checks if this instance is valid for importing, given a certain launcher type
|
||||
/// eg: is_valid_importable_instance("C:/MultiMC/Instance 1", "MultiMC")
|
||||
export async function is_valid_importable_instance(instanceFolder, launcherType) {
|
||||
return await invoke('plugin:import|import_is_valid_importable_instance', {
|
||||
instanceFolder,
|
||||
launcherType,
|
||||
})
|
||||
}
|
||||
|
||||
/// Gets the default path for the given launcher type
|
||||
/// null if it can't be found or doesn't exist
|
||||
/// eg: get_default_launcher_path("MultiMC")
|
||||
export async function get_default_launcher_path(launcherType) {
|
||||
return await invoke('plugin:import|import_get_default_launcher_path', { launcherType })
|
||||
}
|
||||
Reference in New Issue
Block a user