Remove relative path conversion for plugin settings files

Removed logic that converted absolute paths to relative paths within the ProgramDirectory. Now, plugin settings file paths are always stored as absolute paths. Deleted the ConvertToRelativePathIfPossible method and updated usages accordingly.
This commit is contained in:
Jack251970 2026-01-24 16:07:04 +08:00
parent d49e5b4c1f
commit 9fa4c37109
2 changed files with 2 additions and 45 deletions

View file

@ -73,8 +73,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
if (!string.IsNullOrEmpty(selectedFile))
{
// Convert to relative path if within ProgramDirectory for portability
PluginsSettingsFilePath = DataLocation.ConvertToRelativePathIfPossible(selectedFile);
PluginsSettingsFilePath = selectedFile;
}
// Nothing selected because user pressed cancel from the file dialog window
else
@ -98,8 +97,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
if (!string.IsNullOrEmpty(selectedFile))
{
// Convert to relative path if within ProgramDirectory for portability
PluginsSettingsFilePath = DataLocation.ConvertToRelativePathIfPossible(selectedFile);
PluginsSettingsFilePath = selectedFile;
}
else
{

View file

@ -62,46 +62,5 @@ namespace Flow.Launcher.Infrastructure.UserSettings
// Resolve relative to ProgramDirectory
return Path.GetFullPath(Path.Combine(Constant.ProgramDirectory, path));
}
/// <summary>
/// Converts an absolute path to a relative path if it's within ProgramDirectory.
/// This enables portability by storing paths relative to the program directory when possible.
/// </summary>
/// <param name="absolutePath">The absolute path to convert</param>
/// <returns>A relative path if the path is within ProgramDirectory, otherwise the original absolute path</returns>
public static string ConvertToRelativePathIfPossible(string absolutePath)
{
if (string.IsNullOrEmpty(absolutePath))
return absolutePath;
if (!Path.IsPathRooted(absolutePath))
return absolutePath;
try
{
// Get the full absolute paths for comparison
var fullAbsolutePath = Path.GetFullPath(absolutePath);
var fullProgramDir = Path.GetFullPath(Constant.ProgramDirectory);
// Check if the absolute path is within ProgramDirectory
if (fullAbsolutePath.StartsWith(fullProgramDir, StringComparison.OrdinalIgnoreCase))
{
// Convert to relative path
var relativePath = Path.GetRelativePath(fullProgramDir, fullAbsolutePath);
// Prefix with .\ for clarity
if (!relativePath.StartsWith('.'))
relativePath = ".\\" + relativePath;
return relativePath;
}
}
catch
{
// If conversion fails, return the original path
}
return absolutePath;
}
}
}