Compare commits

...
5 Commits
Author SHA1 Message Date
Alexandru Macocian 75807edfb7 Merge branch 'master' of https://github.com/AlexMacocian/Daybreak 2021-04-08 00:31:49 +02:00
Alexandru Macocian becce84849 Updated to 0.1.1 2021-04-08 00:31:42 +02:00
Alexandru Macocian c313e66957 Removed credential manager.
Switched to ProtectedData and saving username and password in configuration.
2021-04-08 00:31:24 +02:00
amacocianandGitHub 9717aa1777 Update README.md 2021-04-07 20:19:35 +02:00
amacocianandGitHub 36ea941fe6 Update README.md 2021-04-07 20:02:19 +02:00
12 changed files with 89 additions and 33 deletions
@@ -12,5 +12,9 @@ namespace Daybreak.Configuration
public string LeftBrowserDefault { get; set; }
[JsonProperty("RightBrowserDefault")]
public string RightBrowserDefault { get; set; }
[JsonProperty("ProtectedUsername")]
public string ProtectedUsername { get; set; }
[JsonProperty("ProtectedPassword")]
public string ProtectedPassword { get; set; }
}
}
@@ -1,13 +1,13 @@
using Daybreak.Services.ApplicationDetection;
using Daybreak.Services.ApplicationLifetime;
using Daybreak.Services.Bloogum;
using Daybreak.Services.Configuration;
using Daybreak.Services.Credentials;
using Daybreak.Services.Logging;
using Daybreak.Services.Screenshots;
using Daybreak.Services.ViewManagement;
using Daybreak.Views;
using Microsoft.Web.WebView2.Core;
using Palletizer.WPF.Services.ConfigurationManager;
using Slim;
using System.Extensions;
+2 -3
View File
@@ -9,16 +9,15 @@
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<Version>0.1</Version>
<Version>0.1.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.4.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.774.44" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Slim" Version="1.2.1" />
<PackageReference Include="SystemExtensions.NetStandard" Version="1.1.3" />
<PackageReference Include="WCL" Version="1.0.1" />
<PackageReference Include="WCL" Version="1.0.2" />
<PackageReference Include="WpfExtended" Version="0.1.1" />
</ItemGroup>
+1 -1
View File
@@ -72,7 +72,7 @@
<Grid x:Name="Container" Grid.Row="1">
</Grid>
<wcl:TitleBar x:Name="Titlebar"
Background="Transparent" Text="" MouseLeftButtonDown="TitleBar_MouseLeftButtonDown"
Background="Transparent" MouseLeftButtonDown="TitleBar_MouseLeftButtonDown"
WindowState="Normal" MinimizeButtonClicked="TitleBar_MinimizeButtonClicked"
MaximizeButtonClicked="TitleBar_MaximizeButtonClicked"
RestoreButtonClicked="TitleBar_RestoreButtonClicked"
@@ -1,5 +1,5 @@
using Daybreak.Services.Credentials;
using Palletizer.WPF.Services.ConfigurationManager;
using Daybreak.Services.Configuration;
using Daybreak.Services.Credentials;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -41,15 +41,18 @@ namespace Daybreak.Services.ApplicationDetection
}
var auth = this.credentialManager.GetCredentials();
if (auth is null)
{
throw new InvalidOperationException($"No credentials available");
}
if (Process.Start(executable, new List<string> { "-email", auth.Username, "-password", auth.Password, "-character", configuration.CharacterName }) is null)
{
throw new InvalidOperationException($"Unable to launch executable");
}
auth.Do(
onSome: (credentials) =>
{
if (Process.Start(executable, new List<string> { "-email", credentials.Username, "-password", credentials.Password, "-character", configuration.CharacterName }) is null)
{
throw new InvalidOperationException($"Unable to launch executable");
}
},
onNone: () =>
{
throw new InvalidOperationException($"No credentials available");
});
}
private static bool GuildwarsProcessDetected()
@@ -4,7 +4,7 @@ using Daybreak.Utils;
using System;
using System.IO;
namespace Palletizer.WPF.Services.ConfigurationManager
namespace Daybreak.Services.Configuration
{
public sealed class ConfigurationManager : IConfigurationManager
{
@@ -1,6 +1,6 @@
using Daybreak.Configuration;
namespace Palletizer.WPF.Services.ConfigurationManager
namespace Daybreak.Services.Configuration
{
public interface IConfigurationManager
{
@@ -1,20 +1,65 @@
using Daybreak.Models;
using Daybreak.Services.Configuration;
using Daybreak.Services.Logging;
using Daybreak.Utils;
using System;
using System.Extensions;
using System.Security.Cryptography;
using System.Text;
namespace Daybreak.Services.Credentials
{
public sealed class CredentialManager : ICredentialManager
{
private const string Target = "GuildwarsLogin";
private static readonly byte[] Entropy = Convert.FromBase64String("R3VpbGR3YXJz");
private readonly ILogger logger;
private readonly IConfigurationManager configurationManager;
public LoginCredentials GetCredentials()
public CredentialManager(
ILogger logger,
IConfigurationManager configurationManager)
{
var credential = Meziantou.Framework.Win32.CredentialManager.ReadCredential(Target);
return new LoginCredentials { Username = credential.UserName, Password = credential.Password };
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
this.logger = logger.ThrowIfNull(nameof(logger));
}
public Optional<LoginCredentials> GetCredentials()
{
this.logger.LogInformation("Retrieving credentials");
var config = this.configurationManager.GetConfiguration();
if (string.IsNullOrEmpty(config.ProtectedUsername) ||
string.IsNullOrEmpty(config.ProtectedPassword))
{
this.logger.LogInformation("No credentials found");
return Optional.None<LoginCredentials>();
}
try
{
var usrbytes = Convert.FromBase64String(config.ProtectedUsername);
var psdBytes = Convert.FromBase64String(config.ProtectedPassword);
return new LoginCredentials
{
Username = Encoding.UTF8.GetString(ProtectedData.Unprotect(usrbytes, Entropy, DataProtectionScope.LocalMachine)),
Password = Encoding.UTF8.GetString(ProtectedData.Unprotect(psdBytes, Entropy, DataProtectionScope.LocalMachine))
};
}
catch(Exception e)
{
this.logger.LogError($"Unable to retrieve credentials. Details: {e}");
return Optional.None<LoginCredentials>();
}
}
public void StoreCredentials(LoginCredentials loginCredentials)
{
Meziantou.Framework.Win32.CredentialManager.WriteCredential(Target, loginCredentials.Username, loginCredentials.Password, Meziantou.Framework.Win32.CredentialPersistence.LocalMachine);
this.logger.LogInformation("Storing credentials");
var usrBytes = Encoding.UTF8.GetBytes(loginCredentials.Username);
var psdBytes = Encoding.UTF8.GetBytes(loginCredentials.Password);
var config = this.configurationManager.GetConfiguration();
config.ProtectedUsername = Convert.ToBase64String(ProtectedData.Protect(usrBytes, Entropy, DataProtectionScope.LocalMachine));
config.ProtectedPassword = Convert.ToBase64String(ProtectedData.Protect(psdBytes, Entropy, DataProtectionScope.LocalMachine));
this.configurationManager.SaveConfiguration(config);
}
}
}
@@ -1,10 +1,11 @@
using Daybreak.Models;
using System.Extensions;
namespace Daybreak.Services.Credentials
{
public interface ICredentialManager
{
void StoreCredentials(LoginCredentials loginCredentials);
LoginCredentials GetCredentials();
Optional<LoginCredentials> GetCredentials();
}
}
+9 -7
View File
@@ -1,13 +1,10 @@
using Daybreak.Configuration;
using Daybreak.Models;
using Daybreak.Models;
using Daybreak.Services.Configuration;
using Daybreak.Services.Credentials;
using Daybreak.Services.ViewManagement;
using Microsoft.Win32;
using Palletizer.WPF.Services.ConfigurationManager;
using System.Extensions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Extensions;
namespace Daybreak.Views
{
@@ -36,8 +33,13 @@ namespace Daybreak.Views
{
var config = this.configurationManager.GetConfiguration();
var creds = this.credentialManager.GetCredentials();
this.UsernameTextbox.Text = creds.Username;
this.PasswordBox.Password = creds.Password;
creds.DoAny(
onSome: (credentials) =>
{
this.UsernameTextbox.Text = credentials.Username;
this.PasswordBox.Password = credentials.Password;
});
this.CharacterTextbox.Text = config.CharacterName;
this.GamePathTextbox.Text = config.GamePath;
}
+1 -2
View File
@@ -1,10 +1,9 @@
using Daybreak.Services.ApplicationDetection;
using Daybreak.Services.Configuration;
using Daybreak.Services.ViewManagement;
using Palletizer.WPF.Services.ConfigurationManager;
using System;
using System.Extensions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Extensions;
+3
View File
@@ -1,5 +1,8 @@
# Daybreak
Custom client for Guildwars.
Requires standalone version https://developer.microsoft.com/microsoft-edge/webview2.
![Alt Text](https://media1.giphy.com/media/Z32o0OZ5pZHDOIodzD/giphy.gif)
## Features
Automatically detect if guildwars is running or not. Includes the ability to launch guildwars from the client.