mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-04-26 18:16:34 +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; }
|
||||
|
||||
IPassStoreDirectory GetRootDirectory();
|
||||
IPassStoreDirectory? GetGroupByType(byte groupType);
|
||||
int GetTotalEntryCount();
|
||||
void Unlock(CompositeKey key);
|
||||
void Lock();
|
||||
|
||||
@@ -6,4 +6,5 @@ namespace KeyKeeper.PasswordStore;
|
||||
public interface IPassStoreDirectory : IEnumerable<PassStoreEntry>
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (ChildEntries == null)
|
||||
|
||||
@@ -49,6 +49,15 @@ public class PassStoreFileAccessor : IPassStore
|
||||
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()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -252,15 +261,24 @@ public class PassStoreFileAccessor : IPassStore
|
||||
|
||||
private PassStoreEntry WriteInitialStoreTree(OuterEncryptionWriter w)
|
||||
{
|
||||
PassStoreEntry root =
|
||||
new PassStoreEntryGroup(
|
||||
Guid.NewGuid(),
|
||||
DateTime.UtcNow,
|
||||
DateTime.UtcNow,
|
||||
Guid.Empty,
|
||||
"",
|
||||
GROUP_TYPE_ROOT
|
||||
);
|
||||
PassStoreEntryGroup defaultGroup = new(
|
||||
Guid.NewGuid(),
|
||||
DateTime.UtcNow,
|
||||
DateTime.UtcNow,
|
||||
Guid.Empty,
|
||||
"",
|
||||
GROUP_TYPE_DEFAULT
|
||||
);
|
||||
PassStoreEntryGroup root = new(
|
||||
Guid.NewGuid(),
|
||||
DateTime.UtcNow,
|
||||
DateTime.UtcNow,
|
||||
Guid.Empty,
|
||||
"",
|
||||
GROUP_TYPE_ROOT,
|
||||
[defaultGroup]
|
||||
);
|
||||
defaultGroup.Parent = root;
|
||||
root.WriteToStream(w);
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using KeyKeeper.PasswordStore;
|
||||
using static KeyKeeper.PasswordStore.FileFormatConstants;
|
||||
|
||||
namespace KeyKeeper.ViewModels;
|
||||
|
||||
@@ -33,7 +34,9 @@ public partial class RepositoryWindowViewModel : ViewModelBase
|
||||
|
||||
private void SwitchToUnlocked()
|
||||
{
|
||||
CurrentPage = new UnlockedRepositoryViewModel(passStore);
|
||||
var directory = passStore.GetGroupByType(GROUP_TYPE_DEFAULT)
|
||||
?? passStore.GetRootDirectory();
|
||||
CurrentPage = new UnlockedRepositoryViewModel(passStore, directory);
|
||||
}
|
||||
|
||||
private void SwitchToLocked()
|
||||
|
||||
@@ -8,13 +8,14 @@ namespace KeyKeeper.ViewModels;
|
||||
public class UnlockedRepositoryViewModel : ViewModelBase
|
||||
{
|
||||
private IPassStore passStore;
|
||||
private IPassStoreDirectory currentDirectory;
|
||||
private bool hasUnsavedChanges;
|
||||
|
||||
public IEnumerable<PassStoreEntryPassword> Passwords
|
||||
{
|
||||
get
|
||||
{
|
||||
return passStore.GetRootDirectory()
|
||||
return currentDirectory
|
||||
.Where(entry => entry is 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;
|
||||
currentDirectory = directory;
|
||||
HasUnsavedChanges = false;
|
||||
}
|
||||
|
||||
@@ -40,7 +42,7 @@ public class UnlockedRepositoryViewModel : ViewModelBase
|
||||
{
|
||||
if (entry is PassStoreEntryPassword)
|
||||
{
|
||||
(passStore.GetRootDirectory() as PassStoreEntryGroup)!.ChildEntries.Add(entry);
|
||||
currentDirectory.AddEntry(entry);
|
||||
HasUnsavedChanges = true;
|
||||
OnPropertyChanged(nameof(Passwords));
|
||||
}
|
||||
@@ -48,18 +50,15 @@ public class UnlockedRepositoryViewModel : ViewModelBase
|
||||
|
||||
public void DeleteEntry(Guid id)
|
||||
{
|
||||
(passStore.GetRootDirectory() as PassStoreEntryGroup)!.DeleteEntry(id);
|
||||
currentDirectory.DeleteEntry(id);
|
||||
HasUnsavedChanges = true;
|
||||
OnPropertyChanged(nameof(Passwords));
|
||||
}
|
||||
|
||||
public void UpdateEntry(PassStoreEntryPassword updatedEntry)
|
||||
{
|
||||
var root = passStore.GetRootDirectory() as PassStoreEntryGroup;
|
||||
if (root == null) return;
|
||||
|
||||
root.DeleteEntry(updatedEntry.Id);
|
||||
root.ChildEntries.Add(updatedEntry);
|
||||
currentDirectory.DeleteEntry(updatedEntry.Id);
|
||||
currentDirectory.AddEntry(updatedEntry);
|
||||
OnPropertyChanged(nameof(Passwords));
|
||||
}
|
||||
|
||||
@@ -68,4 +67,4 @@ public class UnlockedRepositoryViewModel : ViewModelBase
|
||||
passStore.Save();
|
||||
HasUnsavedChanges = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user