Skip to content

Commit 8b6f9f4

Browse files
committed
Move function to FilesFolders
1 parent c9c306f commit 8b6f9f4

3 files changed

Lines changed: 32 additions & 30 deletions

File tree

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal AbstractPluginEnvironment(List<PluginMetadata> pluginMetadataList, Plug
4444
/// Resolves the configured runtime executable path to an absolute path.
4545
/// Supports both absolute paths and relative paths (relative to ProgramDirectory).
4646
/// </summary>
47-
private string ResolvedPluginsSettingsFilePath => DataLocation.ResolveAbsolutePath(PluginsSettingsFilePath);
47+
private string ResolvedPluginsSettingsFilePath => FilesFolders.ResolveAbsolutePath(PluginsSettingsFilePath);
4848

4949
internal IEnumerable<PluginPair> Setup()
5050
{

Flow.Launcher.Infrastructure/UserSettings/DataLocation.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,5 @@ public static bool PortableDataLocationInUse()
4242
public const string PluginEnvironments = "Environments";
4343
public const string PluginDeleteFile = "NeedDelete.txt";
4444
public static readonly string PluginEnvironmentsPath = Path.Combine(DataDirectory(), PluginEnvironments);
45-
46-
/// <summary>
47-
/// Resolves a path that may be relative to an absolute path.
48-
/// If the path is already absolute, returns it as-is.
49-
/// If the path is not rooted (as determined by <see cref="Path.IsPathRooted(string)"/>), resolves it relative to ProgramDirectory.
50-
/// </summary>
51-
/// <param name="path">The path to resolve</param>
52-
/// <returns>An absolute path</returns>
53-
public static string ResolveAbsolutePath(string path)
54-
{
55-
if (string.IsNullOrEmpty(path))
56-
return path;
57-
58-
// If already absolute, return as-is
59-
if (Path.IsPathFullyQualified(path))
60-
return path;
61-
62-
// Resolve relative to ProgramDirectory, handling invalid path formats gracefully
63-
try
64-
{
65-
return Path.GetFullPath(Path.Combine(Constant.ProgramDirectory, path));
66-
}
67-
catch (System.Exception)
68-
{
69-
// If the path cannot be resolved (invalid characters, format, or too long),
70-
// return the original path to avoid crashing the application.
71-
return path;
72-
}
73-
}
7445
}
7546
}

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Linq;
5+
using System.Reflection;
6+
57
#pragma warning disable IDE0005
68
using System.Windows;
79
#pragma warning restore IDE0005
@@ -487,5 +489,34 @@ public static void ValidateDataDirectory(string bundledDataDirectory, string dat
487489
}
488490
}
489491
}
492+
493+
/// <summary>
494+
/// Resolves a path that may be relative to an absolute path.
495+
/// If the path is already absolute, returns it as-is.
496+
/// If the path is not rooted (as determined by <see cref="Path.IsPathRooted(string)"/>), resolves it relative to ProgramDirectory.
497+
/// </summary>
498+
/// <param name="path">The path to resolve</param>
499+
/// <returns>An absolute path</returns>
500+
public static string ResolveAbsolutePath(string path)
501+
{
502+
if (string.IsNullOrEmpty(path))
503+
return path;
504+
505+
// If already absolute, return as-is
506+
if (Path.IsPathFullyQualified(path))
507+
return path;
508+
509+
// Resolve relative to ProgramDirectory, handling invalid path formats gracefully
510+
try
511+
{
512+
return Path.GetFullPath(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString(), path));
513+
}
514+
catch (Exception)
515+
{
516+
// If the path cannot be resolved (invalid characters, format, or too long),
517+
// return the original path to avoid crashing the application.
518+
return path;
519+
}
520+
}
490521
}
491522
}

0 commit comments

Comments
 (0)