Upload via GUI (25 Dateien)
This commit is contained in:
+30
-9
@@ -17,6 +17,13 @@ const { spawn } = require('child_process');
|
||||
const API = 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/AeroMc-Launcher/releases';
|
||||
const UA = 'AeroMC-Launcher';
|
||||
|
||||
function detectInstallKind() {
|
||||
const portableExe = String(process.env.PORTABLE_EXECUTABLE_FILE || '').trim();
|
||||
const execName = path.basename(portableExe || process.execPath || '').toLowerCase();
|
||||
if (portableExe || execName.includes('portable')) return 'portable';
|
||||
return 'setup';
|
||||
}
|
||||
|
||||
// "1.2.3" -> [1,2,3]; führendes "v" und Zusätze wie "-beta" werden ignoriert
|
||||
function parseVersion(v) {
|
||||
const m = String(v || '').trim().replace(/^v/i, '').match(/^(\d+)(?:\.(\d+))?(?:\.(\d+))?/);
|
||||
@@ -34,13 +41,21 @@ function compareVersions(a, b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Windows-Installer im Release finden (.exe bevorzugt, sonst .zip)
|
||||
function pickAsset(release) {
|
||||
function isPortableAsset(name) {
|
||||
return /portable/i.test(name) && /\.exe$/i.test(name);
|
||||
}
|
||||
|
||||
function isSetupAsset(name) {
|
||||
return /setup/i.test(name) && /\.exe$/i.test(name);
|
||||
}
|
||||
|
||||
// passendes Windows-Artefakt im Release finden
|
||||
function pickAsset(release, installKind) {
|
||||
const assets = release.assets || [];
|
||||
return assets.find((a) => /\.exe$/i.test(a.name))
|
||||
|| assets.find((a) => /setup.*\.exe$/i.test(a.name))
|
||||
|| assets.find((a) => /\.zip$/i.test(a.name))
|
||||
|| null;
|
||||
if (installKind === 'portable') {
|
||||
return assets.find((a) => isPortableAsset(a.name)) || null;
|
||||
}
|
||||
return assets.find((a) => isSetupAsset(a.name)) || null;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -48,6 +63,7 @@ function pickAsset(release) {
|
||||
* -> { available, currentVersion, latestVersion, notes, asset, url, noReleases }
|
||||
*/
|
||||
async function checkForUpdate(currentVersion) {
|
||||
const installKind = detectInstallKind();
|
||||
const res = await fetch(API + '?limit=10', { headers: { 'User-Agent': UA, Accept: 'application/json' } });
|
||||
if (!res.ok) throw new Error('Update-Server antwortet mit HTTP ' + res.status);
|
||||
const list = await res.json();
|
||||
@@ -59,14 +75,15 @@ async function checkForUpdate(currentVersion) {
|
||||
releases.sort((a, b) => compareVersions(b.tag_name, a.tag_name));
|
||||
const latest = releases[0];
|
||||
const available = compareVersions(latest.tag_name, currentVersion) > 0;
|
||||
const asset = pickAsset(latest);
|
||||
const asset = pickAsset(latest, installKind);
|
||||
return {
|
||||
available,
|
||||
currentVersion,
|
||||
latestVersion: String(latest.tag_name || '').replace(/^v/i, ''),
|
||||
installKind,
|
||||
notes: latest.body || '',
|
||||
published: latest.published_at || latest.created_at || null,
|
||||
asset: asset ? { name: asset.name, url: asset.browser_download_url, size: asset.size } : null,
|
||||
asset: asset ? { name: asset.name, url: asset.browser_download_url, size: asset.size, kind: installKind } : null,
|
||||
url: latest.html_url,
|
||||
};
|
||||
}
|
||||
@@ -77,6 +94,10 @@ async function checkForUpdate(currentVersion) {
|
||||
*/
|
||||
async function downloadAndInstall(asset, onProgress) {
|
||||
if (!asset || !asset.url) throw new Error('Kein Installer im Release gefunden.');
|
||||
const installKind = detectInstallKind();
|
||||
if (asset.kind && asset.kind !== installKind) {
|
||||
throw new Error('Das angebotene Update passt nicht zur laufenden Paketart.');
|
||||
}
|
||||
|
||||
const dir = path.join(os.tmpdir(), 'aeromc-update');
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
@@ -112,4 +133,4 @@ function runInstaller(installerPath) {
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { checkForUpdate, downloadAndInstall, runInstaller, compareVersions, parseVersion };
|
||||
module.exports = { checkForUpdate, downloadAndInstall, runInstaller, compareVersions, parseVersion, detectInstallKind };
|
||||
|
||||
Reference in New Issue
Block a user