Skip to content

Commit

Permalink
Determine base directory in a more reliable manner
Browse files Browse the repository at this point in the history
  • Loading branch information
geluk committed Oct 17, 2022
1 parent d391553 commit c3924fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pass-winmenu-tests/Configuration/RuntimeConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace PassWinmenuTests.Configuration
public class RuntimeConfigurationTests
{
[Fact]
public void Parse_NoArgs_ConfigFileLocationIsNull()
public void Parse_NoArgs_SetsDefaultLocation()
{
var config = RuntimeConfiguration.Parse(new[] { "app.exe" });

config.ConfigFileLocation.ShouldBeNull();
config.ConfigFileLocation.ShouldEndWith("pass-winmenu.yaml");
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions pass-winmenu/src/Configuration/RuntimeConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.IO;
using System.Reflection;

#nullable enable
namespace PassWinmenu.Configuration
Expand All @@ -14,8 +14,8 @@ private RuntimeConfiguration()

internal static RuntimeConfiguration Parse(string[] args)
{
var executableDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location);
var defaultConfigPath = Path.Combine(executableDirectory!, "pass-winmenu.yaml");
var executableDirectory = AppDomain.CurrentDomain.BaseDirectory;
var defaultConfigPath = Path.Combine(executableDirectory, "pass-winmenu.yaml");

var configuration = new RuntimeConfiguration
{
Expand Down
4 changes: 2 additions & 2 deletions pass-winmenu/src/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private void LoadConfigFile(RuntimeConfiguration runtimeConfig)
"Would you like to open it now?", "New configuration file created", MessageBoxButton.YesNo);
if (open == MessageBoxResult.Yes)
{
Process.Start(runtimeConfig.ConfigFileLocation);
Process.Start("explorer", runtimeConfig.ConfigFileLocation);
}

App.Exit();
Expand All @@ -262,7 +262,7 @@ private void LoadConfigFile(RuntimeConfiguration runtimeConfig)
"Would you like to open both files now?", "Configuration file out of date", MessageBoxButton.YesNo);
if (openBoth == MessageBoxResult.Yes)
{
Process.Start(runtimeConfig.ConfigFileLocation);
Process.Start("explorer", runtimeConfig.ConfigFileLocation);
Process.Start(backedUpFile);
}
App.Exit();
Expand Down
7 changes: 6 additions & 1 deletion pass-winmenu/src/ExternalPrograms/Gpg/GpgHomeDirResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public GpgHomeDirectory GetHomeDir()
/// </summary>
private string GetDefaultHomeDir()
{
var psi = new ProcessStartInfo(installation.GpgConfExecutable.FullName, "--list-dirs");
var psi = new ProcessStartInfo(installation.GpgConfExecutable.FullName, "--list-dirs")
{
RedirectStandardOutput = true,
UseShellExecute = false,
};

var gpgConf = processes.Start(psi);

var lines = gpgConf.StandardOutput.ReadAllLines();
Expand Down

0 comments on commit c3924fa

Please sign in to comment.