Skip to content

Commit 037cc43

Browse files
fix windows update error
1 parent 8d3b97b commit 037cc43

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

command/src/commands/command.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ pub fn apt(name: &str) -> io::Result<(usize,String)>{
342342

343343
// apt -update xxx
344344
pub fn update_new(version: &str) -> io::Result<(usize,String)>{
345-
if version.is_empty(){
346-
return Ok(missing_pattern());
347-
}
345+
348346
match update(&version) {
349347
Ok(_) => {
350348
let res = format!("Successfully Update version {}",version);
@@ -365,7 +363,7 @@ pub fn update_lastest() -> Result<(usize,String),std::io::Error>{
365363
update_last().await;
366364
});
367365

368-
return Ok((STATUE_CODE,"update over!".to_string()));
366+
return Ok((STATUE_CODE,"Successfully Update lastest version!".to_string()));
369367
}
370368

371369
use tar::Archive;

command/src/commands/download.rs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ pub fn update(version: &str) -> std::io::Result<()>{
7474
let _release_linux = format!("https://github.com/zhangzijie-pro/Tiks/releases/download/{}/tiks",version);
7575
let _release_window = format!("https://github.com/zhangzijie-pro/Tiks/releases/download/{}/tiks.exe",version);
7676

77-
#[cfg(target_os="linux")]
78-
let app_linux = _get_linux_dir();
79-
task::block_on(async {
80-
update_to(&_release_linux, app_linux);
81-
});
82-
#[cfg(target_os="windows")]{
83-
let app_window = _get_window_dir();
84-
task::block_on(async {
85-
update_to(&_release_window, app_window);
86-
});
77+
if cfg!(target_os = "linux") | cfg!(target_os="mac"){
78+
let app_linux = get_linux_dir();
79+
task::block_on(async {
80+
update_to(&_release_linux, app_linux).await;
81+
});
82+
}
83+
84+
if cfg!(target_os="windows"){
85+
let app_window = get_window_dir();
86+
task::block_on(async {
87+
update_to(&_release_window, app_window).await;
88+
});
8789
}
8890

8991
Ok(())
@@ -93,19 +95,24 @@ pub fn update(version: &str) -> std::io::Result<()>{
9395
pub async fn update_last() -> Result<(), Box<dyn std::error::Error>>{
9496
let client = Client::new();
9597

96-
#[cfg(target_os="linux")]
97-
let response = client.get(_GITHUB_RELEASE_LINUX).send().await.expect("Error: update error");
98-
let app = _get_linux_dir();
99-
let mut file = File::create(app).expect("Can't create file : tiks");
100-
101-
#[cfg(target_os="windows")]{
102-
let response = client.get(_GITHUB_RELEASE_WINDOW).send().await.expect("Error: update error");
103-
let app = _get_window_dir();
104-
let mut file = File::create(app).expect("Can't create file : tiks");
98+
if cfg!(target_os = "linux") | cfg!(target_os="mac"){
99+
let response = client.get(_GITHUB_RELEASE_LINUX).send().await.expect("Error: update error");
100+
let app = get_linux_dir();
101+
let mut file = File::create(app).expect("Can't create file : tiks");
102+
103+
let byte = response.bytes().await.unwrap();
104+
let _ = file.write_all(&byte);
105+
}
106+
107+
if cfg!(target_os="windows"){
108+
let response = client.get(_GITHUB_RELEASE_WINDOW).send().await.expect("Error: update error");
109+
let app = get_window_dir();
110+
let mut file = File::create(app).expect("Can't create file : tiks");
111+
112+
let byte = response.bytes().await.unwrap();
113+
let _ = file.write_all(&byte);
105114
}
106115

107-
let byte = response.bytes().await.unwrap();
108-
let _ = file.write_all(&byte);
109116
Ok(())
110117
}
111118

@@ -123,15 +130,15 @@ async fn update_to(url: &str,filename: PathBuf) -> Result<(), Box<dyn std::error
123130
}
124131

125132

126-
fn _get_window_dir() -> PathBuf{
133+
fn get_window_dir() -> PathBuf{
127134
let home = dirs::home_dir().unwrap();
128135
let app_dir = home.join(".Tiks");
129136
let app_window = app_dir.join("bin").join("tiks.exe");
130137

131138
app_window
132139
}
133140

134-
fn _get_linux_dir() -> PathBuf{
141+
fn get_linux_dir() -> PathBuf{
135142
let home = dirs::home_dir().unwrap();
136143
let app_dir = home.join(".Tiks");
137144
let app_linux = app_dir.join("bin").join("tiks");

0 commit comments

Comments
 (0)