From fb6d803a5bf0fb49a72c6cb1b88b9bc128cc3fc4 Mon Sep 17 00:00:00 2001 From: Arnob Paul Date: Fri, 12 Jan 2024 00:35:51 -0500 Subject: [PATCH] [Enhancement] Add textbox for folder browser (resolve #10) and miscellaneous improvement Issue: https://github.com/arnobpl/SymlinkCreator/issues/10 --- SymlinkCreator/App.config | 9 ++ SymlinkCreator/Properties/Annotations.cs | 2 +- SymlinkCreator/Properties/AssemblyInfo.cs | 16 +-- SymlinkCreator/SymlinkCreator.csproj | 117 +++++++++++++++++- .../core/ApplicationConfiguration.cs | 2 +- SymlinkCreator/core/SymlinkAgent.cs | 1 - SymlinkCreator/packages.config | 59 +++++++++ .../ui/mainWindow/MainWindow.xaml.cs | 47 +++---- .../ui/mainWindow/MainWindowViewModel.cs | 4 +- .../ui/utility/NativeAdminShieldIcon.cs | 2 +- .../SymlinkCreatorTests.csproj | 3 + SymlinkCreatorTests/SymlinkUtilityTest.cs | 4 +- SymlinkCreatorTests/app.config | 11 ++ 13 files changed, 234 insertions(+), 43 deletions(-) create mode 100644 SymlinkCreator/packages.config create mode 100644 SymlinkCreatorTests/app.config diff --git a/SymlinkCreator/App.config b/SymlinkCreator/App.config index be93275..da5e47a 100644 --- a/SymlinkCreator/App.config +++ b/SymlinkCreator/App.config @@ -4,4 +4,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/SymlinkCreator/Properties/Annotations.cs b/SymlinkCreator/Properties/Annotations.cs index 87cf259..31e7a30 100644 --- a/SymlinkCreator/Properties/Annotations.cs +++ b/SymlinkCreator/Properties/Annotations.cs @@ -304,7 +304,7 @@ public sealed class CannotApplyEqualityOperatorAttribute : Attribute /// class MyComponent : IComponent { } /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - [BaseTypeRequired(typeof (Attribute))] + [BaseTypeRequired(typeof(Attribute))] public sealed class BaseTypeRequiredAttribute : Attribute { public BaseTypeRequiredAttribute([NotNull] Type baseType) diff --git a/SymlinkCreator/Properties/AssemblyInfo.cs b/SymlinkCreator/Properties/AssemblyInfo.cs index e59c2b9..0d999af 100644 --- a/SymlinkCreator/Properties/AssemblyInfo.cs +++ b/SymlinkCreator/Properties/AssemblyInfo.cs @@ -11,7 +11,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Arnob Paul")] [assembly: AssemblyProduct("Symlink Creator")] -[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -33,18 +33,18 @@ [assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) + //(used if a resource is not found in the page, + // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) )] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // @@ -52,5 +52,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.2")] -[assembly: AssemblyFileVersion("1.2.2")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.3")] +[assembly: AssemblyFileVersion("1.2.3")] \ No newline at end of file diff --git a/SymlinkCreator/SymlinkCreator.csproj b/SymlinkCreator/SymlinkCreator.csproj index 5576757..6a3a68f 100644 --- a/SymlinkCreator/SymlinkCreator.csproj +++ b/SymlinkCreator/SymlinkCreator.csproj @@ -40,16 +40,120 @@ + + packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll + + + packages\Microsoft.Win32.Registry.AccessControl.8.0.0\lib\net462\Microsoft.Win32.Registry.AccessControl.dll + + + packages\Microsoft.Win32.SystemEvents.8.0.0\lib\net462\Microsoft.Win32.SystemEvents.dll + + + packages\Microsoft-WindowsAPICodePack-Core.1.1.5\lib\net48\Microsoft.WindowsAPICodePack.dll + + + packages\Microsoft-WindowsAPICodePack-Shell.1.1.5\lib\net48\Microsoft.WindowsAPICodePack.Shell.dll + - + + packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + packages\System.CodeDom.8.0.0\lib\net462\System.CodeDom.dll + + + packages\System.Configuration.ConfigurationManager.8.0.0\lib\net462\System.Configuration.ConfigurationManager.dll + + + packages\System.Data.Odbc.8.0.0\lib\net462\System.Data.Odbc.dll + + + packages\System.Data.OleDb.8.0.0\lib\net462\System.Data.OleDb.dll + + + packages\System.Data.SqlClient.4.8.5\lib\net461\System.Data.SqlClient.dll + + + packages\System.Diagnostics.EventLog.8.0.0\lib\net462\System.Diagnostics.EventLog.dll + + + packages\System.Diagnostics.PerformanceCounter.8.0.0\lib\net462\System.Diagnostics.PerformanceCounter.dll + - + + packages\System.Drawing.Common.8.0.0\lib\net462\System.Drawing.Common.dll + + + packages\System.IO.4.3.0\lib\net462\System.IO.dll + True + True + + + packages\System.IO.FileSystem.AccessControl.5.0.0\lib\net461\System.IO.FileSystem.AccessControl.dll + + + packages\System.IO.Packaging.8.0.0\lib\net462\System.IO.Packaging.dll + + + packages\System.IO.Pipes.AccessControl.5.0.0\lib\net461\System.IO.Pipes.AccessControl.dll + + + packages\System.IO.Ports.8.0.0\lib\net462\System.IO.Ports.dll + + + packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll + True + True + + + packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Security.Permissions.8.0.0\lib\net462\System.Security.Permissions.dll + + + packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + packages\System.ServiceModel.Duplex.4.10.0\lib\net461\System.ServiceModel.Duplex.dll + + + packages\System.ServiceModel.Http.4.10.0\lib\net461\System.ServiceModel.Http.dll + + + packages\System.ServiceModel.NetTcp.4.10.0\lib\net461\System.ServiceModel.NetTcp.dll + + + packages\System.ServiceModel.Primitives.4.10.0\lib\net461\System.ServiceModel.Primitives.dll + + + packages\System.ServiceModel.Security.4.10.0\lib\net461\System.ServiceModel.Security.dll + + + packages\System.ServiceModel.Syndication.8.0.0\lib\net462\System.ServiceModel.Syndication.dll + + + packages\System.ServiceProcess.ServiceController.8.0.0\lib\net462\System.ServiceProcess.ServiceController.dll + + + packages\System.Text.Encoding.CodePages.8.0.0\lib\net462\System.Text.Encoding.CodePages.dll + + + packages\System.Threading.AccessControl.8.0.0\lib\net462\System.Threading.AccessControl.dll + + + packages\System.Web.Services.Description.4.10.0\lib\net461\System.Web.Services.Description.dll + - - - - 4.0 @@ -85,6 +189,7 @@ + diff --git a/SymlinkCreator/core/ApplicationConfiguration.cs b/SymlinkCreator/core/ApplicationConfiguration.cs index f1bfeb2..f057633 100644 --- a/SymlinkCreator/core/ApplicationConfiguration.cs +++ b/SymlinkCreator/core/ApplicationConfiguration.cs @@ -81,7 +81,7 @@ public static string ApplicationCompany #region web addresses - public static string CompanyWebAddress => "https://github.com/arnobpl"; + public static string CompanyWebAddress => "https://github.com/arnobpl/SymlinkCreator"; #endregion } diff --git a/SymlinkCreator/core/SymlinkAgent.cs b/SymlinkCreator/core/SymlinkAgent.cs index e5c1c45..f599502 100644 --- a/SymlinkCreator/core/SymlinkAgent.cs +++ b/SymlinkCreator/core/SymlinkAgent.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Text; diff --git a/SymlinkCreator/packages.config b/SymlinkCreator/packages.config new file mode 100644 index 0000000..2e1ec98 --- /dev/null +++ b/SymlinkCreator/packages.config @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SymlinkCreator/ui/mainWindow/MainWindow.xaml.cs b/SymlinkCreator/ui/mainWindow/MainWindow.xaml.cs index f4967c9..43e5957 100644 --- a/SymlinkCreator/ui/mainWindow/MainWindow.xaml.cs +++ b/SymlinkCreator/ui/mainWindow/MainWindow.xaml.cs @@ -1,17 +1,18 @@ -using System; +using Microsoft.WindowsAPICodePack.Dialogs; +using SymlinkCreator.core; +using SymlinkCreator.ui.utility; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Windows; -using System.Windows.Forms; -using SymlinkCreator.core; -using SymlinkCreator.ui.utility; using DataFormats = System.Windows.DataFormats; using DragEventArgs = System.Windows.DragEventArgs; using MessageBox = System.Windows.MessageBox; using OpenFileDialog = Microsoft.Win32.OpenFileDialog; + namespace SymlinkCreator.ui.mainWindow { /// @@ -32,7 +33,8 @@ public MainWindow() #region fields - private string _previouslySelectedFolderPath = ""; + private string _previouslySelectedAddFolderPath = ""; + private string _previouslySelectedDestinationFolderPath = ""; #endregion @@ -72,16 +74,17 @@ private void AddFilesButton_OnClick(object sender, RoutedEventArgs e) private void AddFolderButton_OnClick(object sender, RoutedEventArgs e) { - using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) + + CommonOpenFileDialog folderBrowserDialog = new CommonOpenFileDialog { - folderBrowserDialog.SelectedPath = _previouslySelectedFolderPath; - DialogResult result = folderBrowserDialog.ShowDialog(); + IsFolderPicker = true, + InitialDirectory = _previouslySelectedAddFolderPath + }; - if (result == System.Windows.Forms.DialogResult.OK) - { - AddToSourceFileOrFolderList(folderBrowserDialog.SelectedPath); - _previouslySelectedFolderPath = folderBrowserDialog.SelectedPath; - } + if (folderBrowserDialog.ShowDialog() == CommonFileDialogResult.Ok) + { + AddToSourceFileOrFolderList(folderBrowserDialog.FileName); + _previouslySelectedAddFolderPath = folderBrowserDialog.FileName; } } @@ -90,14 +93,16 @@ private void DestinationPathBrowseButton_OnClick(object sender, RoutedEventArgs MainWindowViewModel mainWindowViewModel = this.DataContext as MainWindowViewModel; if (mainWindowViewModel == null) return; - using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) + CommonOpenFileDialog folderBrowserDialog = new CommonOpenFileDialog { - DialogResult result = folderBrowserDialog.ShowDialog(); + IsFolderPicker = true, + InitialDirectory = _previouslySelectedDestinationFolderPath + }; - if (result == System.Windows.Forms.DialogResult.OK) - { - mainWindowViewModel.DestinationPath = folderBrowserDialog.SelectedPath; - } + if (folderBrowserDialog.ShowDialog() == CommonFileDialogResult.Ok) + { + mainWindowViewModel.DestinationPath = folderBrowserDialog.FileName; + _previouslySelectedDestinationFolderPath = folderBrowserDialog.FileName; } } @@ -124,7 +129,7 @@ private void SourceFileOrFolderListView_OnDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { - string[] droppedFileOrFolderList = (string[]) e.Data.GetData(DataFormats.FileDrop); + string[] droppedFileOrFolderList = (string[])e.Data.GetData(DataFormats.FileDrop); AddToSourceFileOrFolderList(droppedFileOrFolderList); } } @@ -133,7 +138,7 @@ private void DestinationPathTextBox_OnDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { - string[] pathList = (string[]) e.Data.GetData(DataFormats.FileDrop); + string[] pathList = (string[])e.Data.GetData(DataFormats.FileDrop); if (pathList != null) { string droppedDestinationPath = pathList[0]; diff --git a/SymlinkCreator/ui/mainWindow/MainWindowViewModel.cs b/SymlinkCreator/ui/mainWindow/MainWindowViewModel.cs index 05e84ab..368a60a 100644 --- a/SymlinkCreator/ui/mainWindow/MainWindowViewModel.cs +++ b/SymlinkCreator/ui/mainWindow/MainWindowViewModel.cs @@ -1,7 +1,7 @@ -using System.Collections.ObjectModel; +using SymlinkCreator.Properties; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; -using SymlinkCreator.Properties; namespace SymlinkCreator.ui.mainWindow { diff --git a/SymlinkCreator/ui/utility/NativeAdminShieldIcon.cs b/SymlinkCreator/ui/utility/NativeAdminShieldIcon.cs index fd5398c..266506b 100644 --- a/SymlinkCreator/ui/utility/NativeAdminShieldIcon.cs +++ b/SymlinkCreator/ui/utility/NativeAdminShieldIcon.cs @@ -34,7 +34,7 @@ public static BitmapSource GetNativeShieldIcon() if (Environment.OSVersion.Version.Major >= 6) { SHSTOCKICONINFO sii = new SHSTOCKICONINFO(); - sii.cbSize = (UInt32) Marshal.SizeOf(typeof (SHSTOCKICONINFO)); + sii.cbSize = (UInt32)Marshal.SizeOf(typeof(SHSTOCKICONINFO)); Marshal.ThrowExceptionForHR(SHGetStockIconInfo(SHSTOCKICONID.SIID_SHIELD, SHGSI.SHGSI_ICON | SHGSI.SHGSI_SMALLICON, diff --git a/SymlinkCreatorTests/SymlinkCreatorTests.csproj b/SymlinkCreatorTests/SymlinkCreatorTests.csproj index 5d2ed96..8dbf6b0 100644 --- a/SymlinkCreatorTests/SymlinkCreatorTests.csproj +++ b/SymlinkCreatorTests/SymlinkCreatorTests.csproj @@ -60,6 +60,9 @@ SymlinkCreator + + + diff --git a/SymlinkCreatorTests/SymlinkUtilityTest.cs b/SymlinkCreatorTests/SymlinkUtilityTest.cs index 58b34b3..608b7b2 100644 --- a/SymlinkCreatorTests/SymlinkUtilityTest.cs +++ b/SymlinkCreatorTests/SymlinkUtilityTest.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using SymlinkCreator.core; +using System.Collections.Generic; namespace SymlinkCreatorTests { diff --git a/SymlinkCreatorTests/app.config b/SymlinkCreatorTests/app.config new file mode 100644 index 0000000..1696df6 --- /dev/null +++ b/SymlinkCreatorTests/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file