Skip to content

Commit

Permalink
configured serilog
Browse files Browse the repository at this point in the history
  • Loading branch information
codejanovic committed Jun 16, 2024
1 parent fa5edbb commit fbcbc28
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 22 deletions.
23 changes: 15 additions & 8 deletions Smurftown/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Smurftown.UI.MVVM;
using Smurftown.UI.MVVM.ViewModel;
using System.Configuration;
using System.Data;
using System.IO;
using System.Windows;
using Serilog;

namespace Smurftown
{
Expand All @@ -12,7 +9,17 @@ namespace Smurftown
/// </summary>
public partial class App : Application
{

}
protected override void OnStartup(StartupEventArgs e)
{
if (!Directory.Exists(Directories.UserPath)) Directory.CreateDirectory(Directories.UserPath);

using var log = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(Path.Combine(Directories.UserPath, "smurftown.log"))
.CreateLogger();

}
log.Information("starting smurftown");
base.OnStartup(e);
}
}
}
11 changes: 5 additions & 6 deletions Smurftown/Backend/Gateway/BattlenetAccountGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ namespace Smurftown.Backend.Gateway
public class BattlenetAccountGateway
{
public static readonly BattlenetAccountGateway Instance = new();

private readonly string _configDirectory = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _configFileDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".smurftown");
private readonly string _configFile;

private readonly IDeserializer _yamlIn = new DeserializerBuilder()
Expand All @@ -26,7 +23,7 @@ public class BattlenetAccountGateway

private BattlenetAccountGateway()
{
_configFile = Path.Combine(_configFileDirectory, "data.yaml");
_configFile = Path.Combine(Directories.UserPath, "data.yaml");
foreach (var account in ReadFromConfigFile())
{
BattlenetAccounts.Add(account);
Expand Down Expand Up @@ -115,8 +112,10 @@ private void ensureConfigFileExists()
{
if (!File.Exists(_configFile))
{
Directory.CreateDirectory(_configFileDirectory);
using (File.Create(_configFile)) { }
Directory.CreateDirectory(Directories.UserPath);
using (File.Create(_configFile))
{
}
}
}

Expand Down
9 changes: 3 additions & 6 deletions Smurftown/Backend/Gateway/WindowsAccountGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.DirectoryServices.AccountManagement;
using System.IO;
using System.Management;
using Serilog;
using Smurftown.Backend.Entity;

namespace Smurftown.Backend.Gateway
Expand Down Expand Up @@ -81,7 +82,8 @@ public async Task OpenBattlenet(BattlenetAccount account)
var command = account.DedicatedWindowsUser
? $"{_psExecExecutable} -accepteula -u {windowsUser.Name} -p {windowsUser.Name} \"{programPath}\""
: $"\"{programPath}\"";
Console.WriteLine(command);
Log.Information($"{account.Battletag()}: starting battlenet");
Log.Information($"{account.Battletag()}: executing '{command}'");
var startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Expand All @@ -96,19 +98,14 @@ public async Task OpenBattlenet(BattlenetAccount account)
using (var process = new Process())
{
process.StartInfo = startInfo;
Console.WriteLine("Starting process");
process.Start();

Console.WriteLine("Waiting for 500 ms");
await Task.Delay(500);

// Kill the process if it's still running
Console.WriteLine("Checking if process is finished: " + process.HasExited);
if (!process.HasExited)
{
Console.WriteLine("Killing process..");
process.Kill();
Console.WriteLine("Killing process.. DONE!");
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Smurftown/Directories.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.IO;

namespace Smurftown;

public abstract class Directories
{
public static readonly string UserPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".smurftown");
}
5 changes: 5 additions & 0 deletions Smurftown/Smurftown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0-preview.5.24306.7"/>
<PackageReference Include="MvvmDialogs" Version="9.1.2" />
<PackageReference Include="Serilog" Version="4.0.0"/>
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.1-dev-10391"/>
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0"/>
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00972"/>
<PackageReference Include="System.DirectoryServices" Version="9.0.0-preview.4.24266.19" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="9.0.0-preview.4.24266.19" />
<PackageReference Include="System.Management" Version="8.0.0" />
Expand Down
1 change: 0 additions & 1 deletion SmurftownInstaller/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
</Applications>

<Capabilities>
<Capability Name="internetClient"/>
<rescap:Capability Name="runFullTrust"/>
<iot:Capability Name="systemManagement"/>
</Capabilities>
Expand Down
Binary file modified SmurftownInstaller/SmurftownInstaller.assets.cache
Binary file not shown.
6 changes: 5 additions & 1 deletion SmurftownInstaller/SmurftownInstaller.wapproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
Expand Down Expand Up @@ -173,7 +173,11 @@
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" PrivateAssets="all" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Smurftown\Smurftown.csproj" />
Expand Down

0 comments on commit fbcbc28

Please sign in to comment.