Merge pull request #69 from mateuszskoczek/features/last_out_directory

saving directory feature added
This commit is contained in:
2024-03-07 22:13:09 +01:00
committed by GitHub
Unverified
5 changed files with 42 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using VDownload.Models; using VDownload.Models;
using VDownload.Services.Data.Application;
using VDownload.Services.Data.Settings; using VDownload.Services.Data.Settings;
using VDownload.Services.UI.StoragePicker; using VDownload.Services.UI.StoragePicker;
using VDownload.Services.Utility.Filename; using VDownload.Services.Utility.Filename;
@@ -21,6 +22,7 @@ namespace VDownload.Core.ViewModels.Home.Helpers
protected readonly ISettingsService _settingsService; protected readonly ISettingsService _settingsService;
protected readonly IStoragePickerService _storagePickerService; protected readonly IStoragePickerService _storagePickerService;
protected readonly IFilenameService _filenameService; protected readonly IFilenameService _filenameService;
protected readonly IApplicationDataService _applicationDataService;
#endregion #endregion
@@ -82,11 +84,12 @@ namespace VDownload.Core.ViewModels.Home.Helpers
#region CONSTRUCTORS #region CONSTRUCTORS
public VideoViewModel(Video video, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService) public VideoViewModel(Video video, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, IApplicationDataService applicationDataService)
{ {
_settingsService = settingsService; _settingsService = settingsService;
_storagePickerService = storagePickerService; _storagePickerService = storagePickerService;
_filenameService = filenameService; _filenameService = filenameService;
_applicationDataService = applicationDataService;
Video = video; Video = video;
@@ -102,10 +105,18 @@ namespace VDownload.Core.ViewModels.Home.Helpers
MediaType = _settingsService.Data.Common.Tasks.DefaultMediaType; MediaType = _settingsService.Data.Common.Tasks.DefaultMediaType;
TrimStart = TimeSpan.Zero; TrimStart = TimeSpan.Zero;
TrimEnd = Duration; TrimEnd = Duration;
DirectoryPath = _settingsService.Data.Common.Tasks.DefaultOutputDirectory;
Filename = _filenameService.CreateFilename(_settingsService.Data.Common.Tasks.FilenameTemplate, video); Filename = _filenameService.CreateFilename(_settingsService.Data.Common.Tasks.FilenameTemplate, video);
VideoExtension = _settingsService.Data.Common.Tasks.DefaultVideoExtension; VideoExtension = _settingsService.Data.Common.Tasks.DefaultVideoExtension;
AudioExtension = _settingsService.Data.Common.Tasks.DefaultAudioExtension; AudioExtension = _settingsService.Data.Common.Tasks.DefaultAudioExtension;
if (_settingsService.Data.Common.Tasks.SaveLastOutputDirectory && !string.IsNullOrWhiteSpace(_applicationDataService.Data.Common.LastOutputDirectory))
{
DirectoryPath = _applicationDataService.Data.Common.LastOutputDirectory;
}
else
{
DirectoryPath = _settingsService.Data.Common.Tasks.DefaultOutputDirectory;
}
} }
#endregion #endregion
@@ -141,6 +152,9 @@ namespace VDownload.Core.ViewModels.Home.Helpers
if (newDirectory is not null) if (newDirectory is not null)
{ {
this.DirectoryPath = newDirectory; this.DirectoryPath = newDirectory;
_applicationDataService.Data.Common.LastOutputDirectory = newDirectory;
await _applicationDataService.Save();
} }
} }

View File

@@ -20,6 +20,7 @@ using VDownload.Services.Utility.Filename;
using VDownload.Services.UI.Dialogs; using VDownload.Services.UI.Dialogs;
using VDownload.Services.UI.StringResources; using VDownload.Services.UI.StringResources;
using CommunityToolkit.WinUI.Helpers; using CommunityToolkit.WinUI.Helpers;
using VDownload.Services.Data.Application;
namespace VDownload.Core.ViewModels.Home namespace VDownload.Core.ViewModels.Home
{ {
@@ -34,6 +35,7 @@ namespace VDownload.Core.ViewModels.Home
protected readonly IFilenameService _filenameService; protected readonly IFilenameService _filenameService;
protected readonly IDialogsService _dialogsService; protected readonly IDialogsService _dialogsService;
protected readonly IStringResourcesService _stringResourcesService; protected readonly IStringResourcesService _stringResourcesService;
protected readonly IApplicationDataService _applicationDataService;
#endregion #endregion
@@ -179,7 +181,7 @@ namespace VDownload.Core.ViewModels.Home
#region CONSTRUCTORS #region CONSTRUCTORS
public HomePlaylistViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, IDialogsService dialogsService, IStringResourcesService stringResourcesService) public HomePlaylistViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, IDialogsService dialogsService, IStringResourcesService stringResourcesService, IApplicationDataService applicationDataService)
{ {
_tasksManager = tasksManager; _tasksManager = tasksManager;
_settingsService = settingsService; _settingsService = settingsService;
@@ -187,6 +189,7 @@ namespace VDownload.Core.ViewModels.Home
_filenameService = filenameService; _filenameService = filenameService;
_dialogsService = dialogsService; _dialogsService = dialogsService;
_stringResourcesService = stringResourcesService; _stringResourcesService = stringResourcesService;
_applicationDataService = applicationDataService;
_removedVideos = new List<VideoViewModel>(); _removedVideos = new List<VideoViewModel>();
@@ -231,7 +234,7 @@ namespace VDownload.Core.ViewModels.Home
Videos.Clear(); Videos.Clear();
foreach (Video video in playlist) foreach (Video video in playlist)
{ {
Videos.Add(new VideoViewModel(video, _settingsService, _storagePickerService, _filenameService), true); Videos.Add(new VideoViewModel(video, _settingsService, _storagePickerService, _filenameService, _applicationDataService), true);
} }
UpdateFilter(); UpdateFilter();
} }
@@ -252,6 +255,9 @@ namespace VDownload.Core.ViewModels.Home
{ {
video.DirectoryPath = newDirectory; video.DirectoryPath = newDirectory;
} }
_applicationDataService.Data.Common.LastOutputDirectory = newDirectory;
await _applicationDataService.Save();
} }
} }

