summaryrefslogtreecommitdiffstats
path: root/src/launcher.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/launcher.rs')
-rw-r--r--src/launcher.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/launcher.rs b/src/launcher.rs
index 27fdf9c..82abef0 100644
--- a/src/launcher.rs
+++ b/src/launcher.rs
@@ -1,5 +1,5 @@
use std::{collections::{BTreeMap, HashMap}, error::Error, fmt::Write, io::ErrorKind};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use chrono::{DateTime, Utc};
use serde::{Serialize, Deserialize};
@@ -34,11 +34,13 @@ struct RemoteVersionList {
}
impl RemoteVersionList {
- async fn new(home: &str) -> Result<RemoteVersionList, Box<dyn Error>> {
+ async fn new(home: impl AsRef<Path>) -> Result<RemoteVersionList, Box<dyn Error>> {
let text = reqwest::get(URL_VERSION_MANIFEST).await?.error_for_status()?.text().await?;
let manifest: VersionManifest = serde_json::from_str(text.as_str())?;
- let fname = format!("{home}/.remote.json");
+ let mut fname = home.as_ref().to_path_buf();
+ fname.push(".version.json");
+
let index: RemoteVersionIndex = match tokio::fs::read_to_string(fname).await {
Ok(s) => serde_json::from_str(s.as_str())?,
Err(e) => {
@@ -71,11 +73,13 @@ impl LocalVersionList {
serde_json::from_str(tokio::fs::read_to_string(path).await?)?;
}
- async fn load_versions(home: &str, skip: impl Fn(&str) -> bool) -> Result<LocalVersionList, Box<dyn Error>> {
+ async fn load_versions(home: impl AsRef<Path>, skip: impl Fn(&str) -> bool) -> Result<LocalVersionList, Box<dyn Error>> {
let mut rd = tokio::fs::read_dir(home).await?;
let versions = BTreeMap::new();
while let Some(ent) = rd.next_entry().await? {
+ if !ent.file_type().await?.is_dir() { continue; }
+
// when the code is fugly
let path = match ent.file_name().to_str() {
Some(s) => {
@@ -124,7 +128,7 @@ struct VersionList {
}
impl VersionList {
- pub async fn online(home: &str) -> Result<VersionList, Box<dyn Error>> {
+ pub async fn online(home: impl AsRef<Path>) -> Result<VersionList, Box<dyn Error>> {
let remote = RemoteVersionList::new(home).await?;
let local = LocalVersionList::load_versions(home, |s| remote.versions.contains_key(s)).await?;
@@ -135,7 +139,7 @@ impl VersionList {
})
}
- pub async fn offline(home: &str) -> Result<VersionList, Box<dyn Error>> {
+ pub async fn offline(home: impl AsRef<Path>) -> Result<VersionList, Box<dyn Error>> {
let local = LocalVersionList::load_versions(home, |_| false).await?;
Ok(VersionList {