Add error handling for directory operation

This commit is contained in:
Jack251970 2025-06-06 13:25:43 +08:00
parent 57470a9799
commit f59e2399b9

View file

@ -294,16 +294,22 @@ public class FirefoxBookmarkLoader : FirefoxBookmarkLoaderBase
{ {
var platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var packagesPath = Path.Combine(platformPath, "Packages"); var packagesPath = Path.Combine(platformPath, "Packages");
try
{
// Search for folder with Mozilla.Firefox prefix
var firefoxPackageFolder = Directory.EnumerateDirectories(packagesPath, "Mozilla.Firefox*",
SearchOption.TopDirectoryOnly).FirstOrDefault();
// Search for folder with Mozilla.Firefox prefix // Msix FireFox not installed
var firefoxPackageFolder = Directory.EnumerateDirectories(packagesPath, "Mozilla.Firefox*", if (firefoxPackageFolder == null) return string.Empty;
SearchOption.TopDirectoryOnly).FirstOrDefault();
// Msix FireFox not installed var profileFolderPath = Path.Combine(firefoxPackageFolder, @"LocalCache\Roaming\Mozilla\Firefox");
if (firefoxPackageFolder == null) return string.Empty; return GetProfileIniPath(profileFolderPath);
}
var profileFolderPath = Path.Combine(firefoxPackageFolder, @"LocalCache\Roaming\Mozilla\Firefox"); catch
return GetProfileIniPath(profileFolderPath); {
return string.Empty;
}
} }
} }