Repository navigation
Expand file tree
/
Copy pathupdate_check.cpp
More file actions
705 lines (594 loc) · 28.2 KB
/
Copy pathupdate_check.cpp
File metadata and controls
705 lines (594 loc) · 28.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
#include "SDK-2025-03-07/foobar2000/SDK/foobar2000.h"
#include "third_party/nlohmann/json.hpp"
#include "repository_mapping.h"
#include "remote_registry.h"
#include "update_check.h"
#include "result_window.h"
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <sstream>
#include <regex>
// ------------------------------------------------------------------
// Phase 1: 更新確認のコアロジック(手動確認・自動確認で共用)
//
// 流れ:
// 1. componentversion::enumerate() で導入済みコンポーネントを取得(メインスレッド)
// 2. Repository Mapping(cfg_stringに永続化。repository_mapping.cpp参照)と突き合わせ
// 3. マッチしたものだけワーカースレッドでGitHub Releases APIへ問い合わせ
// 4. バージョン比較(数値のみ対応。それ以外は「比較不能」として誤判定を避ける)
// 5. 結果をまとめて1回のログ出力で表示
//
// Repository Mappingへの登録は「Manage Component Repositories...」から行う。
// ------------------------------------------------------------------
namespace {
// DP-0009 / DP-0010: 誤判定するくらいなら「比較不能」を返す。
//
// 対応する形式(SemVer準拠。先頭のv/Vは許容):
// MAJOR.MINOR.PATCH[.MORE...][-prerelease][+build]
// 例: "4.2.0", "v1.5.2", "1.0.0-beta", "2.0.0-rc.1", "1.2.3+20240101"
//
// - ビルドメタデータ(+以降)は優先順位に影響しないため無視する(SemVer仕様通り)
// - prerelease同士の比較はSemVer 2.0.0の優先順位ルールに従う:
// * ドット区切りの識別子ごとに比較する
// * 数字のみの識別子は数値として比較する
// * 数字のみの識別子は、英数字混在の識別子より必ず「小さい」とみなす
// * それ以外(英字を含む)は文字コード順(ASCII)で比較する
// * すべて一致した場合、識別子の数が少ない方を「小さい」とみなす
// - この形式に当てはまらないバージョン文字列は「比較不能」として扱う
struct ParsedVersion {
std::vector<long long> core;
std::vector<std::string> prerelease; // 空 = 正式リリース(prereleaseなし)
bool hasPrerelease = false;
};
bool isValidPrereleaseIdentifier(std::string const& id) {
if (id.empty()) return false;
for (char c : id) {
if (!(std::isalnum(static_cast<unsigned char>(c)) || c == '-')) return false;
}
return true;
}
bool isNumericIdentifier(std::string const& id) {
if (id.empty()) return false;
for (char c : id) {
if (!std::isdigit(static_cast<unsigned char>(c))) return false;
}
return true;
}
bool tryParseVersion(std::string raw, ParsedVersion& out) {
std::string s = raw;
if (!s.empty() && (s[0] == 'v' || s[0] == 'V')) s.erase(0, 1);
if (s.empty()) return false;
// ビルドメタデータ(+以降)は優先順位に無関係なので切り落とす
size_t plusPos = s.find('+');
if (plusPos != std::string::npos) {
s = s.substr(0, plusPos);
}
if (s.empty()) return false;
// prerelease(-以降)を切り出す
std::string corePart = s;
std::string prereleasePart;
bool hasPrerelease = false;
size_t dashPos = s.find('-');
if (dashPos != std::string::npos) {
corePart = s.substr(0, dashPos);
prereleasePart = s.substr(dashPos + 1);
hasPrerelease = true;
}
// コア部分(数字とドットのみ)を解析
if (corePart.empty()) return false;
for (char c : corePart) {
if (!(std::isdigit(static_cast<unsigned char>(c)) || c == '.')) return false;
}
std::vector<long long> core;
{
std::stringstream ss(corePart);
std::string token;
while (std::getline(ss, token, '.')) {
if (token.empty()) return false;
try {
core.push_back(std::stoll(token));
} catch (...) {
return false;
}
}
}
if (core.empty()) return false;
// prerelease部分(あれば)を解析
std::vector<std::string> prerelease;
if (hasPrerelease) {
if (prereleasePart.empty()) return false; // "1.2.3-" のような不完全な形式は不可
std::stringstream ss(prereleasePart);
std::string token;
while (std::getline(ss, token, '.')) {
if (!isValidPrereleaseIdentifier(token)) return false;
prerelease.push_back(token);
}
if (prerelease.empty()) return false;
}
out.core = std::move(core);
out.prerelease = std::move(prerelease);
out.hasPrerelease = hasPrerelease;
return true;
}
// SemVer 2.0.0の優先順位ルールでprerelease識別子リストを比較する。
// 戻り値: a<b なら負、a>b なら正、等しければ0。
int comparePrereleaseIdentifiers(std::vector<std::string> const& a, std::vector<std::string> const& b) {
size_t n = (std::min)(a.size(), b.size());
for (size_t i = 0; i < n; ++i) {
std::string const& ida = a[i];
std::string const& idb = b[i];
bool numA = isNumericIdentifier(ida);
bool numB = isNumericIdentifier(idb);
if (numA && numB) {
long long va, vb;
try {
va = std::stoll(ida);
vb = std::stoll(idb);
} catch (...) {
// 極端に長い数字列などで変換に失敗した場合は文字列比較にフォールバック
if (ida != idb) return ida < idb ? -1 : 1;
continue;
}
if (va != vb) return va < vb ? -1 : 1;
continue;
}
if (numA != numB) {
// 数字のみの識別子は、英数字混在の識別子より必ず小さい(SemVer仕様)
return numA ? -1 : 1;
}
if (ida != idb) return ida < idb ? -1 : 1;
}
if (a.size() != b.size()) return a.size() < b.size() ? -1 : 1;
return 0;
}
UpdateStatus compareVersions(std::string const& installedRaw, std::string const& latestRaw) {
ParsedVersion a, b;
if (!tryParseVersion(installedRaw, a) || !tryParseVersion(latestRaw, b)) {
return UpdateStatus::ComparisonUnsupported;
}
// 1. コア部分(Major.Minor.Patch...)を比較
size_t n = (std::max)(a.core.size(), b.core.size());
for (size_t i = 0; i < n; ++i) {
long long av = i < a.core.size() ? a.core[i] : 0;
long long bv = i < b.core.size() ? b.core[i] : 0;
if (av < bv) return UpdateStatus::UpdateAvailable;
if (av > bv) return UpdateStatus::UpToDate;
}
// 2. コアが同じ場合、prereleaseの有無・内容で比較する(SemVer仕様)
// 正式リリースは、同じコアのどのprereleaseよりも優先順位が高い
if (!a.hasPrerelease && !b.hasPrerelease) return UpdateStatus::UpToDate;
if (a.hasPrerelease && !b.hasPrerelease) return UpdateStatus::UpdateAvailable; // 導入版がprerelease、最新は正式版
if (!a.hasPrerelease && b.hasPrerelease) return UpdateStatus::UpToDate; // 導入版が既に正式版、最新はprerelease
int cmp = comparePrereleaseIdentifiers(a.prerelease, b.prerelease);
if (cmp < 0) return UpdateStatus::UpdateAvailable;
return UpdateStatus::UpToDate;
}
// ------------------------------------------------------------------
// サイト別のリリース取得。それぞれ「取得できたか」「tag_name/リリースページURL」
// 「(失敗時の)原因別メッセージ」を返す。
//
// 注意: GitLab/CodebergのAPI仕様は、GitHub(実機で動作検証済み)ほど検証が
// できていない。エンドポイントの詳細(特にCodebergの/latestの有無、GitLabの
// permalink/latestの挙動)は実際にビルドして動作確認しながら調整すること。
//
// marc2k3(HTML直書き配布)は正式なAPIが無いサイト固有のパーサーであり、
// ページの構造(Zensicalテーマ)が変わると壊れる前提。DP-0009に従い、
// 想定した構造が見つからない場合は誤判定せず必ずエラーを返す。
// ------------------------------------------------------------------
struct FetchedRelease {
std::string tagName;
std::string releaseUrl;
};
bool FetchGitHubLatestRelease(
std::string const& owner, std::string const& repo, abort_callback& abort,
FetchedRelease& out, std::string& errorMessage
) {
pfc::string8 body;
try {
pfc::string8 url = "https://api.github.com/repos/";
url << owner.c_str() << "/" << repo.c_str() << "/releases/latest";
http_client::ptr client = http_client::get();
http_request::ptr request = client->create_request("GET");
request->add_header("User-Agent", "foo_component_update_checker/2.3.0");
request->add_header("Accept", "application/vnd.github+json");
file::ptr response = request->run(url, abort);
response->read_string_raw(body, abort);
} catch (std::exception const& e) {
errorMessage = std::string("Network/API error: ") + e.what();
return false;
}
try {
nlohmann::json parsed = nlohmann::json::parse(body.c_str());
out.tagName = parsed.value("tag_name", "");
out.releaseUrl = parsed.value("html_url", "");
return true;
} catch (std::exception const& e) {
errorMessage = std::string("Invalid response: ") + e.what();
return false;
}
}
bool FetchGitLabLatestRelease(
std::string const& owner, std::string const& repo, abort_callback& abort,
FetchedRelease& out, std::string& errorMessage
) {
pfc::string8 body;
try {
// GitLabのプロジェクトIDは "owner/repo" をURLエンコードした形("%2F"区切り)で指定する。
pfc::string8 url = "https://gitlab.com/api/v4/projects/";
url << owner.c_str() << "%2F" << repo.c_str() << "/releases/permalink/latest";
http_client::ptr client = http_client::get();
http_request::ptr request = client->create_request("GET");
request->add_header("User-Agent", "foo_component_update_checker/2.3.0");
file::ptr response = request->run(url, abort);
response->read_string_raw(body, abort);
} catch (std::exception const& e) {
errorMessage = std::string("Network/API error: ") + e.what();
return false;
}
try {
nlohmann::json parsed = nlohmann::json::parse(body.c_str());
out.tagName = parsed.value("tag_name", "");
// GitLabのAPIレスポンスにはリリースページの直接URLが含まれていないため、
// 標準的なURL形式から組み立てる。
pfc::string8 url = "https://gitlab.com/";
url << owner.c_str() << "/" << repo.c_str() << "/-/releases/" << out.tagName.c_str();
out.releaseUrl = url.c_str();
return !out.tagName.empty();
} catch (std::exception const& e) {
errorMessage = std::string("Invalid response: ") + e.what();
return false;
}
}
bool FetchCodebergLatestRelease(
std::string const& owner, std::string const& repo, abort_callback& abort,
FetchedRelease& out, std::string& errorMessage
) {
pfc::string8 body;
try {
// Codeberg(Gitea)は一覧取得APIを使い、先頭(最新)の1件だけ要求する。
pfc::string8 url = "https://codeberg.org/api/v1/repos/";
url << owner.c_str() << "/" << repo.c_str() << "/releases?limit=1&draft=false&pre-release=false";
http_client::ptr client = http_client::get();
http_request::ptr request = client->create_request("GET");
request->add_header("User-Agent", "foo_component_update_checker/2.3.0");
file::ptr response = request->run(url, abort);
response->read_string_raw(body, abort);
} catch (std::exception const& e) {
errorMessage = std::string("Network/API error: ") + e.what();
return false;
}
try {
nlohmann::json parsed = nlohmann::json::parse(body.c_str());
if (!parsed.is_array() || parsed.empty()) {
errorMessage = "Invalid response: no releases found for this repository.";
return false;
}
nlohmann::json const& latest = parsed[0];
out.tagName = latest.value("tag_name", "");
out.releaseUrl = latest.value("html_url", "");
return !out.tagName.empty();
} catch (std::exception const& e) {
errorMessage = std::string("Invalid response: ") + e.what();
return false;
}
}
bool FetchMarc2k3LatestRelease(
std::string const& pageUrl, abort_callback& abort,
FetchedRelease& out, std::string& errorMessage
) {
pfc::string8 body;
try {
http_client::ptr client = http_client::get();
http_request::ptr request = client->create_request("GET");
request->add_header("User-Agent", "foo_component_update_checker/2.3.0");
file::ptr response = request->run(pfc::string8(pageUrl.c_str()), abort);
response->read_string_raw(body, abort);
} catch (std::exception const& e) {
errorMessage = std::string("Network/API error: ") + e.what();
return false;
}
std::string html = body.c_str();
// marc2k3サイト(Zensicalテーマ)のDownloadボタンを特定する。実例:
// <a class="md-button md-button--primary" href="../../files/foo_cover_utils-1.7.fb2k-component">
// href は "../../files/..." のような相対パスのままで、絶対URL化する必要はない
// (末尾のファイル名からバージョンさえ取れればよく、releaseUrlは登録ページURLを
// そのまま使うため)。
// 注意: このパターンは "([^"]+)" のように )" という並びを含むため、
// 既定の区切り子 R"( ... )" だと生文字列リテラルが途中で終端してしまう。
// カスタム区切り子 R"RX( ... )RX" を使って衝突を避ける。
static const std::regex downloadButtonPattern(
R"RX(class="md-button md-button--primary"\s+href="([^"]+)")RX"
);
std::smatch m;
if (!std::regex_search(html, m, downloadButtonPattern)) {
errorMessage = "Unable to locate the download button on this page (page structure may have changed).";
return false;
}
std::string href = m[1].str();
// ファイル名末尾の "-<version>.fb2k-component" からバージョンを抜き出す。
static const std::regex versionPattern(
R"(-([0-9]+(?:\.[0-9]+)*)\.fb2k-component$)"
);
std::smatch vm;
if (!std::regex_search(href, vm, versionPattern)) {
errorMessage = "Download link found, but its filename didn't match the expected version pattern.";
return false;
}
out.tagName = vm[1].str(); // 例: "1.7"
out.releaseUrl = pageUrl; // 専用のリリースページが無いため、登録ページURLをそのまま使う
return true;
}
// SourceForgeは正式なReleases APIを持たないが、プラットフォーム共通機能として
// 各プロジェクトのファイル配布用RSSフィード(/projects/{project}/rss?path={path})
// を持っている。これはmarc2k3と違いSourceForge全プロジェクトに共通する構造なので、
// プロジェクトごとの特別対応なしに汎用的に扱える。
//
// 登録は「フォルダのファイル一覧ページURL」で行う(例:
// https://sourceforge.net/projects/sacddecoder/files/foo_input_sacd/)。
// フェッチ時にそこからプロジェクト名とフォルダパスを抜き出し、RSS URLを組み立てる。
bool FetchSourceForgeLatestRelease(
std::string const& folderUrl, abort_callback& abort,
FetchedRelease& out, std::string& errorMessage
) {
static const std::regex folderUrlPattern(
R"RX(sourceforge\.net/projects/([^/]+)/files(/[^?#]*)?)RX"
);
std::smatch fm;
if (!std::regex_search(folderUrl, fm, folderUrlPattern)) {
errorMessage = "Invalid SourceForge URL: expected a project files page, e.g. https://sourceforge.net/projects/<project>/files/<folder>/";
return false;
}
std::string project = fm[1].str();
std::string path = fm[2].matched ? fm[2].str() : "";
// RSSのpathパラメータは末尾スラッシュ無しの形式を使う。空ならルート("/")扱い。
if (!path.empty() && path.back() == '/') path.pop_back();
if (path.empty()) path = "/";
std::string rssUrl = "https://sourceforge.net/projects/" + project + "/rss?path=" + path;
pfc::string8 body;
try {
http_client::ptr client = http_client::get();
http_request::ptr request = client->create_request("GET");
request->add_header("User-Agent", "foo_component_update_checker/2.3.0");
file::ptr response = request->run(pfc::string8(rssUrl.c_str()), abort);
response->read_string_raw(body, abort);
} catch (std::exception const& e) {
errorMessage = std::string("Network/API error: ") + e.what();
return false;
}
std::string xml = body.c_str();
// <item><title><![CDATA[/folder/filename]]></title>...</item> という並びを
// 日付が新しい順(SourceForgeのRSSはアップロード順)に走査し、バージョン番号+
// アーカイブ拡張子という形に厳密にマッチする最初のファイルを採用する。
// これにより readme.txt 等の非パッケージファイルや、"-1.6.x.zip" のような
// 互換ビルド用サフィックス付きファイル(数字だけで終わらない)は自然に
// スキップされ、実質「最新の正式リリース」だけが拾われる(DP-0009)。
static const std::regex itemTitlePattern(
R"RX(<title><!\[CDATA\[([^\]]+)\]\]></title>)RX"
);
static const std::regex fileVersionPattern(
R"RX(-([0-9]+(?:\.[0-9]+)*)\.(?:zip|rar|7z|fb2k-component)$)RX",
std::regex::icase
);
auto begin = std::sregex_iterator(xml.begin(), xml.end(), itemTitlePattern);
auto end = std::sregex_iterator();
for (auto it = begin; it != end; ++it) {
std::string title = (*it)[1].str();
std::smatch vm;
if (std::regex_search(title, vm, fileVersionPattern)) {
out.tagName = vm[1].str();
out.releaseUrl = folderUrl; // RSS URLではなく、人が見られるフォルダページを使う
return true;
}
}
errorMessage = "No release archive with a recognizable version number was found in this SourceForge folder's feed.";
return false;
}
// foobar.hyv.fi(Case氏の個人配布サイト)は、marc2k3と同じくこのサイト専用の
// パーサー。ただし構造がmarc2k3と異なり、ダウンロードリンクのファイル名には
// バージョンが含まれていない(例: foo_hdcd.fb2k-component)。代わりにページ内の
// 情報テーブルに "Version:" の行が明示的にあるので、そちらから直接読み取る。
// サイト全体で同一テンプレートが使われていることを実サイト2件
// (foo_hdcd, foo_out_digital)で確認済み。
bool FetchHyvLatestRelease(
std::string const& pageUrl, abort_callback& abort,
FetchedRelease& out, std::string& errorMessage
) {
pfc::string8 body;
try {
http_client::ptr client = http_client::get();
http_request::ptr request = client->create_request("GET");
request->add_header("User-Agent", "foo_component_update_checker/2.3.0");
file::ptr response = request->run(pfc::string8(pageUrl.c_str()), abort);
response->read_string_raw(body, abort);
} catch (std::exception const& e) {
errorMessage = std::string("Network/API error: ") + e.what();
return false;
}
std::string html = body.c_str();
// 実例: <tr><td>Version:</td><td>1.22</td></tr>
// "Changes" テーブル側にも "1.22 (2025-09-08):" のような紛らわしい文字列が
// あるが、リテラル "Version:" は情報テーブル側にしか出現しないため、
// このパターンで確実に区別できる。
static const std::regex versionRowPattern(
R"RX(<tr><td>Version:</td><td>([^<]+)</td></tr>)RX"
);
std::smatch vm;
if (!std::regex_search(html, vm, versionRowPattern)) {
errorMessage = "Unable to locate the Version field on this page (page structure may have changed).";
return false;
}
out.tagName = vm[1].str();
out.releaseUrl = pageUrl; // 専用のリリースページが無いため、登録ページURLをそのまま使う
return true;
}
} // namespace
std::vector<InstalledComponentInfo> GetInstalledComponents() {
std::vector<InstalledComponentInfo> installed;
for (auto ptr : componentversion::enumerate()) {
pfc::string8 fileName, name, version;
ptr->get_file_name(fileName);
ptr->get_component_name(name);
ptr->get_component_version(version);
InstalledComponentInfo info;
info.fileName = fileName.c_str();
info.displayName = name.c_str();
info.installedVersion = version.c_str();
installed.push_back(std::move(info));
}
return installed;
}
std::vector<CheckResult> RunUpdateCheck(
std::vector<InstalledComponentInfo> const& installed,
abort_callback& abort
) {
std::vector<CheckResult> results;
// Repository Mappingはcfg_stringに保存されているが、cfg_varはメインスレッド
// 前提のAPIではないため、ワーカースレッドで読み込んでも問題ない。
std::vector<RepositoryMappingEntry> mappingEntries = loadRepositoryMapping();
// Remote Registry(開発側が管理する既知コンポーネントDB)。
// ユーザー登録に無いコンポーネントの補完として使う(DP-0018 Hybrid Registry Model)。
// GitHub上の静的JSONを取得するため、ここでもネットワークI/Oが発生しうる。
RemoteRegistryFetchStatus registryStatus;
std::vector<RemoteRegistryEntry> remoteEntries = GetRemoteRegistryEntries(abort, ®istryStatus);
// Remote Registry自体の取得に失敗した場合、これまでは完全に見えなかった。
// 通知レベルの判定(automatic_check.cpp)に使えるよう、結果セットの一部として
// 合成エントリを含める(手動確認では常に表示される)。
if (registryStatus.attempted && !registryStatus.succeeded) {
CheckResult r;
r.dllName = "";
r.displayName = "Shared Registry (known_components.json)";
r.installedVersion = "";
r.status = UpdateStatus::Error;
r.errorMessage = registryStatus.errorMessage;
results.push_back(std::move(r));
}
for (auto const& comp : installed) {
// 1. ユーザーが明示的に登録した内容を最優先する
RepositoryMappingEntry mapping;
bool found = findRepositoryMapping(mappingEntries, comp.fileName, mapping);
// 2. ユーザー登録が無ければ、Remote Registry(known_components.json)を参照する
if (!found) {
RemoteRegistryEntry remote;
if (findRemoteRegistryEntry(remoteEntries, comp.fileName, remote)) {
mapping.dllName = remote.dllName;
mapping.source = remote.source;
mapping.owner = remote.owner;
mapping.repo = remote.repo;
mapping.url = remote.url;
found = true;
}
}
if (!found) continue; // Phase 1/2: どちらにも無ければ静かにスキップ
CheckResult r;
r.dllName = comp.fileName;
r.displayName = comp.displayName;
r.installedVersion = comp.installedVersion;
FetchedRelease release;
std::string errorMessage;
bool fetchOk = false;
if (mapping.source == "gitlab") {
fetchOk = FetchGitLabLatestRelease(mapping.owner, mapping.repo, abort, release, errorMessage);
} else if (mapping.source == "codeberg") {
fetchOk = FetchCodebergLatestRelease(mapping.owner, mapping.repo, abort, release, errorMessage);
} else if (mapping.source == "marc2k3") {
fetchOk = FetchMarc2k3LatestRelease(mapping.url, abort, release, errorMessage);
} else if (mapping.source == "sourceforge") {
fetchOk = FetchSourceForgeLatestRelease(mapping.url, abort, release, errorMessage);
} else if (mapping.source == "hyv") {
fetchOk = FetchHyvLatestRelease(mapping.url, abort, release, errorMessage);
} else {
// "github"、または未設定(後方互換)の場合はGitHubとして扱う。
fetchOk = FetchGitHubLatestRelease(mapping.owner, mapping.repo, abort, release, errorMessage);
}
if (fetchOk) {
r.latestVersion = release.tagName;
r.releaseUrl = release.releaseUrl;
r.status = compareVersions(r.installedVersion, r.latestVersion);
} else {
r.status = UpdateStatus::Error;
r.errorMessage = errorMessage;
}
results.push_back(std::move(r));
}
return results;
}
bool HasUpdateAvailable(std::vector<CheckResult> const& results) {
for (auto const& r : results) {
if (r.status == UpdateStatus::UpdateAvailable) return true;
}
return false;
}
bool HasAnyError(std::vector<CheckResult> const& results) {
for (auto const& r : results) {
if (r.status == UpdateStatus::Error) return true;
}
return false;
}
void PrintUpdateCheckResults(std::vector<CheckResult> const& results, const char* emptyMessage) {
if (results.empty()) {
console::print(emptyMessage);
return;
}
pfc::string8 msg = "Update Check: result set (";
msg << static_cast<int>(results.size()) << " item(s))\n";
for (auto const& r : results) {
msg << "--------------------------------\n";
msg << r.displayName.c_str() << " [" << r.dllName.c_str() << "]\n";
msg << " Installed: " << r.installedVersion.c_str() << "\n";
switch (r.status) {
case UpdateStatus::UpdateAvailable:
msg << " Latest: " << r.latestVersion.c_str() << " -> Update available\n";
msg << " Release: " << r.releaseUrl.c_str() << "\n";
break;
case UpdateStatus::UpToDate:
msg << " Latest: " << r.latestVersion.c_str() << " -> Up to date\n";
break;
case UpdateStatus::ComparisonUnsupported:
msg << " Latest: " << r.latestVersion.c_str() << " -> Unable to compare versions\n";
msg << " Release: " << r.releaseUrl.c_str() << "\n";
break;
case UpdateStatus::Error:
msg << " Error: " << r.errorMessage.c_str() << "\n";
break;
}
}
console::print(msg);
}
namespace {
// {5E9A1C4D-2B6F-4E7A-8D3C-6F1A9B4E2D50}
const GUID guid_mainmenu_check_for_updates =
{ 0x5e9a1c4d, 0x2b6f, 0x4e7a, { 0x8d, 0x3c, 0x6f, 0x1a, 0x9b, 0x4e, 0x2d, 0x50 } };
class mainmenu_commands_check_for_updates : public mainmenu_commands {
public:
t_uint32 get_command_count() override {
return 1;
}
GUID get_command(t_uint32 p_index) override {
return guid_mainmenu_check_for_updates;
}
void get_name(t_uint32 p_index, pfc::string_base& p_out) override {
p_out = "Check Third-Party Component Updates";
}
bool get_description(t_uint32 p_index, pfc::string_base& p_out) override {
p_out = "Checks third-party components (not covered by foobar2000's own Component Repository) for updates via their GitHub repositories.";
return true;
}
GUID get_parent() override {
return mainmenu_groups::help;
}
void execute(t_uint32 p_index, service_ptr_t<service_base> p_callback) override {
std::vector<InstalledComponentInfo> installed = GetInstalledComponents();
// 検査の起動・進捗表示・結果反映は全てShowUpdateResultWindow側(result_window.cpp)
// に一本化されている。ここではダイアログを開くだけでよい。
ShowUpdateResultWindow(
core_api::get_main_window(),
installed,
"No installed components matched a registered source.\n"
"Use \"Manage Sources...\" (Preferences > Tools > Component Update Checker) to register one."
);
}
};
static service_factory_single_t<mainmenu_commands_check_for_updates> g_mainmenu_commands_check_for_updates_factory;
} // namespace