Merge pull request #67 from mateuszskoczek/features/application_data
appdata added
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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<ApplicationData>(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
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VDownload.Services.Data.Configuration\VDownload.Services.Data.Configuration.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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<IConfigurationService, ConfigurationService>();
|
||||
services.AddSingleton<IAuthenticationDataService, AuthenticationDataService>();
|
||||
services.AddSingleton<ISettingsService, SettingsService>();
|
||||
services.AddSingleton<IApplicationDataService, ApplicationDataService>();
|
||||
}
|
||||
|
||||
protected void BuildUIServices(IServiceCollection services)
|
||||
@@ -180,9 +182,10 @@ namespace VDownload
|
||||
|
||||
protected async Task InitData()
|
||||
{
|
||||
IApplicationDataService applicationDataService = _serviceProvider.GetService<IApplicationDataService>();
|
||||
ISettingsService settingsService = _serviceProvider.GetService<ISettingsService>();
|
||||
IAuthenticationDataService authenticationDataService = _serviceProvider.GetService<IAuthenticationDataService>();
|
||||
await Task.WhenAll(settingsService.Load(), authenticationDataService.Load());
|
||||
await Task.WhenAll(applicationDataService.Load(), settingsService.Load(), authenticationDataService.Load());
|
||||
}
|
||||
|
||||
protected void AssignStaticProperties()
|
||||
|
||||
@@ -188,6 +188,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VDownload.Core\VDownload.Core.ViewModels\VDownload.Core.ViewModels.csproj" />
|
||||
<ProjectReference Include="..\VDownload.Core\VDownload.Core.Views\VDownload.Core.Views.csproj" />
|
||||
<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.Authentication\VDownload.Services.Data.Authentication.csproj" />
|
||||
<ProjectReference Include="..\VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Configuration\VDownload.Services.Data.Configuration.csproj" />
|
||||
<ProjectReference Include="..\VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Settings\VDownload.Services.Data.Settings.csproj" />
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user