Skip to content

Commit

Permalink
fix: bug where directory won't be created if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-george-field committed Jan 22, 2023
1 parent e63cb29 commit 9298a44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/wfh-log-wpf/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using wfh_log_wpf.Logger;
using wfh_log_wpf.Models;
using wfh_log_wpf.Settings;
using wfh_log_wpf.Timer;
using wfh_log_wpf.Uninstaller;

namespace wfh_log_wpf
{
Expand Down Expand Up @@ -114,7 +109,7 @@ private void ShowMainWindow()

private void OpenLogFile()
{
var absoluteFilePath = BaseLog.GetLogPath();
var absoluteFilePath = BaseLog.GetLogFilePath();

var processStartInfo = new ProcessStartInfo
{
Expand Down
16 changes: 12 additions & 4 deletions src/wfh-log-wpf/Logger/BaseLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ public abstract class BaseLog

public BaseLog()
{
AbsoluteFilePath = GetLogPath();
AbsoluteFilePath = GetLogFilePath();

Directory.CreateDirectory(GetLogDirectoryPath());
}

public static string GetLogPath()
public static string GetLogFilePath()
{
var filename = "wfh.log";

return Path.Combine(GetLogDirectoryPath(), filename);
}

public static string GetLogDirectoryPath()
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var directory = "wfh-log";
var filename = "wfh.log";

return Path.Combine(appDataPath, directory, filename);
return Path.Combine(appDataPath, directory);
}
}
}

0 comments on commit 9298a44

Please sign in to comment.