Simplify game install cancellation. Cancels now happen silently and don't generate a dialog.
parent
bb980cc063
commit
1ede37c031
|
@ -49,9 +49,7 @@ namespace LANCommander.PlaynitePlugin
|
|||
{
|
||||
if (progress.CancelToken != null && progress.CancelToken.IsCancellationRequested)
|
||||
{
|
||||
e.Reader.Cancel();
|
||||
e.Reader.Dispose();
|
||||
e.Stream.Dispose();
|
||||
gameManager.CancelInstall();
|
||||
|
||||
progress.IsIndeterminate = true;
|
||||
}
|
||||
|
@ -78,6 +76,17 @@ namespace LANCommander.PlaynitePlugin
|
|||
|
||||
InvokeOnInstalled(new GameInstalledEventArgs(installInfo));
|
||||
}
|
||||
else if (result.Canceled)
|
||||
{
|
||||
var game = Plugin.PlayniteApi.Database.Games.Get(Game.Id);
|
||||
|
||||
game.IsInstalling = false;
|
||||
game.IsInstalled = false;
|
||||
|
||||
Plugin.PlayniteApi.Database.Games.Update(game);
|
||||
}
|
||||
else if (result.Error != null)
|
||||
throw result.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ namespace LANCommander.SDK
|
|||
|
||||
public class ArchiveEntryExtractionProgressArgs : EventArgs
|
||||
{
|
||||
public IReader Reader { get; set; }
|
||||
public TrackableStream Stream { get; set; }
|
||||
public ReaderProgress Progress { get; set; }
|
||||
public IEntry Entry { get; set; }
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@ namespace LANCommander.SDK
|
|||
public delegate void OnArchiveExtractionProgressHandler(long position, long length);
|
||||
public event OnArchiveExtractionProgressHandler OnArchiveExtractionProgress;
|
||||
|
||||
private TrackableStream Stream;
|
||||
private IReader Reader;
|
||||
|
||||
public GameManager(Client client, string defaultInstallDirectory)
|
||||
{
|
||||
Client = client;
|
||||
|
@ -61,7 +64,7 @@ namespace LANCommander.SDK
|
|||
if (!result.Success && !result.Canceled)
|
||||
throw new Exception("Could not extract the installer. Retry the install or check your connection");
|
||||
else if (result.Canceled)
|
||||
throw new Exception("Game install was canceled");
|
||||
return "";
|
||||
|
||||
GameManifest manifest = null;
|
||||
|
||||
|
@ -143,41 +146,62 @@ namespace LANCommander.SDK
|
|||
|
||||
Logger?.LogTrace("Downloading and extracting {Game} to path {Destination}", game.Title, destination);
|
||||
|
||||
var extractionResult = new ExtractionResult
|
||||
{
|
||||
Canceled = false,
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(destination);
|
||||
|
||||
using (var gameStream = Client.StreamGame(game.Id))
|
||||
using (var reader = ReaderFactory.Open(gameStream))
|
||||
{
|
||||
gameStream.OnProgress += (pos, len) =>
|
||||
Stream = Client.StreamGame(game.Id);
|
||||
Reader = ReaderFactory.Open(Stream);
|
||||
|
||||
Stream.OnProgress += (pos, len) =>
|
||||
{
|
||||
OnArchiveExtractionProgress?.Invoke(pos, len);
|
||||
};
|
||||
|
||||
reader.EntryExtractionProgress += (object sender, ReaderExtractionEventArgs<IEntry> e) =>
|
||||
Reader.EntryExtractionProgress += (object sender, ReaderExtractionEventArgs<IEntry> e) =>
|
||||
{
|
||||
OnArchiveEntryExtractionProgress?.Invoke(this, new ArchiveEntryExtractionProgressArgs
|
||||
{
|
||||
Entry = e.Item,
|
||||
Progress = e.ReaderProgress,
|
||||
Reader = reader,
|
||||
Stream = gameStream
|
||||
});
|
||||
};
|
||||
|
||||
reader.WriteAllToDirectory(destination, new ExtractionOptions()
|
||||
while (Reader.MoveToNextEntry())
|
||||
{
|
||||
if (Reader.Cancelled)
|
||||
break;
|
||||
|
||||
Reader.WriteEntryToDirectory(destination, new ExtractionOptions()
|
||||
{
|
||||
ExtractFullPath = true,
|
||||
Overwrite = true
|
||||
Overwrite = true,
|
||||
PreserveFileTime = true,
|
||||
});
|
||||
}
|
||||
|
||||
Reader.Dispose();
|
||||
Stream.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (false)
|
||||
if (Reader.Cancelled)
|
||||
{
|
||||
Logger?.LogTrace("User cancelled the download");
|
||||
|
||||
extractionResult.Canceled = true;
|
||||
|
||||
if (Directory.Exists(destination))
|
||||
{
|
||||
Logger?.LogTrace("Cleaning up orphaned files after cancelled install");
|
||||
|
||||
Directory.Delete(destination, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -194,11 +218,6 @@ namespace LANCommander.SDK
|
|||
}
|
||||
}
|
||||
|
||||
var extractionResult = new ExtractionResult
|
||||
{
|
||||
Canceled = false,
|
||||
};
|
||||
|
||||
if (!extractionResult.Canceled)
|
||||
{
|
||||
extractionResult.Success = true;
|
||||
|
@ -209,5 +228,12 @@ namespace LANCommander.SDK
|
|||
|
||||
return extractionResult;
|
||||
}
|
||||
|
||||
public void CancelInstall()
|
||||
{
|
||||
Reader?.Cancel();
|
||||
// Reader?.Dispose();
|
||||
// Stream?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,8 +126,6 @@ namespace LANCommander.SDK
|
|||
{
|
||||
Entry = e.Item,
|
||||
Progress = e.ReaderProgress,
|
||||
Reader = reader,
|
||||
Stream = redistributableStream
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue