Skip to content

Commit

Permalink
参数设置代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjinming1062 committed Jul 3, 2020
1 parent ae084d3 commit 55bca95
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 230 deletions.
209 changes: 50 additions & 159 deletions FunctionClasses/SettingHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace RecordWin
{
internal static class SettingHelp
{
static string filePath = "Setting.dat";
static readonly string filePath = "Setting.dat";
public static Setting Settings = new Setting();
/// <summary>
/// 配置存取类
Expand All @@ -15,6 +15,22 @@ static SettingHelp()
{
CheckSetting();
}
/// <summary>
/// Setting中属性变更时调用
/// </summary>
internal static void SaveSetting()
{
if (Path.GetDirectoryName(filePath).Length > 0)
{
if (!Directory.Exists(Path.GetDirectoryName(filePath)))
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
}
using (FileStream stream = new FileStream(filePath, FileMode.Create))
{
BinaryFormatter bFormat = new BinaryFormatter();
bFormat.Serialize(stream, Settings);
}
}

#region 私有方法
/// <summary>
Expand Down Expand Up @@ -43,166 +59,41 @@ private static void GetSetting()
Settings = (Setting)bFormat.Deserialize(stream);
}
}
/// <summary>
/// Setting中属性变更时调用
/// </summary>
internal static void SaveSetting()
{
if (Path.GetDirectoryName(filePath).Length > 0)
{
if (!Directory.Exists(Path.GetDirectoryName(filePath)))
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
}
using (FileStream stream = new FileStream(filePath, FileMode.Create))
{
BinaryFormatter bFormat = new BinaryFormatter();
bFormat.Serialize(stream, Settings);
}
}
#endregion
}
[Serializable]
class Setting
{
#region 录制源
bool _桌面 = true;
public bool 桌面
{
get => _桌面;
set { _桌面 = value; SettingHelp.SaveSetting(); }
}

bool _摄像头 = true;
public bool 摄像头
{
get => _摄像头;
set { _摄像头 = value; SettingHelp.SaveSetting(); }
}

bool _声音 = true;
public bool 声音
{
get => _声音;
set { _声音 = value; SettingHelp.SaveSetting(); }
}
#endregion

#region 功能
bool _自动隐藏 = false;
public bool 自动隐藏
{
get => _自动隐藏;
set { _自动隐藏 = value; SettingHelp.SaveSetting(); }
}

bool _录制隐藏 = true;
public bool 录制隐藏
{
get => _录制隐藏;
set { _录制隐藏 = value; SettingHelp.SaveSetting(); }
}

string _保存路径 = "Temp";
public string 保存路径
{
get => _保存路径;
set { _保存路径 = value; SettingHelp.SaveSetting(); }
}

string _编码类型 = "mp4";
public string 编码类型
{
get => _编码类型;
set { _编码类型 = value; SettingHelp.SaveSetting(); }
}

string _命名规则 = "yyMMdd_HHmmss";
public string 命名规则
{
get => _命名规则;
set { _命名规则 = value; SettingHelp.SaveSetting(); }
}

bool _跨屏录制 = false;
public bool 跨屏录制
{
get => _跨屏录制;
set { _跨屏录制 = value; SettingHelp.SaveSetting(); }
}

bool _捕获鼠标 = false;
public bool 捕获鼠标
{
get => _捕获鼠标;
set { _捕获鼠标 = value; SettingHelp.SaveSetting(); }
}

bool _保留视频 = false;
public bool 保留视频
{
get => _保留视频;
set { _保留视频 = value; SettingHelp.SaveSetting(); }
}

bool _保留音频 = false;
public bool 保留音频
{
get => _保留音频;
set { _保留音频 = value; SettingHelp.SaveSetting(); }
}
#endregion

#region 录制
int _视频帧率 = 10;
public int 视频帧率
{
get => _视频帧率;
set { _视频帧率 = value; SettingHelp.SaveSetting(); }
}

int _视频质量 = 5;
public int 视频质量
{
get => _视频质量;
set { _视频质量 = value; SettingHelp.SaveSetting(); }
}

string _摄像头Key;
public string 摄像头Key
{
get => _摄像头Key;
set { _摄像头Key = value; SettingHelp.SaveSetting(); }
}

int _摄像头参数 = 0;
public int 摄像头参数
{
get => _摄像头参数;
set { _摄像头参数 = value; SettingHelp.SaveSetting(); }
[Serializable]
public class Setting
{
#region 录制源
public bool 桌面 { get; set; } = true;
public bool 摄像头 { get; set; } = true;
public bool 声音 { get; set; } = true;
#endregion

#region 功能
public bool 自动隐藏 { get; set; } = false;
public bool 录制隐藏 { get; set; } = true;
public string 保存路径 { get; set; } = "Temp";
public string 编码类型 { get; set; } = "mp4";
public string 命名规则 { get; set; }
public bool 跨屏录制 { get; set; } = false;
public bool 捕获鼠标 { get; set; } = false;
public bool 保留视频 { get; set; } = false;
public bool 保留音频 { get; set; } = false;
#endregion

#region 录制
public int 视频帧率 { get; set; } = 10;
public int 视频质量 { get; set; } = 5;
public string 摄像头Key { get; set; }
public int 摄像头参数 { get; set; } = 0;
#endregion

#region 热键
public Tuple<HotKey.KeyModifiers, int> 播放暂停 { get; set; } = new Tuple<HotKey.KeyModifiers, int>(HotKey.KeyModifiers.Shift, (int)System.Windows.Forms.Keys.Space);
public Tuple<HotKey.KeyModifiers, int> 停止关闭 { get; set; } = new Tuple<HotKey.KeyModifiers, int>(HotKey.KeyModifiers.Shift, (int)System.Windows.Forms.Keys.Escape);
public Tuple<HotKey.KeyModifiers, int> 开关画笔 { get; set; } = new Tuple<HotKey.KeyModifiers, int>(HotKey.KeyModifiers.None, (int)System.Windows.Forms.Keys.F1);
#endregion
}
#endregion

#region 热键
Tuple<HotKey.KeyModifiers, int> _播放暂停 = new Tuple<HotKey.KeyModifiers, int>(HotKey.KeyModifiers.Shift, (int)System.Windows.Forms.Keys.Space);
public Tuple<HotKey.KeyModifiers, int> 播放暂停
{
get => _播放暂停;
set { _播放暂停 = value; SettingHelp.SaveSetting(); }
}

Tuple<HotKey.KeyModifiers, int> _停止关闭 = new Tuple<HotKey.KeyModifiers, int>(HotKey.KeyModifiers.Shift, (int)System.Windows.Forms.Keys.Escape);
public Tuple<HotKey.KeyModifiers, int> 停止关闭
{
get => _停止关闭;
set { _停止关闭 = value; SettingHelp.SaveSetting(); }
}

Tuple<HotKey.KeyModifiers, int> _开关画笔 = new Tuple<HotKey.KeyModifiers, int>(HotKey.KeyModifiers.None, (int)System.Windows.Forms.Keys.F1);
public Tuple<HotKey.KeyModifiers, int> 开关画笔
{
get => _开关画笔;
set { _开关画笔 = value; SettingHelp.SaveSetting(); }
}
#endregion
}
}
3 changes: 2 additions & 1 deletion Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private string MakeFilePath(string Type, string Begin = "")
{
Type = "." + Type;
}
string path = Path.Combine(SettingHelp.Settings.保存路径, $"{Begin}{DateTime.Now.ToString(SettingHelp.Settings.命名规则)}{Type}");
string name = string.IsNullOrEmpty(SettingHelp.Settings.命名规则) ? DateTime.Now.ToString("yyMMdd_HHmmss") : SettingHelp.Settings.命名规则;
string path = Path.Combine(SettingHelp.Settings.保存路径, $"{Begin}{name}{Type}");
if (!Directory.Exists(path))//如果指定文件夹不存在则新建文件夹
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
Expand Down
61 changes: 23 additions & 38 deletions Windows/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,10 @@
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:RecordWin"
mc:Ignorable="d"
Height="340" Width="580" ShowInTaskbar="False" WindowStyle="None" WindowStartupLocation="CenterScreen" Topmost="True" AllowsTransparency="True" MouseDown="Window_MouseDown">
mc:Ignorable="d" Height="340" Width="580" ShowInTaskbar="False" WindowStyle="None"
WindowStartupLocation="CenterScreen" Topmost="True" AllowsTransparency="True" MouseDown="Window_MouseDown">
<Grid Background="{StaticResource LinearBackground}">
<Grid.Resources>
<Style TargetType="ToggleButton" BasedOn="{StaticResource FunctionalButton}">
<Setter Property="Padding" Value="0"/>
<Setter Property="Width" Value="24"/>
<Setter Property="Height" Value="24"/>
<Setter Property="Margin" Value="4"/>
<Setter Property="Cursor" Value="Arrow"/>
<Setter Property="Focusable" Value="False"/>
</Style>
<Style TargetType="Path">
<Setter Property="Fill" Value="White"/>
<Setter Property="Stretch" Value="Uniform"/>
<Setter Property="Width" Value="12"/>
<Setter Property="RenderTransformOrigin" Value ="0.5,0.5"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property ="HorizontalAlignment" Value="Center"/>
</Style>
<Style TargetType="GroupBox">
<Setter Property="Margin" Value="4"/>
<Setter Property="Foreground" Value="#FFD34B4B"/>
Expand All @@ -36,22 +19,24 @@
<Setter Property="Orientation" Value="Horizontal"/>
<Setter Property="Margin" Value="4"/>
</Style>
<Style TargetType="RadioButton">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Width" Value="32"/>
</Style>
<Style TargetType="CheckBox">
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="Black" BorderThickness="1,1,1,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!--<TextBlock Text="高级设置" Grid.Column="0"/>-->
<ToggleButton Grid.Column="1" x:Name="btClose" Click="btClose_Click" ToolTip="关闭" HorizontalAlignment="Right" Margin="4,0">
<Path Data="{DynamicResource IconCross}" />
</ToggleButton>
</Grid>
<ToggleButton Grid.Column="1" x:Name="btClose" Click="btClose_Click" ToolTip="关闭" HorizontalAlignment="Right" Margin="4,0" Style="{StaticResource FunctionalButton}" Width="24" Height="24" Cursor="Arrow">
<Path Data="{DynamicResource IconCross}" Fill="White" Width="12" Stretch="Uniform"/>
</ToggleButton>
</Border>
<Border Grid.Row="1" BorderBrush="Black" BorderThickness="1">
<WrapPanel Orientation="Vertical">
Expand All @@ -71,26 +56,26 @@
<GridSplitter Grid.Column="1" Width="2" Grid.RowSpan="4"/>
<StackPanel Grid.Row="0" Grid.Column="2">
<Label Content="视频质量:"/>
<Slider Foreground="White" x:Name="slZHiLiang" Minimum="1" Maximum="10" TickFrequency="1" ToolTip="数值越大视频越清晰,但体积更大" AutoToolTipPlacement="TopLeft" TickPlacement="BottomRight" Width="230"/>
<Slider Foreground="White" x:Name="slZHiLiang" Minimum="5" Maximum="20" TickFrequency="1" ToolTip="数值越大视频越清晰,但体积更大" AutoToolTipPlacement="TopLeft" TickPlacement="BottomRight" Width="230"/>
<Label Content="{Binding ElementName=slZHiLiang, Path=Value}" ToolTip="质量当前值"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="0">
<Label Content="视频帧率:"/>
<ToggleButton x:Name="btZLL" Click="btZL_Click" Content="" ToolTip="5帧" Height="Auto" Foreground="White" Width="32"/>
<ToggleButton x:Name="btZLM" Click="btZL_Click" Content="" ToolTip="10帧" Height="Auto" Foreground="White" Width="32"/>
<ToggleButton x:Name="btZLH" Click="btZL_Click" Content="" ToolTip="20帧" Height="Auto" Foreground="White" Width="32"/>
<RadioButton x:Name="btZLL" Click="btZL_Click" Content="" ToolTip="5帧"/>
<RadioButton x:Name="btZLM" Click="btZL_Click" Content="" ToolTip="10帧"/>
<RadioButton x:Name="btZLH" Click="btZL_Click" Content="" ToolTip="20帧"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
<Label Content="跨屏录制:"/>
<CheckBox x:Name="cbMultiScreen" Click="cbMultiScreen_Click" ToolTip="勾选时录制全部屏幕否则只录制命令栏所在屏幕" VerticalAlignment="Center"/>
<CheckBox x:Name="cbMultiScreen" Click="cbMultiScreen_Click" ToolTip="勾选时录制全部屏幕否则只录制命令栏所在屏幕"/>
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0">
<Label Content="录制隐藏:"/>
<CheckBox x:Name="cbPlayHidden" Click="cbPlayHidden_Click" ToolTip="开始录制时命令栏将临时取消钉住" VerticalAlignment="Center"/>
<CheckBox x:Name="cbPlayHidden" Click="cbPlayHidden_Click" ToolTip="开始录制时命令栏将临时取消钉住"/>
</StackPanel>
<StackPanel Grid.Row="3" Grid.Column="0">
<Label Content="录制鼠标:"/>
<CheckBox x:Name="cbMouse" Click="cbMouse_Click" ToolTip="录制的视频中是否包含鼠标" VerticalAlignment="Center"/>
<CheckBox x:Name="cbMouse" Click="cbMouse_Click" ToolTip="录制的视频中是否包含鼠标"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="2">
<Label Content="录制摄像头配置:"/>
Expand Down Expand Up @@ -161,8 +146,8 @@
</StackPanel>
<StackPanel>
<Label Content="原始文件:"/>
<CheckBox x:Name="cbRawVideo" Click="cbRawVideo_Click" ToolTip="保留原始视频文件(文件名Raw开头)" VerticalAlignment="Center"/>
<CheckBox x:Name="cbRawAudio" Click="cbRawAudio_Click" ToolTip="保留原始音频文件(文件名Raw开头)" Margin="8 0 0 0" VerticalAlignment="Center"/>
<CheckBox x:Name="cbRawVideo" Click="cbRawVideo_Click" ToolTip="保留原始视频文件(文件名Raw开头)"/>
<CheckBox x:Name="cbRawAudio" Click="cbRawAudio_Click" ToolTip="保留原始音频文件(文件名Raw开头)" Margin="8 0 0 0"/>
</StackPanel>
</StackPanel>
</GroupBox>
Expand Down
Loading

0 comments on commit 55bca95

Please sign in to comment.