Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): add view models + settings logic #233

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
437e5fd
feat(settings): add source folder settings
alexsee Aug 20, 2023
a9910cd
Merge branch 'main' of github.com:alexsee/bsh3 into feat/add-sources-…
alexsee Aug 31, 2023
05e17a9
chore: introduce enum for media type
alexsee Aug 31, 2023
7cb2bda
feat(ui): add target settings page
alexsee Aug 31, 2023
b8d5d9f
feat(ui): adjust target settings
alexsee Aug 31, 2023
c1d7609
chore: code cleaning
alexsee Sep 1, 2023
cbf56d3
feat(ui): add mode settings
alexsee Sep 2, 2023
01616b5
feat(ui): add options settings
alexsee Sep 2, 2023
3da15b0
feat(ui): add advanced settings
alexsee Sep 2, 2023
e4acc82
chore(ui): tweak mode settings layout
alexsee Sep 2, 2023
34dbca7
chore: minor mode changes
alexsee Sep 2, 2023
ab8ef9a
chore: change options settings layout
alexsee Sep 2, 2023
6208d0c
feat(ui): change layout of sources
alexsee Sep 3, 2023
18128fc
chore(ui): adjust layout style of settings
alexsee Sep 3, 2023
332e5fa
fix(ui): combobox selection + can execute
alexsee Sep 3, 2023
bbe5c16
chore: add logic for target + media type change
alexsee Sep 3, 2023
4a4c89f
chore: move properties to respective region
alexsee Sep 3, 2023
6c78c40
chore: rename properties
alexsee Sep 3, 2023
893f8d9
feat(ui): add save settings for enhanced settings
alexsee Sep 3, 2023
beaaa38
feat(ui): add more settings persistency
alexsee Sep 3, 2023
5077e47
feat(ui): add unc authentication
alexsee Sep 3, 2023
5d91acb
feat: add favorite selection
alexsee May 26, 2024
16b7df4
chore: merge
alexsee Sep 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BSH.Engine/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public string Medium
}
}

private int mediumType = 1;
private MediaType mediumType = MediaType.LocalDevice;

