feat: added support to the new wishes url cache location

This commit is contained in:
Observer KRypt0n_ 2023-07-14 08:20:21 +02:00
parent 76103af95d
commit ee5ab23956
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
3 changed files with 38 additions and 10 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Added support to the new wishes url cache location
### Fixed
- Fixed telemetry disabling

View file

@ -104,6 +104,12 @@ impl SimpleComponent for AboutDialog {
set_release_notes_version: &APP_VERSION,
set_release_notes: &[
"<p>Added</p>",
"<ul>",
"<li>Added support to the new wishes url cache location</li>",
"</ul>",
"<p>Fixed</p>",
"<ul>",

View file

@ -651,19 +651,28 @@ impl SimpleComponent for App {
let web_cache = config.game.path.for_edition(config.launcher.edition)
.join(config.launcher.edition.data_folder())
.join("webCaches/Cache/Cache_Data/data_2");
.join("webCaches");
if !web_cache.exists() {
tracing::error!("Couldn't find wishes URL: cache file doesn't exist");
// Find newest cache folder
let mut web_cache_id = None;
sender.input(AppMsg::Toast {
title: tr("wish-url-search-failed"),
description: None
});
if let Ok(entries) = web_cache.read_dir() {
for entry in entries.flatten() {
if entry.path().is_dir() &&
entry.file_name().to_string_lossy().trim_matches(|c| "0123456789.".contains(c)).is_empty() &&
Some(entry.file_name()) > web_cache_id
{
web_cache_id = Some(entry.file_name());
}
}
}
else {
match std::fs::read(&web_cache) {
if let Some(web_cache_id) = web_cache_id {
let web_cache = web_cache
.join(web_cache_id)
.join("Cache/Cache_Data/data_2");
match std::fs::read(web_cache) {
Ok(web_cache) => {
let web_cache = String::from_utf8_lossy(&web_cache);
@ -674,7 +683,7 @@ impl SimpleComponent for App {
if let Err(err) = open::that(format!("{}#/log", &url[url_begin_pos..url_end_pos])) {
tracing::error!("Failed to open wishes URL: {err}");
sender.input(AppMsg::Toast {
title: tr("wish-url-opening-error"),
description: Some(err.to_string())
@ -702,6 +711,15 @@ impl SimpleComponent for App {
}
}
}
else {
tracing::error!("Couldn't find wishes URL: cache file doesn't exist");
sender.input(AppMsg::Toast {
title: tr("wish-url-search-failed"),
description: None
});
}
}));
})));