Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
静音&记忆全屏
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Oct 20, 2015
1 parent 20d52a7 commit 90b98e1
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 51 deletions.
7 changes: 6 additions & 1 deletion AdmiralRoom/AdmiralRoom.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="CoreAudioApi, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\assemblies\CoreAudioApi.dll</HintPath>
</Reference>
<Reference Include="FiddlerCore4, Version=4.5.1.0, Culture=neutral, PublicKeyToken=67cb91587178ac5a, processorArchitecture=MSIL">
<HintPath>..\packages\FiddlerCore.4.5.1.0\lib\net40\FiddlerCore4.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -158,7 +162,8 @@
</Compile>
<Compile Include="Models\APIModel.cs" />
<Compile Include="Models\Exp.cs" />
<Compile Include="Models\StatusModel.cs" />
<Compile Include="Models\Status.cs" />
<Compile Include="Models\Volume.cs" />
<Compile Include="Officer\Admiral.cs" />
<Compile Include="Officer\BuildingDock.cs" />
<Compile Include="Officer\EquipInfo.cs" />
Expand Down
2 changes: 1 addition & 1 deletion AdmiralRoom/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override void OnStartup(StartupEventArgs e)
this.MainWindow = new MainWindow();
Officer.Staff.Current.Dispatcher = MainWindow.Dispatcher;
this.MainWindow.Show();
Models.StatusModel.Current.StatusText = "就绪";
Models.Status.Current.StatusText = "就绪";
}
protected override void OnExit(ExitEventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion AdmiralRoom/Common/NotifyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Huoyaoyuan.AdmiralRoom
public class NotifyBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName]string name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
protected virtual void OnPropertyChanged([CallerMemberName]string name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
protected virtual void OnAllPropertyChanged() => OnPropertyChanged(null);
}
}
41 changes: 23 additions & 18 deletions AdmiralRoom/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<ribbon:RibbonWindow
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:Huoyaoyuan.AdmiralRoom"
xmlns:ribbon="urn:fluent-ribbon"
xmlns:Models="clr-namespace:Huoyaoyuan.AdmiralRoom.Models" x:Name="ribbonWindow" x:Class="Huoyaoyuan.AdmiralRoom.MainWindow"
xmlns:Dock="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:Theme2010="clr-namespace:Xceed.Wpf.AvalonDock.Themes;assembly=Xceed.Wpf.AvalonDock.Themes.VS2010"
xmlns:Theme2013="clr-namespace:Xceed.Wpf.AvalonDock.Themes;assembly=Xceed.Wpf.AvalonDock.Themes.VS2013"
xmlns:Views="clr-namespace:Huoyaoyuan.AdmiralRoom.Views"
mc:Ignorable="d"
FontFamily="DengXian"
FontSize="15"
Loaded="LoadLayout" Unloaded="SaveLayout"
Title="提督の部屋" d:DesignWidth="1920" d:DesignHeight="1080" WindowState="Maximized">
<ribbon:RibbonWindow x:Name="ribbonWindow" x:Class="Huoyaoyuan.AdmiralRoom.MainWindow"
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:Huoyaoyuan.AdmiralRoom"
xmlns:ribbon="urn:fluent-ribbon"
xmlns:Models="clr-namespace:Huoyaoyuan.AdmiralRoom.Models"
xmlns:Dock="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:Theme2010="clr-namespace:Xceed.Wpf.AvalonDock.Themes;assembly=Xceed.Wpf.AvalonDock.Themes.VS2010"
xmlns:Theme2013="clr-namespace:Xceed.Wpf.AvalonDock.Themes;assembly=Xceed.Wpf.AvalonDock.Themes.VS2013"
xmlns:Views="clr-namespace:Huoyaoyuan.AdmiralRoom.Views"
mc:Ignorable="d"
FontFamily="DengXian"
FontSize="15"
Loaded="LoadLayout" Unloaded="SaveLayout"
Title="提督の部屋">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -45,6 +45,11 @@
<ribbon:Button Header="刷新" KeyTip="R" x:Name="BrowserRefresh" LargeIcon="{StaticResource IconRefresh}"/>
<ribbon:Button Header="回到游戏" KeyTip="H" x:Name="BrowserBackToGame" LargeIcon="{StaticResource IconGame}"/>
</ribbon:RibbonGroupBox>
<ribbon:RibbonGroupBox Header="操作">
<ribbon:ToggleButton Header="静音" KeyTip="M"
IsChecked="{Binding Volume.IsMute, Source={x:Static Models:Status.Current}}"
IsEnabled="{Binding IsGameLoaded, Source={x:Static Models:Status.Current}}"/>
</ribbon:RibbonGroupBox>
<ribbon:RibbonGroupBox Header="代理">
<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -146,7 +151,7 @@
</Dock:LayoutPanel>
</Dock:LayoutRoot>
</Dock:DockingManager>
<ribbon:StatusBar Grid.Row="2" FontSize="18" DataContext="{x:Static Models:StatusModel.Current}">
<ribbon:StatusBar Grid.Row="2" FontSize="18" DataContext="{x:Static Models:Status.Current}">
<ribbon:StatusBarItem HorizontalAlignment="Left" Content="{Binding StatusText}"/>
<Separator HorizontalAlignment="Left"/>
</ribbon:StatusBar>
Expand Down
2 changes: 2 additions & 0 deletions AdmiralRoom/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public MainWindow()
FontSmall.Click += (_, __) => this.FontSize -= 1;

