Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszskoczek committed Mar 15, 2024
1 parent 8ff6071 commit c4710b5
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 151 deletions.
8 changes: 6 additions & 2 deletions VDownload.Core/VDownload.Core.Strings/StringResource.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Microsoft.Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace VDownload.Core.Strings
{
Expand All @@ -30,7 +31,10 @@ internal StringResource(ResourceLoader resourceLoader)

#region PUBLIC METHODS

public string Get(string key) => _resourceLoader.GetString(key);
public string Get(string key)
{
return _resourceLoader.GetString(key);
}

#endregion
}
Expand Down
17 changes: 15 additions & 2 deletions VDownload.Core/VDownload.Core.Strings/StringResourcesManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Microsoft.UI.Xaml;
using Microsoft.Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace VDownload.Core.Strings
{
Expand Down Expand Up @@ -35,7 +36,19 @@ public static class StringResourcesManager

private static StringResource BuildResource(string resourceName)
{
ResourceLoader loader = new ResourceLoader(resourceName);
File.AppendAllText("C:\\Users\\mateusz\\Desktop\\test.txt", $"teststring {resourceName}\n");
ResourceLoader loader;
try
{
loader = new ResourceLoader($"VDownload.Core.Strings/{resourceName}");
File.AppendAllText("C:\\Users\\mateusz\\Desktop\\test.txt", $"afterteststring {resourceName}\n");
}
catch (Exception e)
{

File.AppendAllText("C:\\Users\\mateusz\\Desktop\\test.txt", $"teststringerror {e.Message}\n");
throw;
}
return new StringResource(loader);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,48 @@
</ItemGroup>

<ItemGroup>
<PRIResource Update="Strings\en-US\AboutViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\AuthenticationViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\BaseViewResources.resw">
<Generator></Generator>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\CommonResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\DialogButtonsResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\FilenameTemplateResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\HomeDownloadsViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\HomeVideoCollectionViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\HomeVideoViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\HomeViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\NotificationsResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\SearchResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\SettingsViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
<PRIResource Update="Strings\en-US\SubscriptionsViewResources.resw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</PRIResource>
</ItemGroup>
</Project>
22 changes: 10 additions & 12 deletions VDownload.Core/VDownload.Core.Tasks/DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
using Windows.Storage;
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;
using VDownload.Core.Strings;

namespace VDownload.Core.Tasks
{
Expand All @@ -39,7 +39,6 @@ private enum TaskResult
protected readonly IConfigurationService _configurationService;
protected readonly ISettingsService _settingsService;
protected readonly IFFmpegService _ffmpegService;
protected readonly IStringResourcesService _stringResourcesService;
protected readonly INotificationsService _notificationsService;

#endregion
Expand Down Expand Up @@ -87,12 +86,11 @@ private enum TaskResult

#region CONSTRUCTORS

internal DownloadTask(Video video, VideoDownloadOptions downloadOptions, IConfigurationService configurationService, ISettingsService settingsService, IFFmpegService ffmpegService, IStringResourcesService stringResourcesService, INotificationsService notificationsService)
internal DownloadTask(Video video, VideoDownloadOptions downloadOptions, IConfigurationService configurationService, ISettingsService settingsService, IFFmpegService ffmpegService, INotificationsService notificationsService)
{
_configurationService = configurationService;
_settingsService = settingsService;
_ffmpegService = ffmpegService;
_stringResourcesService = stringResourcesService;
_notificationsService = notificationsService;

_video = video;
Expand Down Expand Up @@ -165,8 +163,8 @@ private async Task Download()

List<string> content = new List<string>()
{
$"{_stringResourcesService.NotificationsResources.Get("Title")}: {Video.Title}",
$"{_stringResourcesService.NotificationsResources.Get("Author")}: {Video.Author}"
$"{StringResourcesManager.Notifications.Get("Title")}: {Video.Title}",
$"{StringResourcesManager.Notifications.Get("Author")}: {Video.Author}"
};

string errorMessage = null;
Expand Down Expand Up @@ -222,15 +220,15 @@ private async Task Download()

if (ex is TaskCanceledException || ex is HttpRequestException)
{
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorDownloadingTimeout");
message = StringResourcesManager.HomeDownloadsView.Get("ErrorDownloadingTimeout");
}
else if (ex is InstanceFileNotFoundException)
{
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorFFmpegPath");
message = StringResourcesManager.HomeDownloadsView.Get("ErrorFFmpegPath");
}
else if (ex is FFMpegException)
{
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorFFmpeg");
message = StringResourcesManager.HomeDownloadsView.Get("ErrorFFmpeg");
}
else
{
Expand All @@ -249,15 +247,15 @@ private async Task Download()
case TaskResult.Error:
if (_settingsService.Data.Common.Notifications.OnUnsuccessful)
{
string title = _stringResourcesService.NotificationsResources.Get("OnUnsuccessfulTitle");
content.Add($"{_stringResourcesService.NotificationsResources.Get("Message")}: {errorMessage}");
string title = StringResourcesManager.Notifications.Get("OnUnsuccessfulTitle");
content.Add($"{StringResourcesManager.Notifications.Get("Message")}: {errorMessage}");
_notificationsService.SendNotification(title, content);
}
break;
case TaskResult.Success:
if (_settingsService.Data.Common.Notifications.OnSuccessful)
{
string title = _stringResourcesService.NotificationsResources.Get("OnSuccessfulTitle");
string title = StringResourcesManager.Notifications.Get("OnSuccessfulTitle");
_notificationsService.SendNotification(title, content);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using VDownload.Services.Data.Configuration;
using VDownload.Services.Data.Settings;
using VDownload.Services.UI.Notifications;
using VDownload.Services.UI.StringResources;
using VDownload.Services.Utility.FFmpeg;

namespace VDownload.Core.Tasks
Expand All @@ -26,7 +25,6 @@ public class DownloadTaskFactoryService : IDownloadTaskFactoryService
protected readonly IConfigurationService _configurationService;
protected readonly ISettingsService _settingsService;
protected readonly IFFmpegService _ffmpegService;
protected readonly IStringResourcesService _stringResourcesService;
protected readonly INotificationsService _notificationsService;

#endregion
Expand All @@ -35,12 +33,11 @@ public class DownloadTaskFactoryService : IDownloadTaskFactoryService

#region CONSTRUCTORS

public DownloadTaskFactoryService(IConfigurationService configurationService, ISettingsService settingsService, IFFmpegService ffmpegService, IStringResourcesService stringResourcesService, INotificationsService notificationsService)
public DownloadTaskFactoryService(IConfigurationService configurationService, ISettingsService settingsService, IFFmpegService ffmpegService, INotificationsService notificationsService)
{
_configurationService = configurationService;
_settingsService = settingsService;
_ffmpegService = ffmpegService;
_stringResourcesService = stringResourcesService;
_notificationsService = notificationsService;
}

Expand All @@ -52,7 +49,7 @@ public DownloadTaskFactoryService(IConfigurationService configurationService, IS

public DownloadTask Create(Video video, VideoDownloadOptions downloadOptions)
{
return new DownloadTask(video, downloadOptions, _configurationService, _settingsService, _ffmpegService, _stringResourcesService, _notificationsService);
return new DownloadTask(video, downloadOptions, _configurationService, _settingsService, _ffmpegService, _notificationsService);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<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" />
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services.UI\VDownload.Services.UI.Notifications\VDownload.Services.UI.Notifications.csproj" />
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services.UI\VDownload.Services.UI.StringResources\VDownload.Services.UI.StringResources.csproj" />
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services.Utility\VDownload.Services.Utility.FFmpeg\VDownload.Services.Utility.FFmpeg.csproj" />
<ProjectReference Include="..\VDownload.Core.Strings\VDownload.Core.Strings.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using VDownload.Core.Strings;
using VDownload.Core.ViewModels.About.Helpers;
using VDownload.Services.Data.Configuration;
using VDownload.Services.Data.Configuration.Models;
using VDownload.Services.UI.StringResources;
using Windows.System.UserProfile;

namespace VDownload.Core.ViewModels.About
Expand All @@ -21,7 +21,6 @@ public partial class AboutViewModel : ObservableObject
{
#region SERVICES

protected readonly IStringResourcesService _stringResourcesService;
protected readonly IConfigurationService _configurationService;

#endregion
Expand Down Expand Up @@ -51,15 +50,14 @@ public partial class AboutViewModel : ObservableObject

#region CONSTRUCTORS

public AboutViewModel(IStringResourcesService stringResourcesService, IConfigurationService configurationService)
public AboutViewModel(IConfigurationService configurationService)
{
_stringResourcesService = stringResourcesService;
_configurationService = configurationService;

string version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
if (version == "0.0.0")
{
version = _stringResourcesService.AboutViewResources.Get("SelfbuiltVersion");
version = StringResourcesManager.AboutView.Get("SelfbuiltVersion");
}
_version = version;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using VDownload.Core.Strings;
using VDownload.Services.Data.Configuration;
using VDownload.Services.UI.Dialogs;
using VDownload.Services.UI.StringResources;
using VDownload.Services.UI.WebView;
using VDownload.Sources.Twitch.Authentication;

Expand All @@ -36,7 +36,6 @@ public enum AuthenticationButton
protected readonly IDialogsService _dialogsService;
protected readonly IWebViewService _webViewService;
protected readonly IConfigurationService _configurationService;
protected readonly IStringResourcesService _stringResourcesService;
protected readonly ITwitchAuthenticationService _twitchAuthenticationService;

#endregion
Expand All @@ -60,12 +59,11 @@ public enum AuthenticationButton

#region CONSTRUCTORS

public AuthenticationViewModel(IDialogsService dialogsService, IWebViewService webViewService, IConfigurationService configurationService, IStringResourcesService stringResourcesService, ITwitchAuthenticationService twitchAuthenticationService)
public AuthenticationViewModel(IDialogsService dialogsService, IWebViewService webViewService, IConfigurationService configurationService, ITwitchAuthenticationService twitchAuthenticationService)
{
_dialogsService = dialogsService;
_webViewService = webViewService;
_configurationService = configurationService;
_stringResourcesService = stringResourcesService;
_twitchAuthenticationService = twitchAuthenticationService;
}

Expand Down Expand Up @@ -100,7 +98,7 @@ public async Task TwitchAuthentication()
Sources.Twitch.Configuration.Models.Authentication auth = _configurationService.Twitch.Authentication;
string authUrl = string.Format(auth.Url, auth.ClientId, auth.RedirectUrl, auth.ResponseType, string.Join(' ', auth.Scopes));

string url = await _webViewService.Show(new Uri(authUrl), (url) => url.StartsWith(auth.RedirectUrl), _stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationWindowTitle"));
string url = await _webViewService.Show(new Uri(authUrl), (url) => url.StartsWith(auth.RedirectUrl), StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationWindowTitle"));

Regex regex = new Regex(auth.RedirectUrlRegex);
Match match = regex.Match(url);
Expand All @@ -112,8 +110,8 @@ public async Task TwitchAuthentication()
}
else
{
string title = _stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationDialogTitle");
string message = _stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationDialogMessage");
string title = StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationDialogTitle");
string message = StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationDialogMessage");
await _dialogsService.ShowOk(title, message);
}
}
Expand All @@ -138,11 +136,11 @@ private async Task TwitchAuthenticationRefresh()
if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable)
{
TwitchButtonEnable = false;
TwitchDescription = _stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationDescriptionNotAuthenticatedNoInternetConnection");
TwitchDescription = StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationDescriptionNotAuthenticatedNoInternetConnection");
}
else
{
TwitchDescription = _stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationDescriptionNotAuthenticated");
TwitchDescription = StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationDescriptionNotAuthenticated");
}
TwitchButtonState = AuthenticationButton.SignIn;
}
Expand All @@ -155,21 +153,21 @@ private async Task TwitchAuthenticationRefresh()
}
catch (Exception ex) when (ex is TaskCanceledException || ex is HttpRequestException)
{
TwitchDescription = _stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationDescriptionCannotValidate");
TwitchDescription = StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationDescriptionCannotValidate");
TwitchButtonState = AuthenticationButton.SignIn;
TwitchButtonEnable = false;
return;
}

if (validationResult.Success)
{
TwitchDescription = string.Format(_stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationDescriptionAuthenticated"), validationResult.TokenData.Login, validationResult.TokenData.ExpirationDate);
TwitchDescription = string.Format(StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationDescriptionAuthenticated"), validationResult.TokenData.Login, validationResult.TokenData.ExpirationDate);
TwitchButtonState = AuthenticationButton.SignOut;
}
else
{
await _twitchAuthenticationService.DeleteToken();
TwitchDescription = _stringResourcesService.AuthenticationViewResources.Get("TwitchAuthenticationDescriptionAuthenticationInvalid");
TwitchDescription = StringResourcesManager.AuthenticationView.Get("TwitchAuthenticationDescriptionAuthenticationInvalid");
TwitchButtonState = AuthenticationButton.SignIn;
}
}
Expand Down
Loading

0 comments on commit c4710b5

Please sign in to comment.