Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Log2Console/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public MainForm()
_loggersPanelFloaty.Docking += OnFloatyDocking;

// Settings
_firstStartup = !UserSettings.Load();
bool portableMode = Environment.GetCommandLineArgs().Contains("--portable");
_firstStartup = !UserSettings.Load(portableMode);
if (_firstStartup)
{
// Initialize default layout
Expand Down
34 changes: 24 additions & 10 deletions src/Log2Console/Settings/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using Log2Console.Log;
using Log2Console.Receiver;

using System.Reflection;

namespace Log2Console.Settings
{
Expand Down Expand Up @@ -67,6 +67,9 @@ public sealed class UserSettings
[NonSerialized]
private Dictionary<string, string> _sourceCodeLocationMap;

[NonSerialized]
private bool _portableMode;

private static UserSettings _instance;

private bool _recursivlyEnableLoggers = true;
Expand Down Expand Up @@ -145,13 +148,14 @@ public static UserSettings Instance
set { _instance = value; }
}

public static bool Load()
public static bool Load(bool portableMode)
{
bool ok = false;

_instance = new UserSettings();
_instance._portableMode = portableMode;

string settingsFilePath = GetSettingsFilePath();
string settingsFilePath = GetSettingsFilePath(portableMode);
if (!File.Exists(settingsFilePath))
return ok;

Expand Down Expand Up @@ -190,23 +194,33 @@ public static bool Load()
ok = false;
}
}
_instance._portableMode = portableMode;

return ok;
}

private static string GetSettingsFilePath()
private static string GetSettingsFilePath(bool portableMode)
{
string userDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

DirectoryInfo di = new DirectoryInfo(userDir);
di = di.CreateSubdirectory("Log2Console");
if (portableMode)
{
string startupPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

return di.FullName + Path.DirectorySeparatorChar + SettingsFileName;
return Path.Combine(startupPath, SettingsFileName);
}
else
{
string userDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

DirectoryInfo di = new DirectoryInfo(userDir);
di = di.CreateSubdirectory("Log2Console");

return Path.Combine(di.FullName, SettingsFileName);
}
}

public void Save()
{
string settingsFilePath = GetSettingsFilePath();
string settingsFilePath = GetSettingsFilePath(this._portableMode);

using (FileStream fs = new FileStream(settingsFilePath, FileMode.Create))
{
Expand Down