this.Loaded += (_, __) => GameHost.Browser.Navigate(Properties.Settings.Default.GameUrl);
this.Loaded += (_, __) => Win32Helper.GetRestoreWindowPosition(this);
this.Closing += (_, __) => Win32Helper.SetRestoreWindowPosition(this);
}

private void MakeViewList(ILayoutElement elem)
Expand Down
50 changes: 50 additions & 0 deletions AdmiralRoom/Models/Status.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace Huoyaoyuan.AdmiralRoom.Models
{
class Status : NotifyBase
{
public static Status Current { get; } = new Status();

private Volume _volume;
public Volume Volume
{
get
{
if (_volume == null) _volume = Volume.GetInstance();
return _volume;
}
}

#region StatusText
private string _statustext = "";
public string StatusText
{
get { return _statustext; }
set
{
if(_statustext != value)
{
_statustext = value;
OnPropertyChanged();
}
}
}
#endregion

#region IsGameLoaded
private bool _isgameloaded;
public bool IsGameLoaded
{
get { return _isgameloaded; }
set
{
if (_isgameloaded != value)
{
_isgameloaded = value;
OnAllPropertyChanged();
}
}
}
#endregion

}
}
22 changes: 0 additions & 22 deletions AdmiralRoom/Models/StatusModel.cs

This file was deleted.

