From 309aa7ea18357e84b31ffb23129620e80ab82277 Mon Sep 17 00:00:00 2001 From: ema Date: Tue, 7 Jan 2025 14:04:34 +0800 Subject: [PATCH] fix: new FileInfo may throw exception --- README.md | 2 -- build/MicaSetup.Tools/MakeIcon.Shared/ImageHelper.cs | 2 +- build/MicaSetup/Helper/Setup/PrepareUninstallPathHelper.cs | 2 +- build/MicaSetup/Helper/System/SpecialPathHelper.cs | 4 ++-- build/MicaSetup/Helper/System/StartMenuHelper.cs | 6 +++--- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e1cb003..8a0f11d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -**应募一个MicaSetup程序图标 | Request a contribution of a MicaSetup program icon | プログラムのアイコンはただ今応募受付中** - ![logo64](./branding/logo64.png) [![Actions](https://github.com/lemutec/MicaSetup/actions/workflows/micasetup.yml/badge.svg)](https://github.com/lemutec/MicaSetup/actions/workflows/micasetup.yml) [![Platform](https://img.shields.io/badge/platform-Windows-blue?logo=windowsxp&color=1E9BFA)](https://dotnet.microsoft.com/zh-cn/download/dotnet/latest/runtime) diff --git a/build/MicaSetup.Tools/MakeIcon.Shared/ImageHelper.cs b/build/MicaSetup.Tools/MakeIcon.Shared/ImageHelper.cs index a71e973..4a6385e 100644 --- a/build/MicaSetup.Tools/MakeIcon.Shared/ImageHelper.cs +++ b/build/MicaSetup.Tools/MakeIcon.Shared/ImageHelper.cs @@ -45,7 +45,7 @@ public static void SaveImage(IconType type, FontFamily fontFamily, string filena IconType.Uninst => nameof(IconType.Uninst), _ => string.Empty, }}"; - string output = Path.Combine(new FileInfo(filename).DirectoryName, $"{pathNoExt}{ext}"); + string output = Path.Combine(Path.GetDirectoryName(filename), $"{pathNoExt}{ext}"); try { diff --git a/build/MicaSetup/Helper/Setup/PrepareUninstallPathHelper.cs b/build/MicaSetup/Helper/Setup/PrepareUninstallPathHelper.cs index b9430ea..e3620b1 100644 --- a/build/MicaSetup/Helper/Setup/PrepareUninstallPathHelper.cs +++ b/build/MicaSetup/Helper/Setup/PrepareUninstallPathHelper.cs @@ -41,7 +41,7 @@ public static UninstallDataInfo GetPrepareUninstallPath() domainFilePath = CommandLineHelper.Values[TempPathForkHelper.ForkedCli]; } - string installLocation = new FileInfo(domainFilePath).DirectoryName; + string installLocation = Path.GetDirectoryName(domainFilePath); string uninstallDataPath = Path.Combine(installLocation, "Uninst.dat"); string uninstallData = "Uninst.dat"; diff --git a/build/MicaSetup/Helper/System/SpecialPathHelper.cs b/build/MicaSetup/Helper/System/SpecialPathHelper.cs index 51e6b3a..c3e32dd 100644 --- a/build/MicaSetup/Helper/System/SpecialPathHelper.cs +++ b/build/MicaSetup/Helper/System/SpecialPathHelper.cs @@ -25,9 +25,9 @@ public static string GetPath(string baseName) { string configPath = Path.Combine(GetFolder(), baseName); - if (!Directory.Exists(new FileInfo(configPath).DirectoryName)) + if (!Directory.Exists(Path.GetDirectoryName(configPath))) { - _ = Directory.CreateDirectory(new FileInfo(configPath).DirectoryName!); + _ = Directory.CreateDirectory(Path.GetDirectoryName(configPath)); } return configPath; } diff --git a/build/MicaSetup/Helper/System/StartMenuHelper.cs b/build/MicaSetup/Helper/System/StartMenuHelper.cs index 816c9cc..d57afcc 100644 --- a/build/MicaSetup/Helper/System/StartMenuHelper.cs +++ b/build/MicaSetup/Helper/System/StartMenuHelper.cs @@ -34,7 +34,7 @@ public static void CreateStartMenuFolder(string folderName, string targetPath, b if (isCreateUninst) { - string uninstTargetPath = Path.Combine($"{new FileInfo(targetPath).Directory.FullName}", "Uninst.exe"); + string uninstTargetPath = Path.Combine($"{Path.GetDirectoryName(targetPath)}", "Uninst.exe"); ShortcutHelper.CreateShortcut(startMenuFolderPath, $"Uninstall_{folderName}", uninstTargetPath); } } @@ -63,8 +63,8 @@ public static bool PinToStartMenu(string filePath) { Type shellType = Type.GetTypeFromProgID("Shell.Application"); object shellObject = Activator.CreateInstance(shellType); - dynamic folder = shellType.InvokeMember("Namespace", BindingFlags.InvokeMethod, null, shellObject, [new FileInfo(filePath).DirectoryName]); - dynamic item = folder.ParseName(new FileInfo(filePath).Name); + dynamic folder = shellType.InvokeMember("Namespace", BindingFlags.InvokeMethod, null, shellObject, [Path.GetDirectoryName(filePath)]); + dynamic item = folder.ParseName(Path.GetFileName(filePath)); dynamic verbs = item.Verbs(); foreach (dynamic verb in verbs)