You've already forked AstralRinth
forked from didirus/AstralRinth
Bug fixes round 3 (#298)
* fixed bugs * title case * bugs; ioerror * reset breadcrumbs * more fixes * more fixes * scrolling bug * more fixes * more fixes * clippy * canonicalize fix * fixed requested changes * removed debouncer update
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::event::{
|
||||
emit::{emit_command, emit_warning},
|
||||
CommandPayload,
|
||||
use crate::{
|
||||
event::{
|
||||
emit::{emit_command, emit_warning},
|
||||
CommandPayload,
|
||||
},
|
||||
util::io,
|
||||
};
|
||||
|
||||
/// Handles external functions (such as through URL deep linkage)
|
||||
@@ -46,7 +49,7 @@ pub async fn parse_command(
|
||||
} else {
|
||||
// We assume anything else is a filepath to an .mrpack file
|
||||
let path = PathBuf::from(command_string);
|
||||
let path = path.canonicalize()?;
|
||||
let path = io::canonicalize(path)?;
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == "mrpack" {
|
||||
return Ok(CommandPayload::RunMRPack { path });
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::path::PathBuf;
|
||||
|
||||
use crate::event::emit::{emit_loading, init_loading};
|
||||
use crate::util::fetch::{fetch_advanced, fetch_json};
|
||||
use crate::util::io;
|
||||
use crate::util::jre::extract_java_majorminor_version;
|
||||
use crate::{
|
||||
state::JavaGlobals,
|
||||
@@ -114,7 +115,7 @@ pub async fn auto_install_java(java_version: u32) -> crate::Result<PathBuf> {
|
||||
let path = state.directories.java_versions_dir();
|
||||
|
||||
if path.exists() {
|
||||
tokio::fs::remove_dir_all(&path).await?;
|
||||
io::remove_dir_all(&path).await?;
|
||||
}
|
||||
|
||||
let mut archive = zip::ZipArchive::new(std::io::Cursor::new(file))
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::State;
|
||||
use crate::{
|
||||
util::io::{self, IOError},
|
||||
State,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::fs::read_to_string;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Logs {
|
||||
@@ -36,8 +38,11 @@ pub async fn get_logs(
|
||||
let logs_folder = state.directories.profile_logs_dir(profile_uuid);
|
||||
let mut logs = Vec::new();
|
||||
if logs_folder.exists() {
|
||||
for entry in std::fs::read_dir(logs_folder)? {
|
||||
let entry = entry?;
|
||||
for entry in std::fs::read_dir(&logs_folder)
|
||||
.map_err(|e| IOError::with_path(e, &logs_folder))?
|
||||
{
|
||||
let entry =
|
||||
entry.map_err(|e| IOError::with_path(e, &logs_folder))?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
if let Some(datetime_string) = path.file_name() {
|
||||
@@ -79,21 +84,21 @@ pub async fn get_output_by_datetime(
|
||||
) -> crate::Result<String> {
|
||||
let state = State::get().await?;
|
||||
let logs_folder = state.directories.profile_logs_dir(profile_uuid);
|
||||
Ok(
|
||||
read_to_string(logs_folder.join(datetime_string).join("stdout.log"))
|
||||
.await?,
|
||||
)
|
||||
let path = logs_folder.join(datetime_string).join("stdout.log");
|
||||
Ok(io::read_to_string(&path).await?)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn delete_logs(profile_uuid: uuid::Uuid) -> crate::Result<()> {
|
||||
let state = State::get().await?;
|
||||
let logs_folder = state.directories.profile_logs_dir(profile_uuid);
|
||||
for entry in std::fs::read_dir(logs_folder)? {
|
||||
let entry = entry?;
|
||||
for entry in std::fs::read_dir(&logs_folder)
|
||||
.map_err(|e| IOError::with_path(e, &logs_folder))?
|
||||
{
|
||||
let entry = entry.map_err(|e| IOError::with_path(e, &logs_folder))?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
std::fs::remove_dir_all(path)?;
|
||||
io::remove_dir_all(&path).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -106,6 +111,7 @@ pub async fn delete_logs_by_datetime(
|
||||
) -> crate::Result<()> {
|
||||
let state = State::get().await?;
|
||||
let logs_folder = state.directories.profile_logs_dir(profile_uuid);
|
||||
std::fs::remove_dir_all(logs_folder.join(datetime_string))?;
|
||||
let path = logs_folder.join(datetime_string);
|
||||
io::remove_dir_all(&path).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -29,7 +29,10 @@ pub mod prelude {
|
||||
profile::{self, Profile},
|
||||
profile_create, settings,
|
||||
state::JavaGlobals,
|
||||
util::jre::JavaVersion,
|
||||
util::{
|
||||
io::{canonicalize, IOError},
|
||||
jre::JavaVersion,
|
||||
},
|
||||
State,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::state::{LinkedData, ModrinthProject, ModrinthVersion, SideType};
|
||||
use crate::util::fetch::{
|
||||
fetch, fetch_advanced, fetch_json, write_cached_icon,
|
||||
};
|
||||
use crate::util::io;
|
||||
use crate::State;
|
||||
|
||||
use reqwest::Method;
|
||||
@@ -13,7 +14,6 @@ use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use tokio::fs;
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -263,7 +263,7 @@ pub async fn generate_pack_from_file(
|
||||
path: PathBuf,
|
||||
profile: PathBuf,
|
||||
) -> crate::Result<CreatePackDescription> {
|
||||
let file = fs::read(&path).await?;
|
||||
let file = io::read(&path).await?;
|
||||
Ok(CreatePackDescription {
|
||||
file: bytes::Bytes::from(file),
|
||||
icon: None,
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::state::MinecraftChild;
|
||||
use crate::{state::MinecraftChild, util::io::IOError};
|
||||
pub use crate::{
|
||||
state::{
|
||||
Hooks, JavaSettings, MemorySettings, Profile, Settings, WindowSize,
|
||||
@@ -121,7 +121,13 @@ pub async fn wait_for_by_uuid(uuid: &Uuid) -> crate::Result<()> {
|
||||
// Kill a running child process directly, and wait for it to be killed
|
||||
#[tracing::instrument(skip(running))]
|
||||
pub async fn kill(running: &mut MinecraftChild) -> crate::Result<()> {
|
||||
running.current_child.write().await.kill().await?;
|
||||
running
|
||||
.current_child
|
||||
.write()
|
||||
.await
|
||||
.kill()
|
||||
.await
|
||||
.map_err(IOError::from)?;
|
||||
wait_for(running).await
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::pack::install_from::{
|
||||
use crate::prelude::JavaVersion;
|
||||
use crate::state::ProjectMetadata;
|
||||
|
||||
use crate::util::io::{self, IOError};
|
||||
use crate::{
|
||||
auth::{self, refresh},
|
||||
event::{emit::emit_profile, ProfilePayloadType},
|
||||
@@ -27,11 +28,7 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::{
|
||||
fs::{self, File},
|
||||
process::Command,
|
||||
sync::RwLock,
|
||||
};
|
||||
use tokio::{fs::File, process::Command, sync::RwLock};
|
||||
|
||||
/// Remove a profile
|
||||
#[tracing::instrument]
|
||||
@@ -110,8 +107,8 @@ pub async fn edit_icon(
|
||||
) -> crate::Result<()> {
|
||||
let state = State::get().await?;
|
||||
|
||||
if let Some(icon) = icon_path {
|
||||
let bytes = tokio::fs::read(icon).await?;
|
||||
let res = if let Some(icon) = icon_path {
|
||||
let bytes = io::read(icon).await?;
|
||||
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
@@ -133,8 +130,6 @@ pub async fn edit_icon(
|
||||
ProfilePayloadType::Edited,
|
||||
)
|
||||
.await?;
|
||||
State::sync().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
None => Err(crate::ErrorKind::UnmanagedProfileError(
|
||||
@@ -151,7 +146,9 @@ pub async fn edit_icon(
|
||||
State::sync().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
State::sync().await?;
|
||||
res
|
||||
}
|
||||
|
||||
// Gets the optimal JRE key for the given profile, using Daedalus
|
||||
@@ -416,7 +413,7 @@ pub async fn add_project_from_path(
|
||||
project_type: Option<String>,
|
||||
) -> crate::Result<PathBuf> {
|
||||
if let Some(profile) = get(profile_path, None).await? {
|
||||
let file = fs::read(path).await?;
|
||||
let file = io::read(path).await?;
|
||||
let file_name = path
|
||||
.file_name()
|
||||
.unwrap_or_default()
|
||||
@@ -525,7 +522,9 @@ pub async fn export_mrpack(
|
||||
|
||||
let profile_base_path = &profile.path;
|
||||
|
||||
let mut file = File::create(export_path).await?;
|
||||
let mut file = File::create(&export_path)
|
||||
.await
|
||||
.map_err(|e| IOError::with_path(e, &export_path))?;
|
||||
let mut writer = ZipFileWriter::new(&mut file);
|
||||
|
||||
// Create mrpack json configuration file
|
||||
@@ -592,9 +591,13 @@ pub async fn export_mrpack(
|
||||
|
||||
// File is not in the config file, add it to the .mrpack zip
|
||||
if path.is_file() {
|
||||
let mut file = File::open(&path).await?;
|
||||
let mut file = File::open(&path)
|
||||
.await
|
||||
.map_err(|e| IOError::with_path(e, &path))?;
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data).await?;
|
||||
file.read_to_end(&mut data)
|
||||
.await
|
||||
.map_err(|e| IOError::with_path(e, &path))?;
|
||||
let builder = ZipEntryBuilder::new(
|
||||
format!("overrides/{relative_path}"),
|
||||
Compression::Deflate,
|
||||
@@ -639,13 +642,21 @@ pub async fn get_potential_override_folders(
|
||||
let mrpack_files = get_modrinth_pack_list(&mrpack);
|
||||
|
||||
let mut path_list: Vec<PathBuf> = Vec::new();
|
||||
let mut read_dir = fs::read_dir(&profile_path).await?;
|
||||
while let Some(entry) = read_dir.next_entry().await? {
|
||||
let mut read_dir = io::read_dir(&profile_path).await?;
|
||||
while let Some(entry) = read_dir
|
||||
.next_entry()
|
||||
.await
|
||||
.map_err(|e| IOError::with_path(e, &profile_path))?
|
||||
{
|
||||
let path: PathBuf = entry.path();
|
||||
if path.is_dir() {
|
||||
// Two layers of files/folders if its a folder
|
||||
let mut read_dir = fs::read_dir(&path).await?;
|
||||
while let Some(entry) = read_dir.next_entry().await? {
|
||||
let mut read_dir = io::read_dir(&path).await?;
|
||||
while let Some(entry) = read_dir
|
||||
.next_entry()
|
||||
.await
|
||||
.map_err(|e| IOError::with_path(e, &profile_path))?
|
||||
{
|
||||
let path: PathBuf = entry.path();
|
||||
let name = path.strip_prefix(&profile_path)?.to_path_buf();
|
||||
if !mrpack_files.contains(&name.to_string_lossy().to_string()) {
|
||||
@@ -712,9 +723,11 @@ pub async fn run_credentials(
|
||||
let result = Command::new(command)
|
||||
.args(&cmd.collect::<Vec<&str>>())
|
||||
.current_dir(path)
|
||||
.spawn()?
|
||||
.spawn()
|
||||
.map_err(|e| IOError::with_path(e, path))?
|
||||
.wait()
|
||||
.await?;
|
||||
.await
|
||||
.map_err(IOError::from)?;
|
||||
|
||||
if !result.success() {
|
||||
return Err(crate::ErrorKind::LauncherError(format!(
|
||||
@@ -925,8 +938,12 @@ pub async fn build_folder(
|
||||
path: &Path,
|
||||
path_list: &mut Vec<PathBuf>,
|
||||
) -> crate::Result<()> {
|
||||
let mut read_dir = fs::read_dir(path).await?;
|
||||
while let Some(entry) = read_dir.next_entry().await? {
|
||||
let mut read_dir = io::read_dir(path).await?;
|
||||
while let Some(entry) = read_dir
|
||||
.next_entry()
|
||||
.await
|
||||
.map_err(|e| IOError::with_path(e, path))?
|
||||
{
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
build_folder(&path, path_list).await?;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Theseus profile management interface
|
||||
use crate::state::LinkedData;
|
||||
use crate::util::io::{self, canonicalize};
|
||||
use crate::{
|
||||
event::{emit::emit_profile, ProfilePayloadType},
|
||||
prelude::ModLoader,
|
||||
@@ -9,11 +10,9 @@ pub use crate::{
|
||||
State,
|
||||
};
|
||||
use daedalus::modded::LoaderVersion;
|
||||
use dunce::canonicalize;
|
||||
use futures::prelude::*;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use tokio::fs;
|
||||
use tokio_stream::wrappers::ReadDirStream;
|
||||
use tracing::{info, trace};
|
||||
use uuid::Uuid;
|
||||
@@ -48,7 +47,7 @@ pub async fn profile_create(
|
||||
.into());
|
||||
}
|
||||
|
||||
if ReadDirStream::new(fs::read_dir(&path).await?)
|
||||
if ReadDirStream::new(io::read_dir(&path).await?)
|
||||
.next()
|
||||
.await
|
||||
.is_some()
|
||||
@@ -56,7 +55,7 @@ pub async fn profile_create(
|
||||
return Err(ProfileCreationError::NotEmptyFolder.into());
|
||||
}
|
||||
} else {
|
||||
fs::create_dir_all(&path).await?;
|
||||
io::create_dir_all(&path).await?;
|
||||
}
|
||||
|
||||
info!(
|
||||
@@ -80,7 +79,7 @@ pub async fn profile_create(
|
||||
Profile::new(uuid, name, game_version, path.clone()).await?;
|
||||
let result = async {
|
||||
if let Some(ref icon) = icon {
|
||||
let bytes = tokio::fs::read(icon).await?;
|
||||
let bytes = io::read(icon).await?;
|
||||
profile
|
||||
.set_icon(
|
||||
&state.directories.caches_dir(),
|
||||
|
||||
Reference in New Issue
Block a user