Add progress dialog for extracting. Mark game as installed after extraction.
parent
ffc51f4e0d
commit
cf326dd5ca
|
@ -34,7 +34,13 @@ namespace LANCommander.Playnite.Extension
|
|||
|
||||
var tempFile = Download(game);
|
||||
|
||||
Extract(game, tempFile);
|
||||
var installDirectory = Extract(game, tempFile);
|
||||
var installInfo = new GameInstallationData()
|
||||
{
|
||||
InstallDirectory = installDirectory
|
||||
};
|
||||
|
||||
InvokeOnInstalled(new GameInstalledEventArgs(installInfo));
|
||||
}
|
||||
|
||||
private string Download(LANCommander.SDK.Models.Game game)
|
||||
|
@ -45,7 +51,7 @@ namespace LANCommander.Playnite.Extension
|
|||
|
||||
if (archive != null)
|
||||
{
|
||||
var result = Plugin.PlayniteApi.Dialogs.ActivateGlobalProgress(progress =>
|
||||
Plugin.PlayniteApi.Dialogs.ActivateGlobalProgress(progress =>
|
||||
{
|
||||
progress.ProgressMaxValue = 100;
|
||||
progress.CurrentProgressValue = 0;
|
||||
|
@ -58,6 +64,7 @@ namespace LANCommander.Playnite.Extension
|
|||
progress.CurrentProgressValue = 100;
|
||||
});
|
||||
|
||||
// Lock the thread until download is done
|
||||
while (progress.CurrentProgressValue != 100)
|
||||
{
|
||||
|
||||
|
@ -65,7 +72,7 @@ namespace LANCommander.Playnite.Extension
|
|||
|
||||
tempFile = destination;
|
||||
},
|
||||
new GlobalProgressOptions($"Downloading {game.Title}")
|
||||
new GlobalProgressOptions($"Downloading {game.Title}...")
|
||||
{
|
||||
IsIndeterminate = false,
|
||||
Cancelable = false,
|
||||
|
@ -77,10 +84,12 @@ namespace LANCommander.Playnite.Extension
|
|||
throw new Exception("Game failed to download");
|
||||
}
|
||||
|
||||
private void Extract(LANCommander.SDK.Models.Game game, string archivePath)
|
||||
private string Extract(LANCommander.SDK.Models.Game game, string archivePath)
|
||||
{
|
||||
var destination = $"C:\\Games\\{game.Title.SanitizeFilename()}";
|
||||
|
||||
Plugin.PlayniteApi.Dialogs.ActivateGlobalProgress(progress =>
|
||||
{
|
||||
ZipFile file = null;
|
||||
|
||||
try
|
||||
|
@ -89,6 +98,8 @@ namespace LANCommander.Playnite.Extension
|
|||
|
||||
file = new ZipFile(fs);
|
||||
|
||||
progress.ProgressMaxValue = file.Count;
|
||||
|
||||
foreach (ZipEntry entry in file)
|
||||
{
|
||||
if (!entry.IsFile)
|
||||
|
@ -107,6 +118,8 @@ namespace LANCommander.Playnite.Extension
|
|||
{
|
||||
StreamUtils.Copy(zipStream, streamWriter, buffer);
|
||||
}
|
||||
|
||||
progress.CurrentProgressValue = entry.ZipFileIndex;
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@ -119,6 +132,14 @@ namespace LANCommander.Playnite.Extension
|
|||
|
||||
File.Delete(archivePath);
|
||||
}
|
||||
},
|
||||
new GlobalProgressOptions($"Extracting {game.Title}...")
|
||||
{
|
||||
IsIndeterminate = false,
|
||||
Cancelable = false,
|
||||
});
|
||||
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue