Skip to content

Commit

Permalink
Added config panel and auto-clean old logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
LittlePox committed Feb 22, 2020
1 parent b987d82 commit d953fa3
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 6 deletions.
1 change: 1 addition & 0 deletions OKEGui/OKEGui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private void AppStartup(object sender, StartupEventArgs e)
{
Initializer.ConfigLogger();
Initializer.WriteConfig();
Initializer.ClearOldLogs();
Logger.Info("程序正常启动");
}
else
Expand Down
73 changes: 73 additions & 0 deletions OKEGui/OKEGui/Gui/ConfigPanel.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<Window x:Class="OKEGui.ConfigPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OKEGui"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d"
Title="设置" Height="300" Width="500">
<Window.Resources>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="105"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Height="70" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="290"/>
<ColumnDefinition Width="95"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,9" Height="30" Grid.Row="0" Grid.Column="0" Text="vspipe.exe"/>
<TextBox Height="25" Grid.Row="0" Grid.Column="1" Text="{Binding Config.vspipePath}"/>
<Button Height="25" Width="40" Grid.Row="0" Grid.Column="2" Content="选择" Click="Vspipe_Click"/>
<TextBlock Margin="10,9" Height="30" Grid.Row="1" Grid.Column="0" Text="RPChecker.exe"/>
<TextBox Height="25" Grid.Row="1" Grid.Column="1" Text="{Binding Config.rpCheckerPath}"/>
<Button Height="25" Width="40" Grid.Row="1" Grid.Column="2" Content="选择" Click="RPChecker_Click"/>
</Grid>
<Grid Grid.Row="1" Height="105" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="95"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,9" Height="30" Grid.Row="0" Grid.Column="0" Text="记录详细程度(从上到下越来越详细)"/>
<ComboBox Height="25" Width="70" Grid.Row="0" HorizontalAlignment="Center" Grid.Column="1" SelectedValue="{Binding Config.logLevel}" SelectedValuePath="Content">
<ComboBoxItem Content="OFF"/>
<ComboBoxItem Content="FATAL"/>
<ComboBoxItem Content="ERROR"/>
<ComboBoxItem Content="WARN"/>
<ComboBoxItem Content="INFO"/>
<ComboBoxItem Content="DEBUG"/>
<ComboBoxItem Content="TRACE"/>
</ComboBox>
<TextBlock Margin="10,9" Height="30" Grid.Row="1" Grid.Column="0" Text="跳过Numa检测(AMD Ryzen 1000系列请勾选)"/>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" IsChecked="{Binding Config.noNuma}"/>
<TextBlock Margin="10,9" Height="30" Grid.Row="2" Grid.Column="0" Text="开启AVX512烤鸡模式"/>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1" IsChecked="{Binding Config.avx512}"/>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Margin="20,20,20,20" Width="100" Height="30" HorizontalAlignment="Center" VerticalAlignment="Bottom" Content="保存" FontWeight="Bold" Click="Save_Click"/>
<Button Grid.Column="1" Margin="20,20,20,20" Width="100" Height="30" HorizontalAlignment="Center" VerticalAlignment="Bottom" Content="取消" IsCancel="True"/>
</Grid>
</Grid>
</Window>
69 changes: 69 additions & 0 deletions OKEGui/OKEGui/Gui/ConfigPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Microsoft.Win32;
using OKEGui.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace OKEGui
{
/// <summary>
/// Config.xaml 的交互逻辑
/// </summary>
public partial class ConfigPanel : Window
{
public OKEGuiConfig Config { get; }

private void Vspipe_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog
{
Multiselect = false,
Filter = "vspipe.exe (vspipe.exe)|vspipe.exe",
InitialDirectory = Config.vspipePath
};
bool result = ofd.ShowDialog().GetValueOrDefault(false);
if (result)
{
Config.vspipePath = ofd.FileName;
}
}

private void RPChecker_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog
{
Multiselect = false,
Filter = "RPChecker.exe (RPChecker*.exe)|RPChecker*.exe",
InitialDirectory = Config.rpCheckerPath
};
bool result = ofd.ShowDialog().GetValueOrDefault(false);
if (result)
{
Config.rpCheckerPath = ofd.FileName;
}
}

