Skip to content

Commit

Permalink
Warning messages for misconfigured log files
Browse files Browse the repository at this point in the history
  • Loading branch information
davghouse committed Jun 25, 2017
1 parent e38d8a4 commit a5a0359
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions AODamageMeter.UI/AODamageMeter.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Generator>MSBuild:Compile</Generator>
</Compile>
<Compile Include="Helpers\DamageMeterExtensions.cs" />
<Compile Include="Helpers\FileHelper.cs" />
<Compile Include="Helpers\SharedTooltips.cs" />
<Compile Include="RowViewModelDataGrid.cs" />
<Compile Include="ViewingMode.cs" />
Expand Down
10 changes: 10 additions & 0 deletions AODamageMeter.UI/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.IO;

namespace AODamageMeter.UI.Helpers
{
public static class FileHelper
{
public static void CreateEmptyFile(string filePath)
=> File.Create(filePath).Dispose();
}
}
7 changes: 4 additions & 3 deletions AODamageMeter.UI/ViewModels/CharacterInfoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AODamageMeter.FightEvents.Attack;
using AODamageMeter.FightEvents.Heal;
using AODamageMeter.UI.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -167,7 +168,7 @@ private void ExecuteAutoConfigureCommand()
LogFilePath = $@"{path}\Log.txt";
if (!File.Exists(LogFilePath))
{
File.Create(LogFilePath);
FileHelper.CreateEmptyFile(LogFilePath);
RefreshLogFileSize();
}
AutoConfigureResult = "Auto-configure succeeded. An existing log file was found.";
Expand All @@ -180,7 +181,7 @@ private void ExecuteAutoConfigureCommand()
LogFilePath = $@"{path}\Log.txt";
if (!File.Exists(LogFilePath))
{
File.Create(LogFilePath);
FileHelper.CreateEmptyFile(LogFilePath);
RefreshLogFileSize();
}
AutoConfigureResult = "Auto-configure succeeded. An existing log file was found and reconfigured.";
Expand All @@ -197,7 +198,7 @@ private void ExecuteAutoConfigureCommand()
Directory.CreateDirectory($@"{chatWindowsPath}\{newWindowName}");
File.WriteAllText($@"{chatWindowsPath}\{newWindowName}\Config.xml", GetAutoConfigureConfigXml(newWindowName));
LogFilePath = $@"{chatWindowsPath}\{newWindowName}\Log.txt";
File.Create(LogFilePath);
FileHelper.CreateEmptyFile(LogFilePath);
RefreshLogFileSize();
bool isAlreadyLoggedIn = Process.GetProcessesByName("AnarchyOnline")
.Any(p => p.MainWindowTitle?.Contains(CharacterName) ?? false);
Expand Down
3 changes: 2 additions & 1 deletion AODamageMeter.UI/ViewModels/DamageMeterViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AODamageMeter.UI.Helpers;
using AODamageMeter.UI.Properties;
using AODamageMeter.UI.ViewModels.Rows;
using System;
Expand Down Expand Up @@ -85,7 +86,7 @@ public bool TryInitializeDamageMeter(string characterName, string logFilePath)

if (!File.Exists(logFilePath))
{
try { File.Create(logFilePath); }
try { FileHelper.CreateEmptyFile(logFilePath); }
catch { return false; }
}

Expand Down
30 changes: 27 additions & 3 deletions AODamageMeter.UI/Views/DamageMeterView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AODamageMeter.UI.Properties;
using AODamageMeter.UI.Helpers;
using AODamageMeter.UI.Properties;
using AODamageMeter.UI.ViewModels;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Input;

Expand Down Expand Up @@ -32,8 +34,30 @@ private void ShowCharacterSelection()
var characterSelectionView = new CharacterSelectionView(_damageMeterViewModel) { Owner = this };
if (characterSelectionView.ShowDialog() == true)
{
_damageMeterViewModel.TryInitializeDamageMeter(
Settings.Default.SelectedCharacterName, Settings.Default.SelectedLogFilePath);
if (string.IsNullOrWhiteSpace(Settings.Default.SelectedCharacterName))
return; // In this case we said 'No character selected' above the OK button, so I guess they know.

if (string.IsNullOrWhiteSpace(Settings.Default.SelectedLogFilePath))
{
MessageBox.Show(
$"No log file for {Settings.Default.SelectedCharacterName} has been specified.",
"Log file not specified",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
else if (!File.Exists(Settings.Default.SelectedLogFilePath))
{
MessageBox.Show(
$"Log file for {Settings.Default.SelectedCharacterName} at {Settings.Default.SelectedLogFilePath} can't be found.",
"Log file not found",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
else
{
_damageMeterViewModel.TryInitializeDamageMeter(
Settings.Default.SelectedCharacterName, Settings.Default.SelectedLogFilePath);
}
}
}

Expand Down

0 comments on commit a5a0359

Please sign in to comment.