public int MediumType
public MediaType MediumType
{
get => mediumType;
set
Expand Down
2 changes: 1 addition & 1 deletion src/BSH.Engine/Contracts/IConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ string Medium
get;
set;
}
int MediumType
MediaType MediumType
{
get;
set;
Expand Down
8 changes: 8 additions & 0 deletions src/BSH.Engine/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Brightbits.BSH.Engine;

public enum MediaType
{
Unset = 0,
LocalDevice = 1,
FileTransferServer = 3
}
2 changes: 1 addition & 1 deletion src/BSH.Engine/Storage/StorageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public StorageFactory(IConfigurationManager configurationManager)

public IStorage GetCurrentStorageProvider()
{
if (configurationManager.MediumType != 3)
if (configurationManager.MediumType != MediaType.FileTransferServer)
{
return new FileSystemStorage(configurationManager);
}
Expand Down
2 changes: 1 addition & 1 deletion src/BSH.Main/Dialogs/frmBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private async void frmBrowser_Load(object sender, EventArgs e)
// get current drive
try
{
if (BackupLogic.ConfigurationManager.MediumType == 1
if (BackupLogic.ConfigurationManager.MediumType == MediaType.LocalDevice
&& BackupLogic.ConfigurationManager.BackupFolder[..1] != "/"
&& !BackupLogic.ConfigurationManager.BackupFolder.StartsWith("\\\\"))
{
Expand Down
12 changes: 6 additions & 6 deletions src/BSH.Main/Dialogs/frmMainTabs/ucConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ private async Task StoreSettingsAsync()
if (cboMedia.SelectedIndex == 1)
{
// FTP
BackupLogic.ConfigurationManager.MediumType = 3;
BackupLogic.ConfigurationManager.MediumType = MediaType.FileTransferServer;
}
else
{
// directory
BackupLogic.ConfigurationManager.MediumType = 1;
BackupLogic.ConfigurationManager.MediumType = MediaType.LocalDevice;

// UNC authentication
if (txtBackupPath.Text.StartsWith(@"\\"))
Expand Down Expand Up @@ -239,7 +239,7 @@ private void LoadSettings()
cboMedia.Tag = "";

// load backup storage
if (BackupLogic.ConfigurationManager.MediumType == 3)
if (BackupLogic.ConfigurationManager.MediumType == MediaType.FileTransferServer)
{
// FTP
cboMedia.SelectedIndex = 1;
Expand Down Expand Up @@ -684,8 +684,8 @@ private async void Button1_Click(object sender, EventArgs e)
if (dlgChangeMedia.cboMedia.SelectedIndex == 0)
{
// directory
BackupLogic.ConfigurationManager.MediumType = 1;
BackupLogic.ConfigurationManager.BackupFolder = Convert.ToString(dlgChangeMedia.lvBackupDrive.SelectedItems[0].Tag) + @"Backups\" + Environment.MachineName + '\\' + Environment.UserName;
BackupLogic.ConfigurationManager.MediumType = MediaType.LocalDevice;
BackupLogic.ConfigurationManager.BackupFolder = Convert.ToString(dlgChangeMedia.lvBackupDrive.SelectedItems[0].Tag) + @"Backups\" + Environment.MachineName + @"\" + Environment.UserName;
BackupLogic.ConfigurationManager.MediaVolumeSerial = Win32Stuff.GetVolumeSerial(BackupLogic.ConfigurationManager.BackupFolder[..1] + @":\");
if (BackupLogic.ConfigurationManager.MediaVolumeSerial == "0")
{
Expand All @@ -695,7 +695,7 @@ private async void Button1_Click(object sender, EventArgs e)
else
{
// FTP server
BackupLogic.ConfigurationManager.MediumType = 3;
BackupLogic.ConfigurationManager.MediumType = MediaType.FileTransferServer;
BackupLogic.ConfigurationManager.FtpHost = dlgChangeMedia.txtFTPServer.Text;
BackupLogic.ConfigurationManager.FtpPort = dlgChangeMedia.txtFTPPort.Text;
BackupLogic.ConfigurationManager.FtpUser = dlgChangeMedia.txtFTPUsername.Text;
Expand Down
12 changes: 6 additions & 6 deletions src/BSH.Main/Dialogs/frmMainTabs/ucDoConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ private async Task ShowWizardStepAsync(int iStep)
if (tcSource.SelectedIndex == 0)
{
// directory
configurationManager.MediumType = 1;
configurationManager.BackupFolder = Convert.ToString(lvBackupDrive.SelectedItems[0].Tag) + @"Backups\" + Environment.MachineName + '\\' + Environment.UserName;
configurationManager.MediumType = MediaType.LocalDevice;
configurationManager.BackupFolder = Convert.ToString(lvBackupDrive.SelectedItems[0].Tag) + @"Backups\" + Environment.MachineName + @"\" + Environment.UserName;
configurationManager.MediaVolumeSerial = Win32Stuff.GetVolumeSerial(configurationManager.BackupFolder.Substring(0, 1) + @":\");
if (configurationManager.MediaVolumeSerial == null || configurationManager.MediaVolumeSerial == "0")
{
Expand All @@ -259,7 +259,7 @@ private async Task ShowWizardStepAsync(int iStep)
else if (tcSource.SelectedIndex == 1)
{
// ftp server
configurationManager.MediumType = 3;
configurationManager.MediumType = MediaType.FileTransferServer;
configurationManager.FtpHost = txtFTPServer.Text;
configurationManager.FtpPort = txtFTPPort.Text;
configurationManager.FtpUser = txtFTPUsername.Text;
Expand All @@ -273,7 +273,7 @@ private async Task ShowWizardStepAsync(int iStep)
else
{
// UNC directory
configurationManager.MediumType = 1;
configurationManager.MediumType = MediaType.LocalDevice;
configurationManager.BackupFolder = txtUNCPath.Text;
configurationManager.MediaVolumeSerial = "";

Expand Down Expand Up @@ -533,7 +533,7 @@ private async Task ShowWizardStepAsync(int iStep)
{
// refresh directory
BackupLogic.ConfigurationManager.BackupFolder = lvBackups.SelectedItems[0].Tag.ToString();
BackupLogic.ConfigurationManager.MediumType = 1;
BackupLogic.ConfigurationManager.MediumType = MediaType.LocalDevice;

await BackupLogic.DbClientFactory.ExecuteNonQueryAsync("UPDATE fileversiontable SET fileType = 1 WHERE fileType = 3");
await BackupLogic.DbClientFactory.ExecuteNonQueryAsync("UPDATE fileversiontable SET fileType = 2 WHERE fileType = 4");
Expand All @@ -549,7 +549,7 @@ private async Task ShowWizardStepAsync(int iStep)
BackupLogic.ConfigurationManager.FtpPort = txtFTPPort2.Text;
BackupLogic.ConfigurationManager.FtpUser = txtFTPUser2.Text;
BackupLogic.ConfigurationManager.FtpCoding = Convert.ToString(cboFtpEncoding2.SelectedItem);
BackupLogic.ConfigurationManager.MediumType = 3;
BackupLogic.ConfigurationManager.MediumType = MediaType.FileTransferServer;

await BackupLogic.DbClientFactory.ExecuteNonQueryAsync("UPDATE fileversiontable SET fileType = 3 WHERE fileType = 1");
await BackupLogic.DbClientFactory.ExecuteNonQueryAsync("UPDATE fileversiontable SET fileType = 4 WHERE fileType = 2");
Expand Down
2 changes: 1 addition & 1 deletion src/BSH.Main/Dialogs/frmMainTabs/ucOverview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private void RefreshInfoText()
}

// backup device
if (BackupLogic.ConfigurationManager.MediumType != 3)
if (BackupLogic.ConfigurationManager.MediumType != MediaType.FileTransferServer)
{
infoText.Append(Resources.DLG_UC_OVERVIEW_LBL_ON_TEXT);
if (BackupLogic.ConfigurationManager.BackupFolder.Substring(0, 1) == "\\")
Expand Down
2 changes: 1 addition & 1 deletion src/BSH.Main/Modules/BackupLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public static void DoBackupWhenDriveIsAvailable(RunBackupMethod RunBackupDelegat
}

// only start, if local device
if (ConfigurationManager.MediumType != 3)
if (ConfigurationManager.MediumType != MediaType.FileTransferServer)
{
dCWatcher = new UsbWatchService();
dCWatcher.StartWatching();
Expand Down
2 changes: 2 additions & 0 deletions src/BSH.MainApp/BSH.MainApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="WinUIEx" Version="2.3.3" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.0.230828-rc" />
<PackageReference Include="CommunityToolkit.WinUI.UI" Version="7.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BSH.Engine\BSH.Engine.csproj">
Expand Down
17 changes: 17 additions & 0 deletions src/BSH.MainApp/Helpers/EnumComparisionConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;

namespace BSH.MainApp.Helpers;

public class EnumComparisonConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return ((int)value).Equals(parameter);
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return value?.Equals(true) == true ? parameter : DependencyProperty.UnsetValue;
}
}
52 changes: 52 additions & 0 deletions src/BSH.MainApp/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,56 @@
<data name="DATETIME_FORMAT" xml:space="preserve">
<value>dd. MMM yyyy hh:mm</value>
</data>
<data name="MediaType_FileTransferServer" xml:space="preserve">
<value>File Transfer Protocol (FTP)</value>
</data>
<data name="MediaType_LocalDevice" xml:space="preserve">
<value>Local Device</value>
</data>
<data name="MsgBox_Ftp_Successful_Text" xml:space="preserve">
<value>The connection test to the specified FTP server was successful.</value>
</data>
<data name="MsgBox_Ftp_Successful_Title" xml:space="preserve">
<value>Connection to FTP Server successful</value>
</data>
<data name="MsgBox_Ftp_Unuccessful_Text" xml:space="preserve">
<value>The connection test to the specified FTP server was unsuccessful.</value>
</data>
<data name="MsgBox_Ftp_Unuccessful_Title" xml:space="preserve">
<value>Connection to FTP Server unsuccessful</value>
</data>
<data name="MsgBox_MediaType_Change_Text" xml:space="preserve">
<value>Existing backups will be deleted.

If you decide to switch the media type, all existing backups will be deleted. Switching the backup device type is not supported.

Do you want to contine (ALL BACKUPS WILL BE DELETED)?</value>
</data>
<data name="MsgBox_MediaType_Change_Title" xml:space="preserve">
<value>Existing backups deletion</value>
</data>
<data name="MsgBox_No" xml:space="preserve">
<value>&amp;No</value>
</data>
<data name="MsgBox_Yes" xml:space="preserve">
<value>&amp;Yes</value>
</data>
<data name="MsgBox_Cancel" xml:space="preserve">
<value>&amp;Cancel</value>
</data>
<data name="MsgBox_LocalPath_Change_Move" xml:space="preserve">
<value>&amp;Move</value>
</data>
<data name="MsgBox_LocalPath_Change_Text" xml:space="preserve">
<value>You can decide to either use or move the location of the backups:

Use: You already moved the path to the backups or the paths have changed.
Move: You want to move the backups to a different path and want BSH to move the files.</value>
</data>
<data name="MsgBox_LocalPath_Change_Title" xml:space="preserve">
<value>Change local path</value>
</data>
<data name="MsgBox_LocalPath_Change_Use" xml:space="preserve">
<value>&amp;Use</value>
</data>
</root>
21 changes: 18 additions & 3 deletions src/BSH.MainApp/ViewModels/BrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public partial class BrowserViewModel : ObservableRecipient, INavigationAware
private FileOrFolderItem? currentItem;

[ObservableProperty]
private string blub;
private string? currentFavorite;

[ObservableProperty]
private string searchTerms;

public ObservableCollection<FileOrFolderItem> CurrentFolderPath { get; } = new();

Expand Down Expand Up @@ -50,9 +53,21 @@ private async Task LoadVersion()
.ToList();

this.Favorites.Clear();
sources.ForEach(x => this.Favorites.Add(x));
sources.ForEach(this.Favorites.Add);
CurrentFavorite = sources[0];

await LoadFolderAsync(CurrentVersion.Id, CurrentFavorite);
}

[RelayCommand]
private async Task LoadFavorite()
{
if (CurrentVersion == null || CurrentFavorite == null)
{
return;
}

await LoadFolderAsync(CurrentVersion.Id, sources[0]);
await LoadFolderAsync(CurrentVersion.Id, CurrentFavorite);
}

[RelayCommand]
Expand Down
Loading
Loading