Code refactor and simplfication

ModernKeePassLib assembly info updated and version fixed
This commit is contained in:
2017-10-02 10:44:04 +02:00
committed by BONNEVILLE Geoffroy
parent 6d69dd4d15
commit 30838d0e00
17 changed files with 57 additions and 91 deletions

View File

@@ -1,5 +1,5 @@
<UserControl
x:Class="ModernKeePass.Controls.PasswordUserControl"
x:Class="ModernKeePass.Controls.OpenDatabaseUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ModernKeePass.Controls"

View File

@@ -1,29 +1,29 @@
using Windows.System;
using System;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using ModernKeePass.Events;
// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236
namespace ModernKeePass.Controls
{
public sealed partial class PasswordUserControl : UserControl
public sealed partial class OpenDatabaseUserControl : UserControl
{
public PasswordUserControl()
public OpenDatabaseUserControl()
{
InitializeComponent();
PasswordBox.Focus(FocusState.Programmatic);
}
public delegate void PasswordCheckedEventHandler(object sender, DatabaseEventArgs e);
public event PasswordCheckedEventHandler PasswordChecked;
public delegate void PasswordCheckedEventHandler(object sender, EventArgs e);
public event PasswordCheckedEventHandler ValidationChecked;
private void OpenButton_OnClick(object sender, RoutedEventArgs e)
{
var app = (App)Application.Current;
StatusTextBlock.Text = app.Database.Open(PasswordBox.Password);
PasswordChecked(this, new DatabaseEventArgs { IsOpen = app.Database.IsOpen });
ValidationChecked?.Invoke(this, new EventArgs());
}
private void PasswordBox_KeyDown(object sender, KeyRoutedEventArgs e)

View File

@@ -1,9 +0,0 @@
using System;
namespace ModernKeePass.Events
{
public class DatabaseEventArgs: EventArgs
{
public bool IsOpen { get; set; }
}
}

View File

@@ -3,7 +3,6 @@ using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using ModernKeePass.Models;
using ModernKeePass.Pages;
using ModernKeePass.ViewModels;
@@ -24,16 +23,16 @@ namespace ModernKeePass
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var mainMenuItems = new ObservableCollection<MainMenuItem>
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
{
new MainMenuItem {Title = "Open", PageType = typeof(OpenDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Page2},
new MainMenuItem {Title = "New" /*, PageType = typeof(NewDatabasePage)*/, Destination = MenuFrame, SymbolIcon = Symbol.Add},
new MainMenuItem {Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Save},
new MainMenuItem {Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Copy}
new MainMenuItemVm {Title = "Open", PageType = typeof(OpenDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Page2},
new MainMenuItemVm {Title = "New" /*, PageType = typeof(NewDatabasePage)*/, Destination = MenuFrame, SymbolIcon = Symbol.Add},
new MainMenuItemVm {Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Save},
new MainMenuItemVm {Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Copy}
};
var app = (App)Application.Current;
if (app.Database != null && app.Database.IsOpen)
mainMenuItems.Add(new MainMenuItem { Title = app.Database.Name, PageType = typeof(GroupDetailPage), Destination = Frame, Parameter = app.Database.RootGroup, Group = 1, SymbolIcon = Symbol.ProtectedDocument});
mainMenuItems.Add(new MainMenuItemVm { Title = app.Database.Name, PageType = typeof(GroupDetailPage), Destination = Frame, Parameter = app.Database.RootGroup, Group = 1, SymbolIcon = Symbol.ProtectedDocument});
var mainVm = DataContext as MainVm;
mainVm.MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
@@ -42,7 +41,7 @@ namespace ModernKeePass
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var mainMenuItem = e.AddedItems[0] as MainMenuItem;
var mainMenuItem = e.AddedItems[0] as MainMenuItemVm;
mainMenuItem?.Destination.Navigate(mainMenuItem.PageType, mainMenuItem.Parameter);
}
}

View File

@@ -116,18 +116,17 @@
<Compile Include="Common\RelayCommand.cs" />
<Compile Include="Common\SuspensionManager.cs" />
<Compile Include="Controls\ListViewWithDisable.cs" />
<Compile Include="Controls\PasswordUserControl.xaml.cs">
<DependentUpon>PasswordUserControl.xaml</DependentUpon>
<Compile Include="Controls\OpenDatabaseUserControl.xaml.cs">
<DependentUpon>OpenDatabaseUserControl.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\PluralizationConverter.cs" />
<Compile Include="Events\DatabaseEventArgs.cs" />
<Compile Include="Interfaces\IIsEnabled.cs" />
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Mappings\PwIconToSegoeMapping.cs" />
<Compile Include="Models\MainMenuItem.cs" />
<Compile Include="Models\RecentItem.cs" />
<Compile Include="ViewModels\MainMenuItemVm.cs" />
<Compile Include="ViewModels\RecentItemVm.cs" />
<Compile Include="Pages\EntryDetailPage.xaml.cs">
<DependentUpon>EntryDetailPage.xaml</DependentUpon>
</Compile>
@@ -166,7 +165,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="Controls\PasswordUserControl.xaml">
<Page Include="Controls\OpenDatabaseUserControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@@ -217,7 +216,9 @@
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\Logo.scale-100.png" />
<Content Include="Assets\Logo.scale-140.png" />

View File

@@ -15,6 +15,6 @@
<HyperlinkButton Content="Browse files..." Click="ButtonBase_OnClick" />
<HyperlinkButton Content="From Url..." IsEnabled="False" />
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
<local:PasswordUserControl Visibility="{Binding SelectedVisibility}" PasswordChecked="PasswordUserControl_PasswordChecked" />
<local:OpenDatabaseUserControl Visibility="{Binding SelectedVisibility}" ValidationChecked="PasswordUserControl_PasswordChecked" />
</StackPanel>
</Page>

View File

@@ -73,10 +73,10 @@ namespace ModernKeePass.Pages
databaseVm.NotifyPropertyChanged("Name");
}
private void PasswordUserControl_PasswordChecked(object sender, Events.DatabaseEventArgs e)
private void PasswordUserControl_PasswordChecked(object sender, EventArgs e)
{
var app = (App)Application.Current;
if (e.IsOpen) _mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
if (app.Database.IsOpen) _mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
}
}
}

