mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-15 12:56:32 +03:00
add default group, use it instead of the root
This commit is contained in:
@@ -7,6 +7,7 @@ public interface IPassStore
|
|||||||
bool Locked { get; }
|
bool Locked { get; }
|
||||||
|
|
||||||
IPassStoreDirectory GetRootDirectory();
|
IPassStoreDirectory GetRootDirectory();
|
||||||
|
IPassStoreDirectory? GetGroupByType(byte groupType);
|
||||||
int GetTotalEntryCount();
|
int GetTotalEntryCount();
|
||||||
void Unlock(CompositeKey key);
|
void Unlock(CompositeKey key);
|
||||||
void Lock();
|
void Lock();
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ namespace KeyKeeper.PasswordStore;
|
|||||||
public interface IPassStoreDirectory : IEnumerable<PassStoreEntry>
|
public interface IPassStoreDirectory : IEnumerable<PassStoreEntry>
|
||||||
{
|
{
|
||||||
bool DeleteEntry(Guid id);
|
bool DeleteEntry(Guid id);
|
||||||
|
void AddEntry(PassStoreEntry entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,12 @@ public class PassStoreEntryGroup : PassStoreEntry, IPassStoreDirectory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddEntry(PassStoreEntry entry)
|
||||||
|
{
|
||||||
|
entry.Parent = this;
|
||||||
|
ChildEntries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
public bool DeleteEntry(Guid id)
|
public bool DeleteEntry(Guid id)
|
||||||
{
|
{
|
||||||
if (ChildEntries == null)
|
if (ChildEntries == null)
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ public class PassStoreFileAccessor : IPassStore
|
|||||||
return (IPassStoreDirectory)root!;
|
return (IPassStoreDirectory)root!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IPassStoreDirectory? GetGroupByType(byte groupType)
|
||||||
|
{
|
||||||
|
if (Locked)
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
return (root as PassStoreEntryGroup)?.ChildEntries
|
||||||
|
.OfType<PassStoreEntryGroup>()
|
||||||
|
.FirstOrDefault(g => g.GroupType == groupType);
|
||||||
|
}
|
||||||
|
|
||||||
public int GetTotalEntryCount()
|
public int GetTotalEntryCount()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
@@ -252,15 +261,24 @@ public class PassStoreFileAccessor : IPassStore
|
|||||||
|
|
||||||
private PassStoreEntry WriteInitialStoreTree(OuterEncryptionWriter w)
|
private PassStoreEntry WriteInitialStoreTree(OuterEncryptionWriter w)
|
||||||
{
|
{
|
||||||
PassStoreEntry root =
|
PassStoreEntryGroup defaultGroup = new(
|
||||||
new PassStoreEntryGroup(
|
Guid.NewGuid(),
|
||||||
Guid.NewGuid(),
|
DateTime.UtcNow,
|
||||||
DateTime.UtcNow,
|
DateTime.UtcNow,
|
||||||
DateTime.UtcNow,
|
Guid.Empty,
|
||||||
Guid.Empty,
|
"",
|
||||||
"",
|
GROUP_TYPE_DEFAULT
|
||||||
GROUP_TYPE_ROOT
|
);
|
||||||
);
|
PassStoreEntryGroup root = new(
|
||||||
|
Guid.NewGuid(),
|
||||||
|
DateTime.UtcNow,
|
||||||
|
DateTime.UtcNow,
|
||||||
|
Guid.Empty,
|
||||||
|
"",
|
||||||
|
GROUP_TYPE_ROOT,
|
||||||
|
[defaultGroup]
|
||||||
|
);
|
||||||
|
defaultGroup.Parent = root;
|
||||||
root.WriteToStream(w);
|
root.WriteToStream(w);
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using KeyKeeper.PasswordStore;
|
using KeyKeeper.PasswordStore;
|
||||||
|
using static KeyKeeper.PasswordStore.FileFormatConstants;
|
||||||
|
|
||||||
namespace KeyKeeper.ViewModels;
|
namespace KeyKeeper.ViewModels;
|
||||||
|
|
||||||
@@ -33,7 +34,9 @@ public partial class RepositoryWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
private void SwitchToUnlocked()
|
private void SwitchToUnlocked()
|
||||||
{
|
{
|
||||||
CurrentPage = new UnlockedRepositoryViewModel(passStore);
|
var directory = passStore.GetGroupByType(GROUP_TYPE_DEFAULT)
|
||||||
|
?? passStore.GetRootDirectory();
|
||||||
|
CurrentPage = new UnlockedRepositoryViewModel(passStore, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SwitchToLocked()
|
private void SwitchToLocked()
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ namespace KeyKeeper.ViewModels;
|
|||||||
public class UnlockedRepositoryViewModel : ViewModelBase
|
public class UnlockedRepositoryViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private IPassStore passStore;
|
private IPassStore passStore;
|
||||||
|
private IPassStoreDirectory currentDirectory;
|
||||||
private bool hasUnsavedChanges;
|
private bool hasUnsavedChanges;
|
||||||
|
|
||||||
public IEnumerable<PassStoreEntryPassword> Passwords
|
public IEnumerable<PassStoreEntryPassword> Passwords
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return passStore.GetRootDirectory()
|
return currentDirectory
|
||||||
.Where(entry => entry is PassStoreEntryPassword)
|
.Where(entry => entry is PassStoreEntryPassword)
|
||||||
.Select(entry => (entry as PassStoreEntryPassword)!);
|
.Select(entry => (entry as PassStoreEntryPassword)!);
|
||||||
}
|
}
|
||||||
@@ -30,9 +31,10 @@ public class UnlockedRepositoryViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnlockedRepositoryViewModel(IPassStore store)
|
public UnlockedRepositoryViewModel(IPassStore store, IPassStoreDirectory directory)
|
||||||
{
|
{
|
||||||
passStore = store;
|
passStore = store;
|
||||||
|
currentDirectory = directory;
|
||||||
HasUnsavedChanges = false;
|
HasUnsavedChanges = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ public class UnlockedRepositoryViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
if (entry is PassStoreEntryPassword)
|
if (entry is PassStoreEntryPassword)
|
||||||
{
|
{
|
||||||
(passStore.GetRootDirectory() as PassStoreEntryGroup)!.ChildEntries.Add(entry);
|
currentDirectory.AddEntry(entry);
|
||||||
HasUnsavedChanges = true;
|
HasUnsavedChanges = true;
|
||||||
OnPropertyChanged(nameof(Passwords));
|
OnPropertyChanged(nameof(Passwords));
|
||||||
}
|
}
|
||||||
@@ -48,18 +50,15 @@ public class UnlockedRepositoryViewModel : ViewModelBase
|
|||||||
|
|
||||||
public void DeleteEntry(Guid id)
|
public void DeleteEntry(Guid id)
|
||||||
{
|
{
|
||||||
(passStore.GetRootDirectory() as PassStoreEntryGroup)!.DeleteEntry(id);
|
currentDirectory.DeleteEntry(id);
|
||||||
HasUnsavedChanges = true;
|
HasUnsavedChanges = true;
|
||||||
OnPropertyChanged(nameof(Passwords));
|
OnPropertyChanged(nameof(Passwords));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateEntry(PassStoreEntryPassword updatedEntry)
|
public void UpdateEntry(PassStoreEntryPassword updatedEntry)
|
||||||
{
|
{
|
||||||
var root = passStore.GetRootDirectory() as PassStoreEntryGroup;
|
currentDirectory.DeleteEntry(updatedEntry.Id);
|
||||||
if (root == null) return;
|
currentDirectory.AddEntry(updatedEntry);
|
||||||
|
|
||||||
root.DeleteEntry(updatedEntry.Id);
|
|
||||||
root.ChildEntries.Add(updatedEntry);
|
|
||||||
OnPropertyChanged(nameof(Passwords));
|
OnPropertyChanged(nameof(Passwords));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user