mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-30 05:28:15 +03:00
Improved Launcher.state.update()
method performance
This commit is contained in:
parent
ee66769cb1
commit
66f852ddea
1 changed files with 94 additions and 79 deletions
|
@ -180,7 +180,6 @@ export default class State
|
||||||
let state: LauncherState|null = null;
|
let state: LauncherState|null = null;
|
||||||
|
|
||||||
const runner = await Runners.current();
|
const runner = await Runners.current();
|
||||||
const dxvk = await DXVK.current();
|
|
||||||
|
|
||||||
// Check if the wine is installed
|
// Check if the wine is installed
|
||||||
if (runner === null)
|
if (runner === null)
|
||||||
|
@ -216,93 +215,109 @@ export default class State
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the DXVK is installed
|
else
|
||||||
else if (dxvk === null)
|
|
||||||
{
|
{
|
||||||
debugThread.log('DXVK is not specified');
|
const dxvk = await DXVK.current();
|
||||||
|
|
||||||
state = 'dxvk-installation-required';
|
// Check if the DXVK is installed
|
||||||
|
if (dxvk === null)
|
||||||
DXVK.list().then((list) => {
|
|
||||||
for (const dxvk of list)
|
|
||||||
if (dxvk.installed && dxvk.recommended)
|
|
||||||
{
|
|
||||||
debugThread.log(`Automatically selected DXVK ${dxvk.version}`);
|
|
||||||
|
|
||||||
state = null;
|
|
||||||
|
|
||||||
DXVK.current(dxvk).then(() => {
|
|
||||||
this.update().then(resolve);
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (state !== null)
|
|
||||||
{
|
{
|
||||||
debugThread.log('No recommended DXVK installed');
|
debugThread.log('DXVK is not specified');
|
||||||
|
|
||||||
|
state = 'dxvk-installation-required';
|
||||||
|
|
||||||
|
DXVK.list().then((list) => {
|
||||||
|
for (const dxvk of list)
|
||||||
|
if (dxvk.installed && dxvk.recommended)
|
||||||
|
{
|
||||||
|
debugThread.log(`Automatically selected DXVK ${dxvk.version}`);
|
||||||
|
|
||||||
|
state = null;
|
||||||
|
|
||||||
|
DXVK.current(dxvk).then(() => {
|
||||||
|
this.update().then(resolve);
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (state !== null)
|
||||||
|
{
|
||||||
|
debugThread.log('No recommended DXVK installed');
|
||||||
|
|
||||||
|
this.set(state);
|
||||||
|
|
||||||
|
resolve(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise select some launcher state
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const gameCurrent = await Game.current;
|
||||||
|
|
||||||
|
if (gameCurrent === null)
|
||||||
|
state = 'game-installation-available';
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const gameLatest = await Game.getLatestData();
|
||||||
|
|
||||||
|
if (gameCurrent != gameLatest.game.latest.version)
|
||||||
|
state = 'game-update-available';
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const installedVoices = await Voice.installed;
|
||||||
|
const selectedVoices = await Voice.selected;
|
||||||
|
|
||||||
|
let voiceUpdateRequired = installedVoices.length != selectedVoices.length || installedVoices.length === 0;
|
||||||
|
|
||||||
|
if (!voiceUpdateRequired)
|
||||||
|
{
|
||||||
|
for (const installedVoice of installedVoices)
|
||||||
|
if (installedVoice.version != gameCurrent || !selectedVoices.includes(installedVoice.lang))
|
||||||
|
{
|
||||||
|
voiceUpdateRequired = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: download default voice language if user removed all of them
|
||||||
|
if (voiceUpdateRequired)
|
||||||
|
state = 'game-voice-update-required';
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const patch = await Patch.latest;
|
||||||
|
|
||||||
|
if (!patch.applied)
|
||||||
|
{
|
||||||
|
state = patch.state == 'preparation' ?
|
||||||
|
'patch-unavailable' : (patch.state == 'testing' ?
|
||||||
|
'test-patch-available' : 'patch-available');
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (gameLatest.pre_download_game && !await Game.isUpdatePredownloaded())
|
||||||
|
state = 'game-pre-installation-available';
|
||||||
|
|
||||||
|
else if (gameLatest.pre_download_game && !await Voice.isUpdatePredownloaded(await Voice.selected))
|
||||||
|
state = 'game-voice-pre-installation-available';
|
||||||
|
|
||||||
|
else state = 'game-launch-available';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debugThread.log(`Updated state: ${state}`);
|
||||||
|
|
||||||
this.set(state);
|
this.set(state);
|
||||||
|
|
||||||
resolve(state);
|
resolve(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise select some launcher state
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const gameCurrent = await Game.current;
|
|
||||||
const gameLatest = await Game.getLatestData();
|
|
||||||
const patch = await Patch.latest;
|
|
||||||
|
|
||||||
const installedVoices = await Voice.installed;
|
|
||||||
const selectedVoices = await Voice.selected;
|
|
||||||
|
|
||||||
let voiceUpdateRequired = installedVoices.length != selectedVoices.length || installedVoices.length === 0;
|
|
||||||
|
|
||||||
if (!voiceUpdateRequired)
|
|
||||||
{
|
|
||||||
for (const installedVoice of installedVoices)
|
|
||||||
if (installedVoice.version != gameCurrent || !selectedVoices.includes(installedVoice.lang))
|
|
||||||
{
|
|
||||||
voiceUpdateRequired = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gameCurrent === null)
|
|
||||||
state = 'game-installation-available';
|
|
||||||
|
|
||||||
else if (gameCurrent != gameLatest.game.latest.version)
|
|
||||||
state = 'game-update-available';
|
|
||||||
|
|
||||||
// TODO: download default voice language if user removed all of them
|
|
||||||
else if (voiceUpdateRequired)
|
|
||||||
state = 'game-voice-update-required';
|
|
||||||
|
|
||||||
else if (!patch.applied)
|
|
||||||
{
|
|
||||||
state = patch.state == 'preparation' ?
|
|
||||||
'patch-unavailable' : (patch.state == 'testing' ?
|
|
||||||
'test-patch-available' : 'patch-available');
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (gameLatest.pre_download_game && !await Game.isUpdatePredownloaded())
|
|
||||||
state = 'game-pre-installation-available';
|
|
||||||
|
|
||||||
else if (gameLatest.pre_download_game && !await Voice.isUpdatePredownloaded(await Voice.selected))
|
|
||||||
state = 'game-voice-pre-installation-available';
|
|
||||||
|
|
||||||
else state = 'game-launch-available';
|
|
||||||
|
|
||||||
debugThread.log(`Updated state: ${state}`);
|
|
||||||
|
|
||||||
this.set(state);
|
|
||||||
|
|
||||||
resolve(state);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue