mirror of
https://github.com/storytold/craft-launcher.git
synced 2026-11-28 13:58:17 -08:00
fix: pass fmt and clippy, tighten fallbacks and Windows icon packaging
- cargo fmt, and clippy::question_mark in feed.rs (the CI gate failed on both). - screenshots: a picture-specific answer from the GitHub fallback is kept instead of the primary network failure, so one unpublished picture no longer skips the rest; the web build now tries the fallback too. - build.rs: track ARTCRAFT_CATALOG_DIR's contents with rerun-if-changed. - package.ps1: reuse the build-verified catalog and icons from artcraft-catalog-cache (works offline), read apps independent of key order and indentation, check each icon's SHA-256, and stop overwriting $line, which New-InstallerArt later uses as a pen colour. Drop the BOM the PR added.
This commit is contained in:
1 parent
5c37aade72
commit
7dd4ee6016
8 files changed
+76
-35
No files matched your search
@@ -147,7 +147,7 @@ impl WebBackend {
|
||||
for shot in details.shots {
|
||||
let result = match (&offline, details.screenshot_url(shot.key)) {
|
||||
(Some(why), _) => Err(why.clone()),
|
||||
(None, Some(url)) => picture(&url).await.map_err(|failure| match failure {
|
||||
(None, Some(url)) => picture_or_fallback(details, shot.key, &url).await.map_err(|failure| match failure {
|
||||
PictureError::Network(why) => {
|
||||
offline = Some(why.clone());
|
||||
why
|
||||
@@ -207,6 +207,21 @@ impl WebBackend {
|
||||
}
|
||||
}
|
||||
|
||||
/// The picture at `url` (getartcraft.com), or else the same picture from the GitHub fallback. A
|
||||
/// picture-specific answer from the fallback is kept, so it doesn't read as a network failure.
|
||||
async fn picture_or_fallback(details: &AppDetails, key: &str, url: &str) -> Result<Vec<u8>, PictureError> {
|
||||
let primary = match picture(url).await {
|
||||
Ok(bytes) => return Ok(bytes),
|
||||
Err(primary) => primary,
|
||||
};
|
||||
let Some(fallback) = details.screenshot_fallback_url(key) else { return Err(primary) };
|
||||
match picture(&fallback).await {
|
||||
Ok(bytes) => Ok(bytes),
|
||||
Err(fallback @ PictureError::Picture(_)) => Err(fallback),
|
||||
Err(PictureError::Network(_)) => Err(primary),
|
||||
}
|
||||
}
|
||||
|
||||
/// Why a picture couldn't be had.
|
||||
enum PictureError {
|
||||
/// This picture only: it isn't published, or what came back isn't a picture.
|
||||
|
||||
@@ -197,9 +197,7 @@ fn load_verified_icon(agent: &ureq::Agent, cache: &Path, app: &App) -> Result<Ve
|
||||
if let Ok(override_dir) = env::var("ARTCRAFT_CATALOG_DIR")
|
||||
&& !override_dir.trim().is_empty()
|
||||
{
|
||||
let candidate = PathBuf::from(override_dir)
|
||||
.join("launcher-app-icons")
|
||||
.join(format!("{}-{}.png", app.id, app.icon_sha256));
|
||||
let candidate = PathBuf::from(override_dir).join("launcher-app-icons").join(format!("{}-{}.png", app.id, app.icon_sha256));
|
||||
if let Ok(bytes) = fs::read(&candidate)
|
||||
&& sha256_hex(&bytes) == app.icon_sha256
|
||||
{
|
||||
@@ -220,6 +218,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
println!("cargo:rerun-if-changed=assets/launcher-catalog-public-key.pem");
|
||||
println!("cargo:rerun-if-env-changed=ARTCRAFT_CATALOG_DIR");
|
||||
println!("cargo:rerun-if-env-changed=ARTCRAFT_CATALOG_CACHE_DIR");
|
||||
// The override directory's catalog, signature and icons can change under an unchanged value.
|
||||
if let Ok(override_dir) = env::var("ARTCRAFT_CATALOG_DIR")
|
||||
&& !override_dir.trim().is_empty()
|
||||
{
|
||||
println!("cargo:rerun-if-changed={override_dir}");
|
||||
}
|
||||
|
||||
let out = PathBuf::from(env::var_os("OUT_DIR").ok_or("OUT_DIR missing")?);
|
||||
let cache = cache_dir(&out);
|
||||
|
||||
@@ -186,10 +186,7 @@ mod tests {
|
||||
#[test]
|
||||
fn picture_addresses_come_only_from_the_pages_own_pictures() {
|
||||
let page = AppDetails::by_id("photocraft").unwrap();
|
||||
assert_eq!(
|
||||
page.screenshot_url("demo").as_deref(),
|
||||
Some("https://getartcraft.com/launcher-screenshots/v1/photocraft/demo.jpg")
|
||||
);
|
||||
assert_eq!(page.screenshot_url("demo").as_deref(), Some("https://getartcraft.com/launcher-screenshots/v1/photocraft/demo.jpg"));
|
||||
assert_eq!(
|
||||
page.screenshot_fallback_url("demo").as_deref(),
|
||||
Some("https://raw.githubusercontent.com/storytold/craft-launcher-assets/v1/photocraft/demo.jpg")
|
||||
|
||||
@@ -244,10 +244,8 @@ impl Feed {
|
||||
if let Some(feed_repo) = &entry.repo
|
||||
&& !feed_repo.eq_ignore_ascii_case(&repo)
|
||||
{
|
||||
match app.former_repo.filter(|former| feed_repo.eq_ignore_ascii_case(former)) {
|
||||
Some(former) => repo = former.to_string(),
|
||||
None => return None,
|
||||
}
|
||||
let former = app.former_repo.filter(|former| feed_repo.eq_ignore_ascii_case(former))?;
|
||||
repo = former.to_string();
|
||||
}
|
||||
Some((entry, repo))
|
||||
}
|
||||
|
||||
@@ -340,7 +340,8 @@ fn valid_record(r: &Record) -> bool {
|
||||
&& p.shots.iter().all(|s| {
|
||||
identifier(&s.key)
|
||||
&& (s.url == format!("{}/{}/{}/{}.jpg", crate::details::SCREENSHOTS_BASE, crate::details::SCREENSHOTS_REV, r.id, s.key)
|
||||
|| s.url == format!("{}/{}/{}/{}.jpg", crate::details::SCREENSHOTS_FALLBACK_BASE, crate::details::SCREENSHOTS_REV, r.id, s.key))
|
||||
|| s.url
|
||||
== format!("{}/{}/{}/{}.jpg", crate::details::SCREENSHOTS_FALLBACK_BASE, crate::details::SCREENSHOTS_REV, r.id, s.key))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2462,9 +2462,7 @@ fn track_answer(
|
||||
) -> (Option<LatestRelease>, Origin, Option<Source>) {
|
||||
let query = release_query(feed, app).with_priority(github_priority(app, track, shared, force));
|
||||
if *track == VersionTrack::Nightly {
|
||||
if !force
|
||||
&& let Some(FeedAnswer::Fresh(Some(nightly))) = feed.map(|f| f.answer_nightly(app, now))
|
||||
{
|
||||
if !force && let Some(FeedAnswer::Fresh(Some(nightly))) = feed.map(|f| f.answer_nightly(app, now)) {
|
||||
return (Some(LatestRelease::Found(nightly)), Origin::ArtCraftApi, Some(Source::Feed));
|
||||
}
|
||||
// Its own record, apart from the stable track's: asking about one doesn't stand in for
|
||||
|
||||
@@ -67,11 +67,13 @@ pub fn fetch_all(http: Option<&Http>, paths: &Paths, details: &AppDetails, mut e
|
||||
continue;
|
||||
}
|
||||
let result = match (http, details.screenshot_url(shot.key)) {
|
||||
(Some(http), Some(url)) => download(http, &url, &saved).or_else(|primary_err| {
|
||||
match details.screenshot_fallback_url(shot.key) {
|
||||
Some(fallback) => download(http, &fallback, &saved).map_err(|_| primary_err),
|
||||
None => Err(primary_err),
|
||||
(Some(http), Some(url)) => download(http, &url, &saved).or_else(|primary| match details.screenshot_fallback_url(shot.key) {
|
||||
// A picture-specific answer from the fallback ("not published") must not read as a
|
||||
// network failure, or the pictures still to fetch would be skipped.
|
||||
Some(fallback) => {
|
||||
download(http, &fallback, &saved).map_err(|fallback| if matches!(fallback, Failure::Picture(_)) { fallback } else { primary })
|
||||
}
|
||||
None => Err(primary),
|
||||
}),
|
||||
(None, _) => Err(Failure::Network("HTTPS isn't available".into())),
|
||||
(_, None) => Err(Failure::Picture("this page has no such picture".into())),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Build, sign and package ArtCraft Launcher for Windows.
|
||||
|
||||
@@ -126,22 +126,48 @@ function New-InstallerArt([string] $BannerOut, [string] $DialogOut) {
|
||||
'anicraft', 'designcraft', 'figcraft', 'wordcraft', 'soundcraft', 'deckcraft', 'cadcraft', 'gridcraft', 'craft-anything', 'texturecraft', 'materialcraft'
|
||||
$mark = [System.Drawing.Image]::FromFile((Join-Path $Root 'assets\app-icon\hicolor\256x256\apps\ai.storyteller.artcraft-launcher.png'))
|
||||
$wordmark = [System.Drawing.Image]::FromFile((Join-Path $Root 'docs\brand\artcraft-logo-white.png'))
|
||||
# Fetch app icons from the live signed website catalog (cached in TEMP for repeated builds).
|
||||
$iconCache = Join-Path $env:TEMP 'artcraft-launcher-icon-cache'
|
||||
New-Item -ItemType Directory -Force -Path $iconCache | Out-Null
|
||||
$catalogText = (Invoke-WebRequest -UseBasicParsing -Uri 'https://getartcraft.com/launcher-catalog.toml').Content
|
||||
$iconUrls = @{}
|
||||
$currentId = $null
|
||||
foreach ($line in ($catalogText -split "`r?`n")) {
|
||||
if ($line -match '^id\s*=\s*"([^"]+)"') { $currentId = $Matches[1] }
|
||||
elseif ($currentId -and $line -match '^icon_url\s*=\s*"([^"]+)"') { $iconUrls[$currentId] = $Matches[1] }
|
||||
# App icons come from the signed launcher catalog. The build already checked the catalog's Ed25519
|
||||
# signature and every icon's SHA-256 (crates/core/build.rs) and keeps both in artcraft-catalog-cache:
|
||||
# reuse them, so packaging works offline. Without that cache (for example -SkipBuild on a fresh
|
||||
# machine) fetch the catalog over HTTPS; its signature is not checked here, but every icon must still
|
||||
# match the SHA-256 the catalog lists.
|
||||
$catalogCache = @($env:ARTCRAFT_CATALOG_CACHE_DIR, (Join-Path $TargetDir "$Target\artcraft-catalog-cache"), (Join-Path $TargetDir 'artcraft-catalog-cache')) |
|
||||
Where-Object { $_ -and (Test-Path -LiteralPath (Join-Path $_ 'launcher-catalog.toml')) } | Select-Object -First 1
|
||||
if ($catalogCache) {
|
||||
$catalogText = Get-Content -Raw -LiteralPath (Join-Path $catalogCache 'launcher-catalog.toml')
|
||||
$iconDir = Join-Path $catalogCache 'icons'
|
||||
} else {
|
||||
Write-Warning 'No build-verified launcher catalog found; fetching getartcraft.com/launcher-catalog.toml without checking its signature.'
|
||||
$catalogText = (Invoke-WebRequest -UseBasicParsing -Uri 'https://getartcraft.com/launcher-catalog.toml').Content
|
||||
$iconDir = Join-Path $env:TEMP 'artcraft-launcher-icon-cache'
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path $iconDir | Out-Null
|
||||
# Read each [[apps]] table's own id, icon_url and icon_sha256, whatever their order or indentation;
|
||||
# any other table header (such as [apps.details]) ends the app's own keys.
|
||||
$catalogApps = @{}
|
||||
$entry = $null
|
||||
foreach ($row in ($catalogText -split "`r?`n")) {
|
||||
if ($row -match '^\s*\[\[apps\]\]\s*(#.*)?$') { $entry = @{}; continue }
|
||||
if ($row -match '^\s*\[') { $entry = $null; continue }
|
||||
if ($null -ne $entry -and $row -match '^\s*(id|icon_url|icon_sha256)\s*=\s*"([^"]*)"') {
|
||||
$entry[$Matches[1]] = $Matches[2]
|
||||
if ($entry['id']) { $catalogApps[$entry['id']] = $entry }
|
||||
}
|
||||
}
|
||||
$icons = $apps | ForEach-Object {
|
||||
$url = $iconUrls[$_]
|
||||
if (-not $url) { throw "Missing icon_url in launcher-catalog.toml for $_" }
|
||||
$fileName = [System.IO.Path]::GetFileName(([System.Uri]$url).AbsolutePath)
|
||||
$cached = Join-Path $iconCache $fileName
|
||||
if (-not (Test-Path $cached)) { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $cached }
|
||||
$app = $catalogApps[$_]
|
||||
if (-not $app -or -not $app['icon_url'] -or -not $app['icon_sha256']) { throw "launcher-catalog.toml has no icon_url and icon_sha256 for $_" }
|
||||
$sha = $app['icon_sha256'].ToLowerInvariant()
|
||||
if ($sha -notmatch '^[0-9a-f]{64}$') { throw "launcher-catalog.toml lists a malformed icon_sha256 for $_" }
|
||||
if ($app['icon_url'] -notmatch '^https://') { throw "launcher-catalog.toml lists a non-HTTPS icon_url for $_" }
|
||||
$cached = Join-Path $iconDir "$sha.png"
|
||||
if (-not ((Test-Path -LiteralPath $cached) -and ((Get-FileHash -LiteralPath $cached -Algorithm SHA256).Hash.ToLowerInvariant() -eq $sha))) {
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $app['icon_url'] -OutFile $cached
|
||||
if ((Get-FileHash -LiteralPath $cached -Algorithm SHA256).Hash.ToLowerInvariant() -ne $sha) {
|
||||
Remove-Item -LiteralPath $cached -Force
|
||||
throw "The icon for $_ does not match the SHA-256 in launcher-catalog.toml"
|
||||
}
|
||||
}
|
||||
[System.Drawing.Image]::FromFile($cached)
|
||||
}
|
||||
# The site's label face; GDI+ draws a variable font at its default instance (Regular).
|
||||
|
||||
Reference in new issue
Block a user