fixes, errors handling
This commit is contained in:
@@ -117,6 +117,21 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="DialogErrorMessageNoInternetConnection" xml:space="preserve">
|
||||
<value>No internet connection. Try again later.</value>
|
||||
</data>
|
||||
<data name="DialogErrorTitle" xml:space="preserve">
|
||||
<value>Error</value>
|
||||
</data>
|
||||
<data name="ErrorDownloadingTimeout" xml:space="preserve">
|
||||
<value>Downloading timeout. Check your internet connection and try again later.</value>
|
||||
</data>
|
||||
<data name="ErrorFFmpeg" xml:space="preserve">
|
||||
<value>FFmpeg exited with error.</value>
|
||||
</data>
|
||||
<data name="ErrorFFmpegPath" xml:space="preserve">
|
||||
<value>No FFmpeg executables found. Check path in settings and try again.</value>
|
||||
</data>
|
||||
<data name="StatusCancelled.Text" xml:space="preserve">
|
||||
<value>Cancelled</value>
|
||||
</data>
|
||||
|
||||
@@ -13,6 +13,9 @@ using System.IO;
|
||||
using VDownload.Services.UI.Notifications;
|
||||
using VDownload.Services.UI.StringResources;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using Instances.Exceptions;
|
||||
using FFMpegCore.Exceptions;
|
||||
|
||||
namespace VDownload.Core.Tasks
|
||||
{
|
||||
@@ -140,7 +143,11 @@ namespace VDownload.Core.Tasks
|
||||
|
||||
await _settingsService.Load();
|
||||
|
||||
string tempDirectory = $"{_settingsService.Data.Common.Temp.Directory}\\{_configurationService.Common.Path.Temp.TasksDirectory}\\{Id}";
|
||||
string tempDirectory = $"{_settingsService.Data.Common.Temp.Directory}\\{_configurationService.Common.Path.Temp.TasksDirectory}\\{Guid.NewGuid()}";
|
||||
if (Directory.Exists(tempDirectory))
|
||||
{
|
||||
Directory.Delete(tempDirectory, true);
|
||||
}
|
||||
Directory.CreateDirectory(tempDirectory);
|
||||
|
||||
List<string> content = new List<string>()
|
||||
@@ -180,10 +187,11 @@ namespace VDownload.Core.Tasks
|
||||
.JoinProgressReporter(onProgressProcessing, downloadResult.NewDuration);
|
||||
await ffmpegBuilder.RunAsync(downloadResult.File, outputPath);
|
||||
|
||||
StorageFile outputFile = await StorageFile.GetFileFromPathAsync(outputPath);
|
||||
|
||||
UpdateStatusWithDispatcher(DownloadTaskStatus.Finalizing);
|
||||
|
||||
string destination = $"{DownloadOptions.Directory}\\{DownloadOptions.Filename}.{DownloadOptions.Extension}";
|
||||
File.Copy(outputPath, destination, true);
|
||||
await Finalizing(outputFile);
|
||||
|
||||
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedSuccessfully);
|
||||
|
||||
@@ -199,7 +207,26 @@ namespace VDownload.Core.Tasks
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateErrorWithDispatcher(ex.Message);
|
||||
string message;
|
||||
|
||||
if (ex is TaskCanceledException || ex is HttpRequestException)
|
||||
{
|
||||
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorDownloadingTimeout");
|
||||
}
|
||||
else if (ex is InstanceFileNotFoundException)
|
||||
{
|
||||
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorFFmpegPath");
|
||||
}
|
||||
else if (ex is FFMpegException)
|
||||
{
|
||||
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorFFmpeg");
|
||||
}
|
||||
else
|
||||
{
|
||||
message = ex.Message;
|
||||
}
|
||||
|
||||
UpdateErrorWithDispatcher(message);
|
||||
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedUnsuccessfully);
|
||||
|
||||
if (_settingsService.Data.Common.Notifications.OnUnsuccessful)
|
||||
@@ -218,11 +245,19 @@ namespace VDownload.Core.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStatusWithDispatcher(DownloadTaskStatus status) => _dispatcherQueue.TryEnqueue(() => Status = status);
|
||||
protected async Task Finalizing(StorageFile outputFile)
|
||||
{
|
||||
StorageFolder destination = await StorageFolder.GetFolderFromPathAsync(DownloadOptions.Directory);
|
||||
|
||||
private void UpdateProgressWithDispatcher(double progress) => _dispatcherQueue.TryEnqueue(() => Progress = progress);
|
||||
string filename = $"{DownloadOptions.Filename}.{DownloadOptions.Extension}";
|
||||
await outputFile.CopyAsync(destination, filename, NameCollisionOption.ReplaceExisting);
|
||||
}
|
||||
|
||||
private void UpdateErrorWithDispatcher(string message) => _dispatcherQueue.TryEnqueue(() => Error = message);
|
||||
protected void UpdateStatusWithDispatcher(DownloadTaskStatus status) => _dispatcherQueue.TryEnqueue(() => Status = status);
|
||||
|
||||
protected void UpdateProgressWithDispatcher(double progress) => _dispatcherQueue.TryEnqueue(() => Progress = progress);
|
||||
|
||||
protected void UpdateErrorWithDispatcher(string message) => _dispatcherQueue.TryEnqueue(() => Error = message);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -68,6 +68,14 @@ namespace VDownload.Core.ViewModels.Home
|
||||
];
|
||||
if (idleStatuses.Contains(task.Status))
|
||||
{
|
||||
if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable)
|
||||
{
|
||||
string title = _stringResourcesService.HomeDownloadsViewResources.Get("DialogErrorTitle");
|
||||
string message = _stringResourcesService.HomeDownloadsViewResources.Get("DialogErrorMessageNoInternetConnection");
|
||||
await _dialogsService.ShowOk(title, message);
|
||||
return;
|
||||
}
|
||||
|
||||
bool continueEnqueue = true;
|
||||
if (NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user