private void Save_Click(object sender, RoutedEventArgs e)
{
Initializer.Config = Config;
Initializer.WriteConfig();
Close();
}

public ConfigPanel()
{
Config = Initializer.Config.Clone() as OKEGuiConfig;
InitializeComponent();
}
}
}
2 changes: 1 addition & 1 deletion OKEGui/OKEGui/Gui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<!--<ComboBoxItem Content="运行程序" />-->
</ComboBox>
<Button Height="23" Margin="200,0,0,0" x:Name="BtnCancelShutdown" VerticalAlignment="Top" HorizontalAlignment="Left" Click="BtnCancelShutdown_Click" Content="点这里取消关机" Width="100" />

<Button Height="23" Width="50" Margin="310,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Click="BtnConfig_Click" Content="设置" />
<Button Height="23" Margin="0,0,0,0" x:Name="BtnDeleteWorker" VerticalAlignment="Top" HorizontalAlignment="Right" Click="BtnDeleteWorker_Click" Content="删除工作单元" Width="100" />
</Grid>
</Grid>
Expand Down
6 changes: 6 additions & 0 deletions OKEGui/OKEGui/Gui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,11 @@ private void BtnCancelShutdown_Click(object sender, RoutedEventArgs e)
Process.Start("cmd.exe", "/c shutdown -a");
BtnCancelShutdown.IsEnabled = false;
}

private void BtnConfig_Click(object sender, RoutedEventArgs e)
{
Window config = new ConfigPanel();
config.ShowDialog();
}
}
}
7 changes: 7 additions & 0 deletions OKEGui/OKEGui/OKEGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Gui\ConfigPanel.xaml.cs">
<DependentUpon>ConfigPanel.xaml</DependentUpon>
</Compile>
<Compile Include="JobProcessor\Audio\FFmpegVolumeChecker.cs" />
<Compile Include="JobProcessor\Demuxer\TrackInfo.cs" />
<Compile Include="JobProcessor\ExceptionParser.cs" />
Expand Down Expand Up @@ -203,6 +206,10 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Page Include="Gui\ConfigPanel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Gui\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
84 changes: 79 additions & 5 deletions OKEGui/OKEGui/Utils/Initializer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using Newtonsoft.Json;
using NLog;
Expand All @@ -9,12 +12,74 @@

namespace OKEGui.Utils
{
class OKEGuiConfig
public class OKEGuiConfig : INotifyPropertyChanged, ICloneable
{
public string vspipePath;
public string logLevel = "DEBUG";
public bool noNuma = false;
public string rpCheckerPath;
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public object Clone()
{
return this.MemberwiseClone();
}

private string _vspipePath;
public string vspipePath
{
get => _vspipePath;
set
{
_vspipePath = value;
NotifyPropertyChanged();
}
}

private string _logLevel = "DEBUG";
public string logLevel
{
get => _logLevel;
set
{
_logLevel = value;
NotifyPropertyChanged();
}
}

private bool _noNuma = false;
public bool noNuma
{
get => _noNuma;
set
{
_noNuma = value;
NotifyPropertyChanged();
}
}

private string _rpCheckerPath;
public string rpCheckerPath
{
get => _rpCheckerPath;
set
{
_rpCheckerPath = value;
NotifyPropertyChanged();
}
}

private bool _avx512;

public bool avx512
{
get => _avx512;
set
{
_avx512 = value;
NotifyPropertyChanged();
}
}
}

static class Initializer
Expand Down Expand Up @@ -82,5 +147,14 @@ public static bool ConfigLogger()
LogManager.Configuration = config;
return true;
}

public static void ClearOldLogs()
{
Directory.GetFiles("log")
.Select(f => new FileInfo(f))
.Where(f => f.LastWriteTime < DateTime.Now.AddMonths(-3) || (f.LastWriteTime < DateTime.Now.AddDays(-7) && f.Length < 1024))
.ToList()
.ForEach(f => f.Delete());
}
}
}

0 comments on commit d953fa3

Please sign in to comment.