Minor changes

- added uri constants
- fixed testing patch auto installation
- improved isTelemetryDisabled method
This commit is contained in:
Observer KRypt0n_ 2021-11-01 14:50:48 +02:00
parent 36d130ead6
commit ca9162cb9f
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
5 changed files with 67 additions and 53 deletions

View file

@ -26,7 +26,7 @@ if (!fs.existsSync(constants.dxvksDir))
$(() => {
if (LauncherLib.version !== null)
document.title = `${constants.gamePlaceholder.uppercase.full} Linux Launcher - ${LauncherLib.version}`;
document.title = `${constants.placeholders.uppercase.full} Linux Launcher - ${LauncherLib.version}`;
// On Start configuration of LauncherUI
LauncherUI.updateLang(LauncherLib.getConfig('lang.launcher') ?? 'en-us');
@ -102,7 +102,7 @@ $(() => {
});
});*/
Tools.getGitTags('https://notabug.org/nobody/an-anime-game-launcher').then (tags => {
Tools.getGitTags(constants.uri.launcher).then (tags => {
if (tags.filter(entry => semver.gt(entry.tag, launcher_version)).length > 0)
{
ipcRenderer.send('notification', {
@ -194,11 +194,11 @@ $(() => {
if (!await LauncherLib.isTelemetryDisabled())
{
console.log('miHoYo\'s telemetry servers doesn\'t disabled!');
console.log(`${constants.placeholders.uppercase.company}'s telemetry servers doesn't disabled!`);
ipcRenderer.send('notification', {
title: document.title,
body: 'miHoYo\'s telemetry servers doesn\'t disabled!'
title: document.title, // FIXME add translation
body: `${constants.placeholders.uppercase.company}'s telemetry servers doesn't disabled!`
});
}
@ -372,8 +372,13 @@ $(() => {
// Patch available
if (patchInfo.version === data.game.latest.version)
{
// TODO: check the patch state
// ..but it's in testing state
if (patchInfo.state === 'testing')
LauncherUI.setState('test-patch-available');
// Otherwise it's fully released and tested and we can auto-install it
else
{
console.log(`%c> Applying patch...`, 'font-size: 16px');
// patch-applying state changes only button text
@ -390,6 +395,7 @@ $(() => {
});
}, data => console.log(data.toString()));
}
}
// Patch is not available
else LauncherUI.setState('patch-unavailable');

View file

@ -161,11 +161,11 @@ export class LauncherLib
this.getData().then(data => {
let gameLatest: string = data.game.latest.version;
fetch(`https://notabug.org/Krock/GI-on-Linux/raw/master/${gameLatest.replaceAll('.', '')}/patch.sh`)
fetch(`${constants.uri.patch}/raw/master/${gameLatest.replaceAll('.', '')}/patch.sh`)
.then(response => response.text())
.then((patch: string) => {
// patch.sh exists so patch in testing, stable or it's just a preparation
fetch(`https://notabug.org/Krock/GI-on-Linux/raw/master/${gameLatest.replaceAll('.', '')}/patch_files/unityplayer_patch.vcdiff`)
fetch(`${constants.uri.patch}/raw/master/${gameLatest.replaceAll('.', '')}/patch_files/unityplayer_patch.vcdiff`)
.then(response => response.text())
.then((unityPatch: string) => {
// unityplayer_patch exists so it's testing or stable
@ -195,33 +195,15 @@ export class LauncherLib
});
}
/**
* 0.0.0.0 log-upload-os.mihoyo.com
* 0.0.0.0 overseauspider.yuanshen.com
*/
public static isTelemetryDisabled (): Promise<boolean>
public static isTelemetryDisabled (domainNum: number = 0): Promise<boolean>
{
return new Promise((resolve, reject) => {
dns.lookup('log-upload-os.mihoyo.com', (error: any, address: string, family: any) => {
if (error)
reject(error);
Tools.domainAvailable(constants.uri.telemetry[domainNum]).then(async (status) => {
if (constants.uri.telemetry[++domainNum] !== undefined)
status &&= await this.isTelemetryDisabled(domainNum);
else
{
if (address != '0.0.0.0')
resolve(false);
else
{
dns.lookup('log-upload-os.mihoyo.com', (error: any, address: string, family: any) => {
if (error)
reject(error);
else resolve(address == '0.0.0.0');
});
}
}
});
resolve(status);
}).catch(reject);
});
}

View file

@ -14,7 +14,7 @@ type LauncherState =
export class LauncherUI
{
public static readonly socialUri = `https://${constants.gamePlaceholder.lowercase.first}.${constants.gamePlaceholder.lowercase.company}.com/launcher/10/${LauncherLib.getConfig('lang.launcher')}?api_url=https%3A%2F%2Fapi-os-takumi.${constants.gamePlaceholder.lowercase.company}.com%2Fhk4e_global&prev=false`;
public static readonly socialUri = `https://${constants.placeholders.lowercase.first}.${constants.placeholders.lowercase.company}.com/launcher/10/${LauncherLib.getConfig('lang.launcher')}?api_url=https%3A%2F%2Fapi-os-takumi.${constants.placeholders.lowercase.company}.com%2Fhk4e_global&prev=false`;
protected static _launcherState: LauncherState = 'game-launch-available';
protected static _i18n: any;

View file

@ -2,6 +2,7 @@ const https = require('follow-redirects').https;
const fs = require('fs');
const path = require('path');
const dns = require('dns');
const { spawn } = require('child_process');
type GitTag = { tag: string, commit: string };
@ -33,6 +34,20 @@ export class Tools
});
}
public static async domainAvailable (uri: string): Promise<boolean>
{
return new Promise((resolve, reject) => {
dns.lookup(uri, (error: any, address: string, family: any) => {
console.log(`${uri} -> ${address}`);
if (error)
reject(error);
else resolve(address == '0.0.0.0');
});
});
}
public static async downloadFile (uri: string, savePath: string, progress: (current: number, total: number, difference: number) => void): Promise<void|Error>
{
return new Promise((resolve, reject) => {

View file

@ -3,12 +3,13 @@ const os = require('os');
export class constants
{
public static readonly gamePlaceholder = {
public static readonly placeholders = {
uppercase:
{
first: Buffer.from('R2Vuc2hpbg==', 'base64').toString(),
second: Buffer.from('SW1wYWN0', 'base64').toString(),
full: Buffer.from('R2Vuc2hpbiBJbXBhY3Q=', 'base64').toString()
full: Buffer.from('R2Vuc2hpbiBJbXBhY3Q=', 'base64').toString(),
company: Buffer.from('bWlIb1lv', 'base64').toString()
},
lowercase:
@ -18,18 +19,28 @@ export class constants
}
};
public static readonly uri = {
api: `https://sdk-os-static.${this.placeholders.lowercase.company}.com/hk4e_global/mdk/launcher/api`,
patch: 'https://notabug.org/Krock/GI-on-Linux',
launcher: 'https://notabug.org/nobody/an-anime-game-launcher',
telemetry: [
`log-upload-os.${this.placeholders.lowercase.company}.com`,
'overseauspider.yuanshen.com'
]
};
public static readonly launcherDir: string = path.join(os.homedir(), '.local', 'share', 'anime-game-launcher');
public static readonly prefixDir: string = path.join(this.launcherDir, 'game');
public static readonly gameDir: string = path.join(this.prefixDir, 'drive_c', 'Program Files', this.gamePlaceholder.uppercase.full);
public static readonly gameDir: string = path.join(this.prefixDir, 'drive_c', 'Program Files', this.placeholders.uppercase.full);
public static readonly runnersDir: string = path.join(this.launcherDir, 'runners');
public static readonly dxvksDir: string = path.join(this.launcherDir, 'dxvks');
public static readonly versionsUri: string = `https://sdk-os-static.${this.gamePlaceholder.lowercase.company}.com/hk4e_global/mdk/launcher/api/resource?key=gcStgarh&launcher_id=10`;
public static readonly backgroundUri: string = `https://sdk-os-static.${this.gamePlaceholder.lowercase.company}.com/hk4e_global/mdk/launcher/api/content?filter_adv=true&launcher_id=10&language=`;
public static readonly versionsUri: string = `${this.uri.api}/resource?key=gcStgarh&launcher_id=10`;
public static readonly backgroundUri: string = `${this.uri.api}/content?filter_adv=true&launcher_id=10&language=`;
public static readonly patchUri: string = 'https://notabug.org/Krock/GI-on-Linux/archive/master.zip';
public static readonly patchUri: string = `${this.uri.patch}/archive/master.zip`;
public static readonly runnersUri: string = 'https://notabug.org/nobody/an-anime-game-launcher/raw/main/runners.json';
public static readonly dxvksUri: string = 'https://notabug.org/nobody/an-anime-game-launcher/raw/main/dxvks.json';
public static readonly runnersUri: string = `${this.uri.launcher}/raw/main/runners.json`;
public static readonly dxvksUri: string = `${this.uri.launcher}/raw/main/dxvks.json`;
}