Skip to content

Commit

Permalink
Manager: Allow selecting multiple log directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Mar 27, 2022
1 parent 7ed95c4 commit 114d215
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 40 deletions.
1 change: 1 addition & 0 deletions ArcdpsLogManager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This is the full changelog of the arcdps Log Manager.

#### New features
- Added support for all 4 End of Dragons strike missions.
- Added an option to have multiple log directories
- Mistlock Instabilities are now detected for Fractal logs and shown in the details pane.
- Added a new column for Mistlock Instabilities to the log list (right-click the column header to enable).
- Added filters for Mistlock Instabilities to *Advanced Filters*.
Expand Down
55 changes: 15 additions & 40 deletions ArcdpsLogManager/Configuration/LogsSettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,22 @@
using System.Linq;
using Eto.Drawing;
using Eto.Forms;
using GW2Scratch.ArcdpsLogManager.Controls;

namespace GW2Scratch.ArcdpsLogManager.Configuration
{
public class LogsSettingsPage : SettingsPage
{
private static readonly string[] DefaultLogLocation = {"Guild Wars 2", "addons", "arcdps", "arcdps.cbtlogs"};

private readonly TextBox locationTextBox;
private readonly DirectoryListControl directoryList;
private readonly CheckBox minDurationCheckBox;
private readonly NumericMaskedTextBox<int> minDurationTextBox;

public LogsSettingsPage()
{
Text = "Logs";

var dialog = new SelectFolderDialog();

locationTextBox = new TextBox
{
ReadOnly = true,
PlaceholderText = "Log Location",
};

var locationDialogButton = new Button {Text = "Select Log Directory"};
locationDialogButton.Click += (sender, args) =>
{
if (dialog.ShowDialog(this) == DialogResult.Ok)
{
locationTextBox.Text = dialog.Directory;
}
};

minDurationCheckBox = new CheckBox
{
Text = "Exclude short logs",
Expand All @@ -52,6 +36,8 @@ public LogsSettingsPage()
minDurationCheckBox.CheckedChanged += (sender, args) =>
minDurationTextBox.Enabled = minDurationCheckBox.Checked ?? false;

directoryList = new DirectoryListControl();

var durationLabel = new Label
{
Text = "Minimum duration in seconds:", VerticalAlignment = VerticalAlignment.Center
Expand All @@ -60,18 +46,17 @@ public LogsSettingsPage()
var layout = new DynamicLayout();
layout.BeginVertical(spacing: new Size(5, 5), padding: new Padding(10));
{
layout.BeginGroup("Log directory", new Padding(5), new Size(5, 5));
layout.BeginGroup("Log directories", new Padding(5), new Size(5, 5));
{
layout.AddRow(new Label
{
Text = "The directory in which your arcdps logs are stored. Subdirectories " +
Text = "The directories in which your arcdps logs are stored. Subdirectories " +
"are also searched, do not choose a parent directory containing more " +
"irrelevant files unless you like extra waiting.",
Wrap = WrapMode.Word,
Height = 70
});
layout.AddRow(locationTextBox);
layout.AddRow(locationDialogButton);
layout.AddRow(directoryList);
}
layout.EndGroup();
layout.BeginGroup("Log filters", new Padding(5), new Size(5, 5));
Expand All @@ -87,37 +72,27 @@ public LogsSettingsPage()

if (Settings.LogRootPaths.Any())
{
if (Settings.LogRootPaths.Count > 1)
{
// There is currently no interface for adding more than one log directory, so this would end up
// losing some quietly when that is implemented.
throw new NotImplementedException();
}

string logRootPath = Settings.LogRootPaths.Single();
if (Directory.Exists(logRootPath))
{
dialog.Directory = logRootPath;
}

locationTextBox.Text = logRootPath;
directoryList.Directories = Settings.LogRootPaths;
}
else
{
string defaultDirectory = GetDefaultLogDirectory();
if (Directory.Exists(defaultDirectory))
{
dialog.Directory = defaultDirectory;
locationTextBox.Text = defaultDirectory;
directoryList.Directories = new[] { defaultDirectory };
}
else
{
directoryList.Directories = Enumerable.Empty<string>();
}
}
}

public override void SaveSettings()
{
if (locationTextBox.Text.Trim() != Settings.LogRootPaths.FirstOrDefault())
if (!directoryList.Directories.Select(x => x.Trim()).SequenceEqual(Settings.LogRootPaths))
{
Settings.LogRootPaths = new[] {locationTextBox.Text};
Settings.LogRootPaths = directoryList.Directories.Select(x => x.Trim()).ToList();
}

bool minDurationChecked = minDurationCheckBox.Checked ?? false;
Expand Down
77 changes: 77 additions & 0 deletions ArcdpsLogManager/Controls/DirectoryListControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Eto.Drawing;
using Eto.Forms;
using System;
using System.Collections.Generic;
using System.Linq;

namespace GW2Scratch.ArcdpsLogManager.Controls;

public class DirectoryListControl : DynamicLayout
{
private List<string> directories;

public IEnumerable<string> Directories
{
get => directories;
set
{
directories = value?.ToList() ?? new List<string>();
RecreateLayout();
}
}

private void RecreateLayout()
{
if (directories == null)
{
SuspendLayout();
Clear();
ResumeLayout();
return;
}

SuspendLayout();
Clear();

BeginVertical(spacing: new Size(5, 5));
{
foreach ((int i, string directory) in directories.Select((x, i) => (i, x)))
{
BeginHorizontal();
Add(new TextBox { Text = directory, ReadOnly = true }, true);
var removeButton = new Button { Text = "Remove" };
removeButton.Click += (_, _) =>
{
directories.RemoveAt(i);
// This will trigger the setter which rebuilds the layout.
Directories = directories;
};
Add(removeButton, false);
EndHorizontal();
}

AddRow(ConstructAddButton());
}
EndVertical();

Create();
ResumeLayout();
}

private Button ConstructAddButton()
{
var button = new Button { Text = "Add a log directory" };
button.Click += (_, _) =>
{
var dialog = new SelectFolderDialog();
if (dialog.ShowDialog(this) == DialogResult.Ok)
{
if (!Directories.Contains(dialog.Directory))
{
Directories = Directories.Append(dialog.Directory);
}
}
};
return button;
}
}

0 comments on commit 114d215

Please sign in to comment.