View File

@@ -10,6 +10,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using VDownload.Core.Tasks; using VDownload.Core.Tasks;
using VDownload.Models; using VDownload.Models;
using VDownload.Services.Data.Application;
using VDownload.Services.Data.Settings; using VDownload.Services.Data.Settings;
using VDownload.Services.UI.Dialogs; using VDownload.Services.UI.Dialogs;
using VDownload.Services.UI.StoragePicker; using VDownload.Services.UI.StoragePicker;
@@ -29,6 +30,7 @@ namespace VDownload.Core.ViewModels.Home
protected readonly IFilenameService _filenameService; protected readonly IFilenameService _filenameService;
protected readonly IDialogsService _dialogsService; protected readonly IDialogsService _dialogsService;
protected readonly IStringResourcesService _stringResourcesService; protected readonly IStringResourcesService _stringResourcesService;
protected readonly IApplicationDataService _applicationDataService;
#endregion #endregion
@@ -96,7 +98,7 @@ namespace VDownload.Core.ViewModels.Home
#region CONSTRUCTORS #region CONSTRUCTORS
public HomeVideoViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, IDialogsService dialogsService, IStringResourcesService stringResourcesService) public HomeVideoViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, IDialogsService dialogsService, IStringResourcesService stringResourcesService, IApplicationDataService applicationDataService)
{ {
_tasksManager = tasksManager; _tasksManager = tasksManager;
_settingsService = settingsService; _settingsService = settingsService;
@@ -104,6 +106,7 @@ namespace VDownload.Core.ViewModels.Home
_filenameService = filenameService; _filenameService = filenameService;
_dialogsService = dialogsService; _dialogsService = dialogsService;
_stringResourcesService = stringResourcesService; _stringResourcesService = stringResourcesService;
_applicationDataService = applicationDataService;
} }
#endregion #endregion
@@ -130,10 +133,18 @@ namespace VDownload.Core.ViewModels.Home
MediaType = _settingsService.Data.Common.Tasks.DefaultMediaType; MediaType = _settingsService.Data.Common.Tasks.DefaultMediaType;
TrimStart = TimeSpan.Zero; TrimStart = TimeSpan.Zero;
TrimEnd = Duration; TrimEnd = Duration;
DirectoryPath = _settingsService.Data.Common.Tasks.DefaultOutputDirectory;
Filename = _filenameService.CreateFilename(_settingsService.Data.Common.Tasks.FilenameTemplate, video); Filename = _filenameService.CreateFilename(_settingsService.Data.Common.Tasks.FilenameTemplate, video);
VideoExtension = _settingsService.Data.Common.Tasks.DefaultVideoExtension; VideoExtension = _settingsService.Data.Common.Tasks.DefaultVideoExtension;
AudioExtension = _settingsService.Data.Common.Tasks.DefaultAudioExtension; AudioExtension = _settingsService.Data.Common.Tasks.DefaultAudioExtension;
if (_settingsService.Data.Common.Tasks.SaveLastOutputDirectory && !string.IsNullOrWhiteSpace(_applicationDataService.Data.Common.LastOutputDirectory))
{
DirectoryPath = _applicationDataService.Data.Common.LastOutputDirectory;
}
else
{
DirectoryPath = _settingsService.Data.Common.Tasks.DefaultOutputDirectory;
}
} }
@@ -144,6 +155,9 @@ namespace VDownload.Core.ViewModels.Home
if (newDirectory is not null) if (newDirectory is not null)
{ {
this.DirectoryPath = newDirectory; this.DirectoryPath = newDirectory;
_applicationDataService.Data.Common.LastOutputDirectory = newDirectory;
await _applicationDataService.Save();
} }
} }

View File

@@ -19,6 +19,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Application\VDownload.Services.Data.Application.csproj" />
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Settings\VDownload.Services.Data.Settings.csproj" /> <ProjectReference Include="..\..\VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Settings\VDownload.Services.Data.Settings.csproj" />
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services.UI\VDownload.Services.UI.Dialogs\VDownload.Services.UI.Dialogs.csproj" /> <ProjectReference Include="..\..\VDownload.Services\VDownload.Services.UI\VDownload.Services.UI.Dialogs\VDownload.Services.UI.Dialogs.csproj" />
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services.UI\VDownload.Services.UI.DictionaryResources\VDownload.Services.UI.DictionaryResources.csproj" /> <ProjectReference Include="..\..\VDownload.Services\VDownload.Services.UI\VDownload.Services.UI.DictionaryResources\VDownload.Services.UI.DictionaryResources.csproj" />

View File

@@ -10,6 +10,6 @@ namespace VDownload.Services.Data.Application
public class ApplicationData public class ApplicationData
{ {
[JsonProperty("common")] [JsonProperty("common")]
public CommonApplicationData Common { get; set; } public CommonApplicationData Common { get; set; } = new CommonApplicationData();
} }
} }