diff --git a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/ApplicationData.cs b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/ApplicationData.cs new file mode 100644 index 0000000..657923e --- /dev/null +++ b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/ApplicationData.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VDownload.Services.Data.Application +{ + public class ApplicationData + { + [JsonProperty("common")] + public CommonApplicationData Common { get; set; } + } +} diff --git a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/ApplicationDataService.cs b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/ApplicationDataService.cs new file mode 100644 index 0000000..9684b3a --- /dev/null +++ b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/ApplicationDataService.cs @@ -0,0 +1,104 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VDownload.Services.Data.Configuration; + +namespace VDownload.Services.Data.Application +{ + public interface IApplicationDataService + { + #region PROPERTIES + + ApplicationData Data { get; } + + #endregion + + + + #region METHODS + + Task Load(); + Task Restore(); + Task Save(); + + #endregion + } + + + + public class ApplicationDataService : IApplicationDataService + { + #region SERVICES + + protected readonly IConfigurationService _configurationService; + + #endregion + + + + #region FIELDS + + protected readonly string _filePath; + + #endregion + + + + #region PROPERTIES + + public ApplicationData Data { get; private set; } + + #endregion + + + + #region CONSTRUCTORS + + public ApplicationDataService(IConfigurationService configurationService) + { + _configurationService = configurationService; + + string appdataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + string appdataDirectoryName = _configurationService.Common.Path.Appdata.DirectoryName; + string appdataAuthenticationFilename = _configurationService.Common.Path.Appdata.SettingsFile; + _filePath = Path.Combine(appdataPath, appdataDirectoryName, appdataAuthenticationFilename); + } + + #endregion + + + + #region PUBLIC METHODS + + public async Task Load() + { + if (File.Exists(_filePath)) + { + string content = await File.ReadAllTextAsync(_filePath); + Data = JsonConvert.DeserializeObject(content); + } + else + { + Data = new ApplicationData(); + } + } + + public async Task Save() + { + Directory.CreateDirectory(Path.GetDirectoryName(_filePath)); + string content = JsonConvert.SerializeObject(Data); + await File.WriteAllTextAsync(_filePath, content); + } + + public async Task Restore() + { + Data = new ApplicationData(); + await Save(); + } + + #endregion + } +} diff --git a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/CommonApplicationData.cs b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/CommonApplicationData.cs new file mode 100644 index 0000000..6898866 --- /dev/null +++ b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/CommonApplicationData.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VDownload.Services.Data.Application +{ + public class CommonApplicationData + { + [JsonProperty("last_output_directory")] + public string? LastOutputDirectory { get; set; } = null; + } +} diff --git a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/VDownload.Services.Data.Application.csproj b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/VDownload.Services.Data.Application.csproj new file mode 100644 index 0000000..8b38c4b --- /dev/null +++ b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Application/VDownload.Services.Data.Application.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Configuration/Models/Appdata.cs b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Configuration/Models/Appdata.cs index 36d6340..f8dbfd4 100644 --- a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Configuration/Models/Appdata.cs +++ b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Configuration/Models/Appdata.cs @@ -18,5 +18,8 @@ namespace VDownload.Services.Data.Configuration.Models [ConfigurationKeyName("settings_file")] public string SettingsFile { get; set; } + + [ConfigurationKeyName("data_file")] + public string DataFile { get; set; } } } diff --git a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Settings/SettingsService.cs b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Settings/SettingsService.cs index 164bad4..2d83230 100644 --- a/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Settings/SettingsService.cs +++ b/VDownload.Services/VDownload.Services.Data/VDownload.Services.Data.Settings/SettingsService.cs @@ -63,7 +63,7 @@ namespace VDownload.Services.Data.Settings string appdataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string appdataDirectoryName = _configurationService.Common.Path.Appdata.DirectoryName; - string appdataAuthenticationFilename = _configurationService.Common.Path.Appdata.SettingsFile; + string appdataAuthenticationFilename = _configurationService.Common.Path.Appdata.DataFile; _filePath = Path.Combine(appdataPath, appdataDirectoryName, appdataAuthenticationFilename); } diff --git a/VDownload.sln b/VDownload.sln index f4a954f..f7c7683 100644 --- a/VDownload.sln +++ b/VDownload.sln @@ -71,6 +71,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VDownload.Services.Utility. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VDownload.Services.Utility.Filename", "VDownload.Services\VDownload.Services.Utility\VDownload.Services.Utility.Filename\VDownload.Services.Utility.Filename.csproj", "{4647EFB5-A206-4F47-976D-BAED11B52579}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VDownload.Services.Data.Application", "VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Application\VDownload.Services.Data.Application.csproj", "{4983E15B-3730-4646-A2BD-16B9ECC9E4FF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -521,6 +523,22 @@ Global {4647EFB5-A206-4F47-976D-BAED11B52579}.Release|x64.Build.0 = Release|Any CPU {4647EFB5-A206-4F47-976D-BAED11B52579}.Release|x86.ActiveCfg = Release|Any CPU {4647EFB5-A206-4F47-976D-BAED11B52579}.Release|x86.Build.0 = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|ARM64.Build.0 = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|x64.ActiveCfg = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|x64.Build.0 = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|x86.ActiveCfg = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Debug|x86.Build.0 = Debug|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|Any CPU.Build.0 = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|ARM64.ActiveCfg = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|ARM64.Build.0 = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|x64.ActiveCfg = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|x64.Build.0 = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|x86.ActiveCfg = Release|Any CPU + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -555,6 +573,7 @@ Global {3BE998A3-1126-4496-BF60-80D0CEA4D24F} = {8539067C-9968-4AEB-928C-FEDC43989A79} {A3166F8A-ECAD-4D4B-9BE3-96FEC799B27B} = {1020167A-4101-496E-82CF-41B65769DD28} {4647EFB5-A206-4F47-976D-BAED11B52579} = {1020167A-4101-496E-82CF-41B65769DD28} + {4983E15B-3730-4646-A2BD-16B9ECC9E4FF} = {05A45688-7EEF-4656-818A-2477625C3707} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9FD7B842-C3E2-4FD0-AD8A-C8E619280AB7} diff --git a/VDownload/App.xaml.cs b/VDownload/App.xaml.cs index 1ae468d..73351e5 100644 --- a/VDownload/App.xaml.cs +++ b/VDownload/App.xaml.cs @@ -16,6 +16,7 @@ using VDownload.Core.Views.About; using VDownload.Core.Views.Authentication; using VDownload.Core.Views.Home; using VDownload.Core.Views.Settings; +using VDownload.Services.Data.Application; using VDownload.Services.Data.Authentication; using VDownload.Services.Data.Configuration; using VDownload.Services.Data.Configuration.Models; @@ -106,6 +107,7 @@ namespace VDownload services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); } protected void BuildUIServices(IServiceCollection services) @@ -180,9 +182,10 @@ namespace VDownload protected async Task InitData() { + IApplicationDataService applicationDataService = _serviceProvider.GetService(); ISettingsService settingsService = _serviceProvider.GetService(); IAuthenticationDataService authenticationDataService = _serviceProvider.GetService(); - await Task.WhenAll(settingsService.Load(), authenticationDataService.Load()); + await Task.WhenAll(applicationDataService.Load(), settingsService.Load(), authenticationDataService.Load()); } protected void AssignStaticProperties() diff --git a/VDownload/VDownload.csproj b/VDownload/VDownload.csproj index c52bd40..47f4796 100644 --- a/VDownload/VDownload.csproj +++ b/VDownload/VDownload.csproj @@ -188,6 +188,7 @@ + diff --git a/VDownload/configuration.json b/VDownload/configuration.json index 3d9223b..b412757 100644 --- a/VDownload/configuration.json +++ b/VDownload/configuration.json @@ -146,7 +146,8 @@ "appdata": { "directory_name": "VDownload", "authentication_file": "authentication.json", - "settings_file": "settings.json" + "settings_file": "settings.json", + "data_file": "data.json" }, "temp": { "tasks_directory": "tasks"