diff --git a/Directory.Build.props b/Directory.Build.props
index c761ee0..49c656b 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -19,7 +19,7 @@
- CS0169;CS0649;IDE0017;IDE0044;IDE0060;IDE0090;NU1701;NU1702
+ C4100;CS0169;CS0649;IDE0017;IDE0044;IDE0060;IDE0090;NU1701;NU1702
$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))
diff --git a/FileRenamer/Helpers/Root/IOHelper.cs b/FileRenamer/Helpers/Root/IOHelper.cs
index 185fd2d..3460cb8 100644
--- a/FileRenamer/Helpers/Root/IOHelper.cs
+++ b/FileRenamer/Helpers/Root/IOHelper.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Text;
namespace FileRenamer.Helpers.Root
{
@@ -19,5 +20,18 @@ public static bool IsDir(string filepath)
return false;
}
}
+
+ ///
+ /// 过滤不合法的文件路径字符
+ ///
+ public static string FilterInvalidPathChars(string path)
+ {
+ StringBuilder titleBuilder = new StringBuilder(path);
+ foreach (char rInvalidChar in Path.GetInvalidPathChars())
+ {
+ titleBuilder = titleBuilder.Replace(rInvalidChar.ToString(), string.Empty);
+ }
+ return titleBuilder.ToString();
+ }
}
}
diff --git a/FileRenamer/Program.cs b/FileRenamer/Program.cs
index 0a7d88f..bcd7f1f 100644
--- a/FileRenamer/Program.cs
+++ b/FileRenamer/Program.cs
@@ -47,7 +47,14 @@ public static void Main(string[] args)
{
if (args[0] is "FileName" || args[0] is "ExtensionName" || args[0] is "UpperAndLowerCase" || args[0] is "FileProperties")
{
- CheckProcessState(args[0]);
+ if (args.Length is 1)
+ {
+ CheckProcessState(args[0]);
+ }
+ else if (args.Length is 2)
+ {
+ CheckProcessState(string.Format("{0} {1}", args[0], args[1]));
+ }
}
}
}
diff --git a/FileRenamer/Properties/AssemblyInfo.cs b/FileRenamer/Properties/AssemblyInfo.cs
index 05d8953..9f93ac8 100644
--- a/FileRenamer/Properties/AssemblyInfo.cs
+++ b/FileRenamer/Properties/AssemblyInfo.cs
@@ -4,14 +4,14 @@
// 程序集信息设置
[assembly: AssemblyCopyright("Copyright ©2023 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("文件重命名工具")]
-[assembly: AssemblyFileVersion("1.1.1002.0")]
-[assembly: AssemblyInformationalVersion("1.1.1002.0")]
+[assembly: AssemblyFileVersion("1.2.1002.0")]
+[assembly: AssemblyInformationalVersion("1.2.1002.0")]
[assembly: AssemblyProduct("文件重命名工具")]
[assembly: AssemblyTitle("文件重命名工具")]
-[assembly: AssemblyVersion("1.1.1002.0")]
+[assembly: AssemblyVersion("1.2.1002.0")]
// 设置程序集对COM组件的访问权限
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("29636fb7-743c-426a-8715-a91f32d2d04a")]
+[assembly: Guid("29636FB7-743C-426A-8715-A91F32D2D04A")]
diff --git a/FileRenamer/Services/Controls/Settings/FileShellMenuService.cs b/FileRenamer/Services/Controls/Settings/FileShellMenuService.cs
index c0fc117..690dba3 100644
--- a/FileRenamer/Services/Controls/Settings/FileShellMenuService.cs
+++ b/FileRenamer/Services/Controls/Settings/FileShellMenuService.cs
@@ -1,7 +1,5 @@
using FileRenamer.Extensions.DataType.Constant;
using FileRenamer.Services.Root;
-using System;
-using System.Diagnostics;
namespace FileRenamer.Services.Controls.Settings
{
diff --git a/FileRenamer/Views/Forms/MainForm.cs b/FileRenamer/Views/Forms/MainForm.cs
index 9990d95..dcb6b5a 100644
--- a/FileRenamer/Views/Forms/MainForm.cs
+++ b/FileRenamer/Views/Forms/MainForm.cs
@@ -1,6 +1,7 @@
using FileReanmer.WindowsAPI.PInvoke.User32;
using FileRenamer.Helpers.Controls;
using FileRenamer.Helpers.Root;
+using FileRenamer.Models;
using FileRenamer.Services.Controls.Settings;
using FileRenamer.Services.Window;
using FileRenamer.Strings;
@@ -17,7 +18,10 @@
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
+using System.Linq;
using System.Runtime.InteropServices;
+using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.UI;
using Windows.UI.Xaml;
@@ -200,11 +204,11 @@ private void OnActualThemeChanged(FrameworkElement sender, object args)
{
if (sender.ActualTheme is ElementTheme.Light)
{
- MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 243, 243, 243));
+ MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 240, 243, 249));
}
else
{
- MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 32, 32, 32));
+ MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 20, 20, 20));
}
}
}
@@ -256,21 +260,184 @@ protected override void WndProc(ref Message m)
await ContentDialogHelper.ShowAsync(new AppRunningDialog(), MainPage);
});
}
- else if (copyDataStruct.lpData is "FileName")
+ else if (copyDataStruct.lpData.Contains("FileName"))
{
- NavigationService.NavigateTo(typeof(FileNamePage));
+ if (NavigationService.GetCurrentPageType() != typeof(FileNamePage))
+ {
+ NavigationService.NavigateTo(typeof(FileNamePage));
+ }
+
+ if (copyDataStruct.lpData.Contains("ShellContextMenu"))
+ {
+ FileNamePage fileNamePage = NavigationService.NavigationFrame.Content as FileNamePage;
+
+ if (fileNamePage is not null)
+ {
+ Task.Run(() =>
+ {
+ try
+ {
+ if (File.Exists(Program.TempFilePath))
+ {
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] fileNamePathList = tempFileText.Split('\n').Where(item => !string.IsNullOrWhiteSpace(item)).ToArray();
+
+ foreach (string fileNamePath in fileNamePathList)
+ {
+ string fileName = IOHelper.FilterInvalidPathChars(fileNamePath);
+
+ BeginInvoke(() =>
+ {
+ fileNamePage.FileNameDataList.Add(new OldAndNewNameModel()
+ {
+ OriginalFileName = Path.GetFileName(fileName),
+ OriginalFilePath = fileName
+ });
+ });
+ }
+ }
+ }
+ catch (Exception) { }
+ });
+ }
+ }
}
- else if (copyDataStruct.lpData is "ExtensionName")
+ else if (copyDataStruct.lpData.Contains("ExtensionName"))
{
- NavigationService.NavigateTo(typeof(ExtensionNamePage));
+ if (NavigationService.GetCurrentPageType() != typeof(ExtensionNamePage))
+ {
+ NavigationService.NavigateTo(typeof(ExtensionNamePage));
+ }
+
+ if (copyDataStruct.lpData.Contains("ShellContextMenu"))
+ {
+ ExtensionNamePage extensionNamePage = NavigationService.NavigationFrame.Content as ExtensionNamePage;
+
+ if (extensionNamePage is not null)
+ {
+ Task.Run(() =>
+ {
+ try
+ {
+ if (File.Exists(Program.TempFilePath))
+ {
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] extensionNamePathList = tempFileText.Split('\n').Where(item => !string.IsNullOrEmpty(item)).ToArray();
+
+ foreach (string extensionNamePath in extensionNamePathList)
+ {
+ string extensionName = IOHelper.FilterInvalidPathChars(extensionNamePath);
+
+ if (!IOHelper.IsDir(extensionName))
+ {
+ BeginInvoke(() =>
+ {
+ extensionNamePage.ExtensionNameDataList.Add(new OldAndNewNameModel()
+ {
+ OriginalFileName = Path.GetFileName(extensionName),
+ OriginalFilePath = extensionName
+ });
+ });
+ }
+ }
+ }
+ }
+ catch (Exception) { }
+ });
+ }
+ }
}
- else if (copyDataStruct.lpData is "UpperAndLowerCase")
+ else if (copyDataStruct.lpData.Contains("UpperAndLowerCase"))
{
- NavigationService.NavigateTo(typeof(UpperAndLowerCasePage));
+ if (NavigationService.GetCurrentPageType() != typeof(UpperAndLowerCase))
+ {
+ NavigationService.NavigateTo(typeof(UpperAndLowerCasePage));
+ }
+
+ if (copyDataStruct.lpData.Contains("ShellContextMenu"))
+ {
+ UpperAndLowerCasePage upperAndLowerCasePage = NavigationService.NavigationFrame.Content as UpperAndLowerCasePage;
+
+ if (upperAndLowerCasePage is not null)
+ {
+ Task.Run(() =>
+ {
+ try
+ {
+ if (File.Exists(Program.TempFilePath))
+ {
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] upperAndLowerCasePathList = tempFileText.Split('\n').Where(item => !string.IsNullOrEmpty(item)).ToArray();
+
+ foreach (string upperAndLowerCasePath in upperAndLowerCasePathList)
+ {
+ string upperAndLowerCase = IOHelper.FilterInvalidPathChars(upperAndLowerCasePath);
+
+ BeginInvoke(() =>
+ {
+ upperAndLowerCasePage.UpperAndLowerCaseDataList.Add(new OldAndNewNameModel()
+ {
+ OriginalFileName = Path.GetFileName(upperAndLowerCase),
+ OriginalFilePath = upperAndLowerCase
+ });
+ });
+ }
+ }
+ }
+ catch (Exception) { }
+ });
+ }
+ }
}
- else if (copyDataStruct.lpData is "FileProperties")
+ else if (copyDataStruct.lpData.Contains("FileProperties"))
{
- NavigationService.NavigateTo(typeof(FilePropertiesPage));
+ if (NavigationService.GetCurrentPageType() != typeof(FilePropertiesPage))
+ {
+ NavigationService.NavigateTo(typeof(FilePropertiesPage));
+ }
+
+ if (copyDataStruct.lpData.Contains("ShellContextMenu"))
+ {
+ FilePropertiesPage filePropertiesPage = NavigationService.NavigationFrame.Content as FilePropertiesPage;
+
+ if (filePropertiesPage is not null)
+ {
+ Task.Run(() =>
+ {
+ try
+ {
+ if (File.Exists(Program.TempFilePath))
+ {
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] filePropertiesPathList = tempFileText.Split('\n').Where(item => !string.IsNullOrEmpty(item)).ToArray();
+
+ foreach (string filePropertiesPath in filePropertiesPathList)
+ {
+ string fileProperties = IOHelper.FilterInvalidPathChars(filePropertiesPath);
+
+ BeginInvoke(() =>
+ {
+ filePropertiesPage.FilePropertiesDataList.Add(new OldAndNewPropertiesModel()
+ {
+ FileName = Path.GetFileName(fileProperties),
+ FilePath = fileProperties
+ });
+ });
+ }
+ }
+ }
+ catch (Exception) { }
+ });
+ }
+ }
}
break;
};
@@ -352,11 +519,11 @@ public void SetWindowBackdrop()
DwmApiLibrary.DwmSetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, ref noBackdrop, Marshal.SizeOf(typeof(int)));
if (MainPage.ActualTheme is ElementTheme.Light)
{
- MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 243, 243, 243));
+ MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 240, 243, 249));
}
else
{
- MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 32, 32, 32));
+ MainPage.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 20, 20, 20));
}
}
else if (BackdropService.AppBackdrop.SelectedValue == BackdropService.BackdropList[1].SelectedValue)
diff --git a/FileRenamer/Views/Pages/MainPage.xaml.cs b/FileRenamer/Views/Pages/MainPage.xaml.cs
index 22d1bac..f106a37 100644
--- a/FileRenamer/Views/Pages/MainPage.xaml.cs
+++ b/FileRenamer/Views/Pages/MainPage.xaml.cs
@@ -11,6 +11,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
+using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -270,114 +271,156 @@ public void OnNavigationViewLoaded(object sender, RoutedEventArgs args)
{
if (arguments[1] is "FileName")
{
- try
+ FileNamePage fileNamePage = MainFrame.Content as FileNamePage;
+
+ if (fileNamePage is not null)
{
- if (File.Exists(Program.TempFilePath))
+ Task.Run(() =>
{
- string tempFileText = File.ReadAllText(Program.TempFilePath);
- File.Delete(tempFileText);
-
- FileNamePage fileNamePage = MainFrame.Content as FileNamePage;
- if (fileNamePage is not null)
+ try
{
- string[] fileNamePathList = tempFileText.Split('\n');
-
- foreach (string fileNamePath in fileNamePathList)
+ if (File.Exists(Program.TempFilePath))
{
- fileNamePage.FileNameDataList.Add(new OldAndNewNameModel()
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] fileNamePathList = tempFileText.Split('\n').Where(item => !string.IsNullOrWhiteSpace(item)).ToArray();
+
+ foreach (string fileNamePath in fileNamePathList)
{
- OriginalFileName = Path.GetFileName(fileNamePath),
- OriginalFilePath = fileNamePath
- });
+ string fileName = IOHelper.FilterInvalidPathChars(fileNamePath);
+
+ Program.MainWindow.BeginInvoke(() =>
+ {
+ fileNamePage.FileNameDataList.Add(new OldAndNewNameModel()
+ {
+ OriginalFileName = Path.GetFileName(fileName),
+ OriginalFilePath = fileName
+ });
+ });
+ }
}
}
- }
+ catch (Exception) { }
+ });
}
- catch (Exception) { }
}
else if (arguments[1] is "ExtensionName")
{
NavigationService.NavigateTo(typeof(ExtensionNamePage));
- try
+
+ ExtensionNamePage extensionNamePage = MainFrame.Content as ExtensionNamePage;
+
+ if (extensionNamePage is not null)
{
- if (File.Exists(Program.TempFilePath))
+ Task.Run(() =>
{
- string tempFileText = File.ReadAllText(Program.TempFilePath);
- File.Delete(tempFileText);
-
- ExtensionNamePage extensionNamePage = MainFrame.Content as ExtensionNamePage;
- if (extensionNamePage is not null)
+ try
{
- string[] extensionNamePathList = tempFileText.Split('\n');
-
- foreach (string extensionNamePath in extensionNamePathList)
+ if (File.Exists(Program.TempFilePath))
{
- extensionNamePage.ExtensionNameDataList.Add(new OldAndNewNameModel()
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] extensionNamePathList = tempFileText.Split('\n').Where(item => !string.IsNullOrEmpty(item)).ToArray();
+
+ foreach (string extensionNamePath in extensionNamePathList)
{
- OriginalFileName = Path.GetFileName(extensionNamePath),
- OriginalFilePath = extensionNamePath
- });
+ string extensionName = IOHelper.FilterInvalidPathChars(extensionNamePath);
+
+ if (!IOHelper.IsDir(extensionName))
+ {
+ Program.MainWindow.BeginInvoke(() =>
+ {
+ extensionNamePage.ExtensionNameDataList.Add(new OldAndNewNameModel()
+ {
+ OriginalFileName = Path.GetFileName(extensionName),
+ OriginalFilePath = extensionName
+ });
+ });
+ }
+ }
}
}
- }
+ catch (Exception) { }
+ });
}
- catch (Exception) { }
}
else if (arguments[1] is "UpperAndLowerCase")
{
NavigationService.NavigateTo(typeof(UpperAndLowerCasePage));
- try
+
+ UpperAndLowerCasePage upperAndLowerCasePage = MainFrame.Content as UpperAndLowerCasePage;
+
+ if (upperAndLowerCasePage is not null)
{
- if (File.Exists(Program.TempFilePath))
+ Task.Run(() =>
{
- string tempFileText = File.ReadAllText(Program.TempFilePath);
- File.Delete(tempFileText);
-
- UpperAndLowerCasePage upperAndLowerCasePage = MainFrame.Content as UpperAndLowerCasePage;
- if (upperAndLowerCasePage is not null)
+ try
{
- string[] upperAndLowerCasePathList = tempFileText.Split('\n');
-
- foreach (string upperAndLowerCasePath in upperAndLowerCasePathList)
+ if (File.Exists(Program.TempFilePath))
{
- upperAndLowerCasePage.UpperAndLowerCaseDataList.Add(new OldAndNewNameModel()
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] upperAndLowerCasePathList = tempFileText.Split('\n').Where(item => !string.IsNullOrEmpty(item)).ToArray();
+
+ foreach (string upperAndLowerCasePath in upperAndLowerCasePathList)
{
- OriginalFileName = Path.GetFileName(upperAndLowerCasePath),
- OriginalFilePath = upperAndLowerCasePath
- });
+ string upperAndLowerCase = IOHelper.FilterInvalidPathChars(upperAndLowerCasePath);
+
+ Program.MainWindow.BeginInvoke(() =>
+ {
+ upperAndLowerCasePage.UpperAndLowerCaseDataList.Add(new OldAndNewNameModel()
+ {
+ OriginalFileName = Path.GetFileName(upperAndLowerCase),
+ OriginalFilePath = upperAndLowerCase
+ });
+ });
+ }
}
}
- }
+ catch (Exception) { }
+ });
}
- catch (Exception) { }
}
else if (arguments[1] is "FileProperties")
{
NavigationService.NavigateTo(typeof(FilePropertiesPage));
- try
+
+ FilePropertiesPage filePropertiesPage = MainFrame.Content as FilePropertiesPage;
+
+ if (filePropertiesPage is not null)
{
- if (File.Exists(Program.TempFilePath))
+ Task.Run(() =>
{
- string tempFileText = File.ReadAllText(Program.TempFilePath);
- File.Delete(tempFileText);
-
- FilePropertiesPage filePropertiesPage = MainFrame.Content as FilePropertiesPage;
- if (filePropertiesPage is not null)
+ try
{
- string[] filePropertiesPathList = tempFileText.Split('\n');
-
- foreach (string filePropertiesPath in filePropertiesPathList)
+ if (File.Exists(Program.TempFilePath))
{
- filePropertiesPage.FilePropertiesDataList.Add(new OldAndNewPropertiesModel()
+ string tempFileText = File.ReadAllText(Program.TempFilePath);
+ File.Delete(Program.TempFilePath);
+
+ string[] filePropertiesPathList = tempFileText.Split('\n').Where(item => !string.IsNullOrEmpty(item)).ToArray();
+
+ foreach (string filePropertiesPath in filePropertiesPathList)
{
- FileName = Path.GetFileName(filePropertiesPath),
- FilePath = filePropertiesPath
- });
+ string fileProperties = IOHelper.FilterInvalidPathChars(filePropertiesPath);
+
+ Program.MainWindow.BeginInvoke(() =>
+ {
+ filePropertiesPage.FilePropertiesDataList.Add(new OldAndNewPropertiesModel()
+ {
+ FileName = Path.GetFileName(fileProperties),
+ FilePath = fileProperties
+ });
+ });
+ }
}
}
- }
+ catch (Exception) { }
+ });
}
- catch (Exception) { }
}
}
}
diff --git a/FileRenamerPackage/Package.appxmanifest b/FileRenamerPackage/Package.appxmanifest
index 708c5c8..93cc9be 100644
--- a/FileRenamerPackage/Package.appxmanifest
+++ b/FileRenamerPackage/Package.appxmanifest
@@ -12,7 +12,7 @@
+ Version="1.2.1002.0" />
ms-resource:PackageDisplayName
diff --git a/FileRenamerShellExtension/BaseExplorerCommand.cpp b/FileRenamerShellExtension/BaseExplorerCommand.cpp
index e9ff630..b1d0a10 100644
--- a/FileRenamerShellExtension/BaseExplorerCommand.cpp
+++ b/FileRenamerShellExtension/BaseExplorerCommand.cpp
@@ -191,7 +191,9 @@ namespace winrt::FileRenamerShellExtension::implementation
IFACEMETHODIMP FileNameCommand::Invoke(_In_opt_ IShellItemArray* selection, _In_opt_ IBindCtx*)
{
- winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe FileName";
+ WriteToFile(selection);
+
+ winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe FileName ShellContextMenu";
OpenApplication(exePath);
CloseProcess();
@@ -229,7 +231,9 @@ namespace winrt::FileRenamerShellExtension::implementation
IFACEMETHODIMP ExtensionNameCommand::Invoke(_In_opt_ IShellItemArray* selection, _In_opt_ IBindCtx*)
{
- winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe ExtensionName";
+ WriteToFile(selection);
+
+ winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe ExtensionName ShellContextMenu";
OpenApplication(exePath);
CloseProcess();
@@ -267,9 +271,11 @@ namespace winrt::FileRenamerShellExtension::implementation
IFACEMETHODIMP UpperAndLowerCaseCommand::Invoke(_In_opt_ IShellItemArray* selection, _In_opt_ IBindCtx*)
{
- winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe UpperAndLowerCase";
+ WriteToFile(selection);
+
+ winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe UpperAndLowerCase ShellContextMenu";
OpenApplication(exePath);
-
+
CloseProcess();
return S_OK;
}
@@ -305,7 +311,9 @@ namespace winrt::FileRenamerShellExtension::implementation
IFACEMETHODIMP FilePropertiesCommand::Invoke(_In_opt_ IShellItemArray* selection, _In_opt_ IBindCtx*)
{
- winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe FileProperties";
+ WriteToFile(selection);
+
+ winrt::hstring exePath = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\FileRenamer.exe FileProperties ShellContextMenu";
OpenApplication(exePath);
CloseProcess();
@@ -365,7 +373,50 @@ winrt::Windows::Foundation::IInspectable ReadSettings(winrt::hstring key)
return winrt::Windows::Storage::ApplicationData::Current().LocalSettings().Values().Lookup(key);
}
+///
+/// 写入文件
+///
+void WriteToFile(_In_opt_ IShellItemArray* pShellItemArray)
+{
+ wchar_t tempPath[MAX_PATH];
+ DWORD tempPathResult = GetTempPath(MAX_PATH, tempPath);
+ if (tempPathResult != 0)
+ {
+ wchar_t tempFileName[MAX_PATH];
+ wcscpy_s(tempFileName, tempPath);
+ wcscat_s(tempFileName, L"FileRenamer.txt");
+ HANDLE hFile = CreateFile(tempFileName, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hFile != INVALID_HANDLE_VALUE)
+ {
+ if (pShellItemArray != nullptr)
+ {
+ DWORD count = 0;
+ pShellItemArray->GetCount(&count);
+
+ for (DWORD index = 0; index < count; index++)
+ {
+ IShellItem* pShellItem;
+ pShellItemArray->GetItemAt(index, &pShellItem);
+
+ LPWSTR itemPath;
+ pShellItem->GetDisplayName(SIGDN_FILESYSPATH, &itemPath);
+ int byteLength = WideCharToMultiByte(CP_UTF8, 0, itemPath, -1, nullptr, 0, nullptr, nullptr);
+ char* buffer = new char[byteLength];
+ WideCharToMultiByte(CP_UTF8, 0, itemPath, -1, buffer, byteLength, nullptr, nullptr);
+
+ DWORD bytesWritten;
+ WriteFile(hFile, buffer, byteLength, &bytesWritten, nullptr);
+ WriteFile(hFile, L"\n", (DWORD)strlen("\n"), &bytesWritten, nullptr);
+
+ delete[] buffer;
+ }
+ }
+
+ CloseHandle(hFile);
+ }
+ }
+}
///
/// 打开应用
diff --git a/FileRenamerShellExtension/BaseExplorerCommand.h b/FileRenamerShellExtension/BaseExplorerCommand.h
index 7ac66d0..f8728fc 100644
--- a/FileRenamerShellExtension/BaseExplorerCommand.h
+++ b/FileRenamerShellExtension/BaseExplorerCommand.h
@@ -15,6 +15,7 @@
void InitializeResource();
winrt::hstring GetLocalized(winrt::hstring resource);
winrt::Windows::Foundation::IInspectable ReadSettings(winrt::hstring key);
+void WriteToFile(_In_opt_ IShellItemArray* pShellItemArray);
void OpenApplication(winrt::hstring exePath);
void CloseProcess();
diff --git a/FileRenamerShellExtension/Resource.rc b/FileRenamerShellExtension/Resource.rc
index 2331584..a3a6293 100644
Binary files a/FileRenamerShellExtension/Resource.rc and b/FileRenamerShellExtension/Resource.rc differ
diff --git a/FileRenamerShellExtension/resource.h b/FileRenamerShellExtension/resource.h
index 1d3ef00..488ce02 100644
--- a/FileRenamerShellExtension/resource.h
+++ b/FileRenamerShellExtension/resource.h
@@ -3,7 +3,7 @@
// Used by Resource.rc
// 新对象的下一组默认值
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101