Skip to content

Commit

Permalink
save updated addon after update
Browse files Browse the repository at this point in the history
  • Loading branch information
MR2011 committed Aug 16, 2020
1 parent f31e44e commit e93c8a8
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl StatefulTable {
}

pub fn get_selected(&self) -> Option<&TableItem> {
match self.state.selected() { Some(i) => self.items.get(i),
match self.state.selected() {
Some(i) => self.items.get(i),
None => None,
}
}
Expand Down Expand Up @@ -456,11 +457,13 @@ impl App {
let log_level;
let msg;
if let Err(err) =
CurseForgeAPI::download(&item.download_url, &save_path).and_then(
|_| AddonManager::add_to_db(&save_path, item.addon.clone()),
)
CurseForgeAPI::download(&item.download_url, &save_path)
.and_then(|_| {
AddonManager::add_to_db(&save_path, item.addon.clone())
})
{
msg = format!("Couldn't install {}.\n{}\n", &item.cells[0], err);
msg =
format!("Couldn't install {}.\n{}\n", &item.cells[0], err);
log_level = LogLevel::Error;
} else {
msg = format!("{} successfully installed.\n", &item.cells[0]);
Expand All @@ -479,7 +482,9 @@ impl App {
.and_then(|_| {
CurseForgeAPI::download(&item.download_url, &save_path)
})
.and_then(|_| AddonManager::add_to_db(&save_path, item.clone()))
.and_then(|_| {
AddonManager::add_to_db(&save_path, item.clone())
})
{
msg = format!(
"Couldn't update {}.\n{}\n",
Expand All @@ -488,7 +493,10 @@ impl App {
);
log_level = LogLevel::Error;
} else {
msg = format!("{} successfully updated.\n", item.name.clone());
msg = format!(
"{} successfully updated.\n",
item.name.clone()
);
log_level = LogLevel::Info;
}
}
Expand All @@ -499,6 +507,11 @@ impl App {
pub fn update_addon(&mut self, save_path: String) {
if self.tab_index == Tab::Installed {
let item = self.installed_table.get_selected().unwrap();
let update = self
.updates
.iter()
.find(|&u| u.addon_id == item.addon.addon_id)
.unwrap();
let name = &item.cells[1];
let msg;
let log_level;
Expand All @@ -507,14 +520,15 @@ impl App {
CurseForgeAPI::download(&item.download_url, &save_path)
})
.and_then(|_| {
AddonManager::add_to_db(&save_path, item.addon.clone())
AddonManager::add_to_db(&save_path, update.clone())
})
{
msg = format!("Couldn't update {}.\n{}\n", name, err);
log_level = LogLevel::Error;
} else {
msg = format!("{} successfully updated.\n", name);
log_level = LogLevel::Info;
self.load_installed_addons();
}
self.log(msg, log_level);
}
Expand All @@ -535,7 +549,10 @@ impl App {
log_level = LogLevel::Info;
}
Err(err) => {
msg = format!("Couldn't delete {}.\n{}\n", &item.cells[1], err);
msg = format!(
"Couldn't delete {}.\n{}\n",
&item.cells[1], err
);
log_level = LogLevel::Error;
}
}
Expand Down

0 comments on commit e93c8a8

Please sign in to comment.