View File

@@ -25,7 +25,7 @@
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" Width="350" Padding="5" />
<local:PasswordUserControl Visibility="{Binding PasswordVisibility}" PasswordChecked="PasswordUserControl_PasswordChecked" />
<local:OpenDatabaseUserControl Visibility="{Binding PasswordVisibility}" ValidationChecked="PasswordUserControl_PasswordChecked" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>

View File

@@ -1,13 +1,11 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using ModernKeePass.Common;
using ModernKeePass.Models;
using ModernKeePass.ViewModels;
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
@@ -32,17 +30,19 @@ namespace ModernKeePass.Pages
_mainFrame = e.Parameter as Frame;
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
var recentVm = DataContext as RecentVm;
recentVm.RecentItems = new ObservableCollection<RecentItem>(
if (recentVm == null) return;
recentVm.RecentItems = new ObservableCollection<RecentItemVm>(
from entry in mru.Entries
select new RecentItem() { Name = entry.Metadata, Token = entry.Token });
select new RecentItemVm {Name = entry.Metadata, Token = entry.Token});
recentVm.NotifyPropertyChanged("RecentItems");
}
private async void RecentListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var recentItem = e.AddedItems[0] as RecentItem;
var recentItem = e.AddedItems[0] as RecentItemVm;
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
var file = await mru.GetFileAsync(recentItem.Token) as StorageFile;
if (recentItem == null) return;
var file = await mru.GetFileAsync(recentItem.Token);
var app = (App)Application.Current;
app.Database = new DatabaseHelper(file);
@@ -50,10 +50,10 @@ namespace ModernKeePass.Pages
recentItem.NotifyPropertyChanged("PasswordVisibility");
}
private void PasswordUserControl_PasswordChecked(object sender, Events.DatabaseEventArgs e)
private void PasswordUserControl_PasswordChecked(object sender, EventArgs e)
{
var app = (App)Application.Current;
if (e.IsOpen) _mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
if (app.Database.IsOpen) _mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
}
}
}

View File

