Skip to content

Commit

Permalink
add self-update subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
8LWXpg committed Dec 23, 2024
1 parent 4da5de3 commit 5223771
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [0.11.0]

### Added

- Added `self-update` subcommand.

## [0.10.0]

### Changed
Expand Down
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 = "ptr"
version = "0.10.0"
version = "0.11.0"
edition = "2021"

[dependencies]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ Options:
Usage: ptr.exe restart
```

### Self Update

```
Usage: ptr.exe self-update
```

### Completion

```
Expand Down
10 changes: 4 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub fn self_update() -> Result<()> {
}
let res: ApiResponse = res.json()?;
let tag = res.tag_name;
if tag == current_version {
if tag == format!("v{current_version}") {
up_to_date!("ptr", current_version);
return Ok(());
}
Expand All @@ -253,17 +253,15 @@ pub fn self_update() -> Result<()> {
let res = Client::new().get(url).send()?;

let file_path = PLUGIN_PATH.join(name);
// {
// let mut file = File::create(&file_path)?;
File::create(&file_path)?.write_all(&res.bytes()?)?;
// }

// extract and replace self
let mut archive = ZipArchive::new(File::open(file_path)?)?;
// extract and self replace
let mut archive = ZipArchive::new(File::open(&file_path)?)?;
let out_path = PLUGIN_PATH.join("ptr.exe");
let mut out_file = File::create(&out_path)?;
io::copy(&mut archive.by_name("ptr.exe")?, &mut out_file)?;
self_replace::self_replace(&out_path)?;
fs::remove_file(&file_path)?;
fs::remove_file(&out_path)?;
add!("ptr", tag);
Ok(())
Expand Down

0 comments on commit 5223771

Please sign in to comment.