Skip to content

Commit

Permalink
Merge pull request #3 from Hamster5295/dev
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
Hamster5295 authored Jan 6, 2024
2 parents 557c88f + 44458ad commit f3ee2d7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ This is the changelog of **Godo**, a version manager for [Godot Engine](https://
* `available` - Show the list of the available Godot Engine versions.
* `list` - List the installed Godot Engines.
* `run` - Run Godot Engine with specific version.
* Automatic installing, uninstalling and running features.
* Automatic installing, uninstalling and running features.

## [1.0.1] - 2024-1-6
### Fixed
* Fixed the error file path when installing
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "godo"
version = "0.1.0"
version = "0.1.1"
authors = ["Hamster5295 <hamster5295@163.com>"]
edition = "2021"
description = "A Version Manager for Godot Engine."
Expand Down
7 changes: 5 additions & 2 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ pub async fn download(client: &Client, file_name: String, url: String) -> String
});

utils::create_install_path();
let path = format!("{}/{}.zip", utils::INSTALL_PATH, file_name);
let path = utils::get_install_path()
.join(file_name + ".zip")
.to_str()
.unwrap()
.to_string();
let mut writer = io::BufWriter::new(
fs::OpenOptions::new()
.create(true)
Expand Down Expand Up @@ -337,7 +341,6 @@ pub async fn download(client: &Client, file_name: String, url: String) -> String
}

writer.flush().unwrap();

path
}

Expand Down
20 changes: 15 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use console::style;
use std::{cmp::Ordering, fs, path::Path};
use std::{
cmp::Ordering,
fs,
path::{Path, PathBuf},
};

use crate::version::{self, Version};

Expand All @@ -15,16 +19,22 @@ macro_rules! err {
};
}

pub fn get_install_path() -> PathBuf {
std::env::current_exe()
.unwrap()
.with_file_name(INSTALL_PATH)
}

pub fn create_install_path() {
fs::create_dir_all(INSTALL_PATH)
fs::create_dir_all(get_install_path())
.unwrap_or_else(|err| err!("Unable to create install directory: ", err.to_string()));
}

pub fn get_installed_dirs() -> Vec<String> {
create_install_path();

let mut installs = vec![];
for dir_result in fs::read_dir(INSTALL_PATH).unwrap() {
for dir_result in fs::read_dir(get_install_path()).unwrap() {
let dir = dir_result.unwrap();
let path = dir.path();
if path.is_dir() {
Expand All @@ -47,7 +57,7 @@ pub fn get_installed_versions() -> Vec<Version> {
pub fn get_executables(dir: String) -> Vec<String> {
let mut files = vec![];

for dir_result in fs::read_dir(Path::new(INSTALL_PATH).join(dir)).unwrap() {
for dir_result in fs::read_dir(get_install_path().join(dir)).unwrap() {
let dir = dir_result.unwrap();
let path = dir.path();
if path.is_file() {
Expand Down Expand Up @@ -144,6 +154,6 @@ where
}

pub fn uninstall_version(version: Version) {
fs::remove_dir_all(Path::new(INSTALL_PATH).join(version.dir_name()))
fs::remove_dir_all(get_install_path().join(version.dir_name()))
.unwrap_or_else(|err| err!("Error when uninstalling:", err.to_string()));
}

0 comments on commit f3ee2d7

Please sign in to comment.