@@ -2,9 +2,9 @@
using Windows.UI.Xaml.Controls;
using ModernKeePass.Interfaces;
namespace ModernKeePass.Models
namespace ModernKeePass.ViewModels
{
public class MainMenuItem: IIsEnabled
public class MainMenuItemVm: IIsEnabled
{
private string _title;

View File

@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using ModernKeePass.Models;
using System.ComponentModel;
using System.Linq;
@@ -7,7 +6,7 @@ namespace ModernKeePass.ViewModels
{
public class MainVm : INotifyPropertyChanged
{
public IOrderedEnumerable<IGrouping<int, MainMenuItem>> MainMenuItems { get; set; }
public IOrderedEnumerable<IGrouping<int, MainMenuItemVm>> MainMenuItems { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)

View File

@@ -1,9 +1,9 @@
using System.ComponentModel;
using Windows.UI.Xaml;
namespace ModernKeePass.Models
namespace ModernKeePass.ViewModels
{
public class RecentItem: INotifyPropertyChanged
public class RecentItemVm: INotifyPropertyChanged
{
public string Token { get; set; }
public string Name { get; set; }

View File

@@ -1,12 +1,11 @@
using ModernKeePass.Models;
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace ModernKeePass.ViewModels
{
public class RecentVm : INotifyPropertyChanged
{
public ObservableCollection<RecentItem> RecentItems { get; set; }
public ObservableCollection<RecentItemVm> RecentItems { get; set; }
public event PropertyChangedEventHandler PropertyChanged;

View File

@@ -18,30 +18,9 @@
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security;
using System.Diagnostics;
using Windows.Storage.Streams;
#if ModernKeePassLib
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
#else
#if !KeePassRT
using System.Security.Cryptography;
#else
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.IO;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Paddings;
using Org.BouncyCastle.Crypto.Parameters;
#endif
#endif
using ModernKeePassLib.Resources;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Engines;
@@ -49,6 +28,9 @@ using Org.BouncyCastle.Crypto.IO;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Paddings;
using Org.BouncyCastle.Crypto.Parameters;
#else
using System.Security.Cryptography;
#endif
namespace ModernKeePassLib.Cryptography.Cipher
{
@@ -86,12 +68,9 @@ namespace ModernKeePassLib.Cryptography.Cipher
/// <summary>
/// Get the UUID of this cipher engine as <c>PwUuid</c> object.
/// </summary>
public PwUuid CipherUuid
{
get { return StandardAesEngine.AesUuid; }
}
public PwUuid CipherUuid => StandardAesEngine.AesUuid;
/// <summary>
/// <summary>
/// Get a displayable name describing this cipher engine.
/// </summary>
public string DisplayName { get { return KLRes.EncAlgorithmAes; } }

View File

@@ -18,18 +18,16 @@
*/
using System;
using System.Security;
#if ModernKeePassLib
using Windows.Security.Cryptography;
using ModernKeePassLib.Utility;
using Windows.Security.Cryptography.Core;
#else
using System.Security.Cryptography;
#endif
using System.IO;
using System.Diagnostics;
using ModernKeePassLib.Native;
using ModernKeePassLib.Utility;
using Windows.Security.Cryptography.Core;
namespace ModernKeePassLib.Cryptography
{

View File

@@ -2,7 +2,7 @@
<package >
<metadata>
<id>ModernKeePassLib</id>
<version>2.28.3000</version>
<version>2.28.4000</version>
<title>ModernKeePassLib</title>
<authors>Geoffroy Bonneville</authors>
<owners>Geoffroy Bonneville</owners>

View File

@@ -22,12 +22,12 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General assembly properties
[assembly: AssemblyTitle("KeePassLib")]
[assembly: AssemblyDescription("KeePass Password Management Library")]
[assembly: AssemblyTitle("ModernKeePassLib")]
[assembly: AssemblyDescription("KeePass Password Management Library for .Net Standard")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Panteam")]
[assembly: AssemblyProduct("KeePassLib")]
[assembly: AssemblyCopyright("Copyright © 2003-2017 Dominik Reichl")]
[assembly: AssemblyCompany("wismna")]
[assembly: AssemblyProduct("ModernKeePassLib")]
[assembly: AssemblyCopyright("Copyright © 2017 Geoffroy Bonneville")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -40,5 +40,5 @@ using System.Runtime.InteropServices;
#endif
// Assembly version information
[assembly: AssemblyVersion("2.28.1.*")]
[assembly: AssemblyFileVersion("2.28.1.0")]
[assembly: AssemblyVersion("2.28.1.4000")]
[assembly: AssemblyFileVersion("2.28.1.4000")]