Skip to content

Commit a5a0359

Browse files
committed
Warning messages for misconfigured log files
1 parent e38d8a4 commit a5a0359

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

AODamageMeter.UI/AODamageMeter.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Generator>MSBuild:Compile</Generator>
9898
</Compile>
9999
<Compile Include="Helpers\DamageMeterExtensions.cs" />
100+
<Compile Include="Helpers\FileHelper.cs" />
100101
<Compile Include="Helpers\SharedTooltips.cs" />
101102
<Compile Include="RowViewModelDataGrid.cs" />
102103
<Compile Include="ViewingMode.cs" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.IO;
2+
3+
namespace AODamageMeter.UI.Helpers
4+
{
5+
public static class FileHelper
6+
{
7+
public static void CreateEmptyFile(string filePath)
8+
=> File.Create(filePath).Dispose();
9+
}
10+
}

AODamageMeter.UI/ViewModels/CharacterInfoViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using AODamageMeter.FightEvents.Attack;
22
using AODamageMeter.FightEvents.Heal;
3+
using AODamageMeter.UI.Helpers;
34
using System;
45
using System.Collections.Generic;
56
using System.Diagnostics;
@@ -167,7 +168,7 @@ private void ExecuteAutoConfigureCommand()
167168
LogFilePath = $@"{path}\Log.txt";
168169
if (!File.Exists(LogFilePath))
169170
{
170-
File.Create(LogFilePath);
171+
FileHelper.CreateEmptyFile(LogFilePath);
171172
RefreshLogFileSize();
172173
}
173174
AutoConfigureResult = "Auto-configure succeeded. An existing log file was found.";
@@ -180,7 +181,7 @@ private void ExecuteAutoConfigureCommand()
180181
LogFilePath = $@"{path}\Log.txt";
181182
if (!File.Exists(LogFilePath))
182183
{
183-
File.Create(LogFilePath);
184+
FileHelper.CreateEmptyFile(LogFilePath);
184185
RefreshLogFileSize();
185186
}
186187
AutoConfigureResult = "Auto-configure succeeded. An existing log file was found and reconfigured.";
@@ -197,7 +198,7 @@ private void ExecuteAutoConfigureCommand()
197198
Directory.CreateDirectory($@"{chatWindowsPath}\{newWindowName}");
198199
File.WriteAllText($@"{chatWindowsPath}\{newWindowName}\Config.xml", GetAutoConfigureConfigXml(newWindowName));
199200
LogFilePath = $@"{chatWindowsPath}\{newWindowName}\Log.txt";
200-
File.Create(LogFilePath);
201+
FileHelper.CreateEmptyFile(LogFilePath);
201202
RefreshLogFileSize();
202203
bool isAlreadyLoggedIn = Process.GetProcessesByName("AnarchyOnline")
203204
.Any(p => p.MainWindowTitle?.Contains(CharacterName) ?? false);

AODamageMeter.UI/ViewModels/DamageMeterViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using AODamageMeter.UI.Helpers;
12
using AODamageMeter.UI.Properties;
23
using AODamageMeter.UI.ViewModels.Rows;
34
using System;
@@ -85,7 +86,7 @@ public bool TryInitializeDamageMeter(string characterName, string logFilePath)
8586

8687
if (!File.Exists(logFilePath))
8788
{
88-
try { File.Create(logFilePath); }
89+
try { FileHelper.CreateEmptyFile(logFilePath); }
8990
catch { return false; }
9091
}
9192

AODamageMeter.UI/Views/DamageMeterView.xaml.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using AODamageMeter.UI.Properties;
1+
using AODamageMeter.UI.Helpers;
2+
using AODamageMeter.UI.Properties;
23
using AODamageMeter.UI.ViewModels;
34
using System.ComponentModel;
5+
using System.IO;
46
using System.Windows;
57
using System.Windows.Input;
68

@@ -32,8 +34,30 @@ private void ShowCharacterSelection()
3234
var characterSelectionView = new CharacterSelectionView(_damageMeterViewModel) { Owner = this };
3335
if (characterSelectionView.ShowDialog() == true)
3436
{
35-
_damageMeterViewModel.TryInitializeDamageMeter(
36-
Settings.Default.SelectedCharacterName, Settings.Default.SelectedLogFilePath);
37+
if (string.IsNullOrWhiteSpace(Settings.Default.SelectedCharacterName))
38+
return; // In this case we said 'No character selected' above the OK button, so I guess they know.
39+
40+
if (string.IsNullOrWhiteSpace(Settings.Default.SelectedLogFilePath))
41+
{
42+
MessageBox.Show(
43+
$"No log file for {Settings.Default.SelectedCharacterName} has been specified.",
44+
"Log file not specified",
45+
MessageBoxButton.OK,
46+
MessageBoxImage.Warning);
47+
}
48+
else if (!File.Exists(Settings.Default.SelectedLogFilePath))
49+
{
50+
MessageBox.Show(
51+
$"Log file for {Settings.Default.SelectedCharacterName} at {Settings.Default.SelectedLogFilePath} can't be found.",
52+
"Log file not found",
53+
MessageBoxButton.OK,
54+
MessageBoxImage.Warning);
55+
}
56+
else
57+
{
58+
_damageMeterViewModel.TryInitializeDamageMeter(
59+
Settings.Default.SelectedCharacterName, Settings.Default.SelectedLogFilePath);
60+
}
3761
}
3862
}
3963

0 commit comments

Comments
 (0)