73 changes: 73 additions & 0 deletions AdmiralRoom/Models/Volume.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using CoreAudioApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Huoyaoyuan.AdmiralRoom.Models
{
class Volume : NotifyBase
{
private SimpleAudioVolume simpleaudiovolume;

#region IsMute
private bool _ismute;
public bool IsMute
{
get { return _ismute; }
set
{
if (_ismute != value)
{
_ismute = value;
simpleaudiovolume.Mute = value;
OnPropertyChanged();
}
}
}
#endregion

#region Value
private float _value;
/// <summary>
/// 音量。范围为0~1
/// </summary>
public float Value
{
get { return _value; }
set
{
if (_value != value)
{
_value = value;
simpleaudiovolume.MasterVolume = value;
OnPropertyChanged();
}
}
}
#endregion

private Volume() { }
public static Volume GetInstance()
{
var volume = new Volume();
var processid = Process.GetCurrentProcess().Id;
var device = (new MMDeviceEnumerator()).GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
for (int i = 0; i < device.AudioSessionManager.Sessions.Count; i++)
{
var session = device.AudioSessionManager.Sessions[i];
if (session.ProcessID == processid)
{
volume.simpleaudiovolume = session.SimpleAudioVolume;
volume.IsMute = volume.simpleaudiovolume.Mute;
volume.Value = volume.simpleaudiovolume.MasterVolume;
}
}
if (volume.simpleaudiovolume == null) return null;
return volume;
}
}
}
1 change: 1 addition & 0 deletions AdmiralRoom/Officer/MasterData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public MasterData()
public IDTable<MissionInfo> MissionInfo { get; private set; }
void MasterHandler(api_start2 api)
{
Models.Status.Current.IsGameLoaded = true;
ShipTypes = new IDTable<ShipType>(api.api_mst_stype.ArrayOperation(x => new ShipType(x)));
ShipInfo = new IDTable<ShipInfo>(api.api_mst_ship.ArrayOperation(x => new ShipInfo(x)));
EquipTypes = new IDTable<EquipType>(api.api_mst_slotitem_equiptype.ArrayOperation(x => new EquipType(x)));
Expand Down
2 changes: 1 addition & 1 deletion AdmiralRoom/Officer/Staff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static void AfterSessionComplete(Session oSession)
{
if (oSession.PathAndQuery.StartsWith("/kcsapi") && oSession.oResponse.MIMEType.Equals("text/plain"))
{
Models.StatusModel.Current.StatusText = "已读取" + oSession.url;
Models.Status.Current.StatusText = "已读取" + oSession.url;
//Thread th = new Thread(new ParameterizedThreadStart(Distribute));
//th.Start(oSession);
oSession.utilDecodeResponse();
Expand Down
98 changes: 91 additions & 7 deletions AdmiralRoom/Win32/Win32Helper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using Microsoft.Win32;

namespace Huoyaoyuan.AdmiralRoom
{
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public RECT(int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;

public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPLACEMENT
{
public int length;
public int flags;
public int showCmd;
public POINT minPosition;
public POINT maxPosition;
public RECT normalPosition;
}
public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
};
internal static class Win32Helper
{
public static void SetIEEmulation(int mode)
Expand Down Expand Up @@ -34,14 +80,8 @@ public static void SetMMCSSTask()
uint index = 0;
AvSetMmThreadCharacteristics("Games", ref index);
}
public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
};
[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
public static bool RefreshIESettings(string strProxy)//strProxy为代理IP:端口
{
const int INTERNET_OPTION_PROXY = 38;
Expand All @@ -63,5 +103,49 @@ public static bool RefreshIESettings(string strProxy)//strProxy为代理IP:端
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
return InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}
[DllImport("user32.dll")]
public static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl);
[DllImport("user32.dll")]
public static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
public static void SetRestoreWindowPosition(Window window)
{
var hwnd = (HwndSource.FromVisual(window) as HwndSource).Handle;
WINDOWPLACEMENT placement;
GetWindowPlacement(hwnd, out placement);
var AppFilename = Process.GetCurrentProcess().MainModule.FileName;
IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WINDOWPLACEMENT)));
try
{
Marshal.StructureToPtr(placement, buffer, false);
byte[] data = new byte[Marshal.SizeOf(typeof(WINDOWPLACEMENT))];
Marshal.Copy(buffer, data, 0, Marshal.SizeOf(typeof(WINDOWPLACEMENT)));
Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationFrame\Positions\" + AppFilename, "PositionObject", data, RegistryValueKind.Binary);
Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationFrame\Positions\" + AppFilename, "Version", 3, RegistryValueKind.DWord);
}
catch { }
finally
{
Marshal.FreeHGlobal(buffer);
}
}
public static void GetRestoreWindowPosition(Window window)
{
var hwnd = (HwndSource.FromVisual(window) as HwndSource).Handle;
WINDOWPLACEMENT placement;
var AppFilename = Process.GetCurrentProcess().MainModule.FileName;
try
{
byte[] data = (byte[])Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationFrame\Positions\" + AppFilename, "PositionObject", null);
IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WINDOWPLACEMENT)));
Marshal.Copy(data, 0, buffer, Marshal.SizeOf(typeof(WINDOWPLACEMENT)));
placement = Marshal.PtrToStructure<WINDOWPLACEMENT>(buffer);
Marshal.FreeHGlobal(buffer);
}
catch
{
return;
}
SetWindowPlacement(hwnd, ref placement);
}
}
}
Binary file added assemblies/CoreAudioApi.dll
Binary file not shown.

0 comments on commit 90b98e1

Please sign in to comment.