Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefNemec committed Nov 26, 2019
2 parents f87ff2e + ea0d577 commit 48f339f
Show file tree
Hide file tree
Showing 69 changed files with 816 additions and 521 deletions.
62 changes: 62 additions & 0 deletions source/Playnite.Common/Computer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Win32;
using Playnite.SDK;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -54,8 +55,18 @@ public enum WindowsVersion
Win10
}

public enum HwCompany
{
Intel,
AMD,
Nvidia,
VMware,
Uknown
}

public static class Computer
{
private static readonly ILogger logger = LogManager.GetLogger();
public static WindowsVersion WindowsVersion
{
get
Expand Down Expand Up @@ -167,5 +178,56 @@ public static ComputerScreen ToComputerScreen(this Screen screen)
return new ComputerScreen(screen);
}
}

public static List<HwCompany> GetGpuVendors()
{
var gpus = new List<string>();
var vendors = new List<HwCompany>();
try
{
using (var video = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"))
{
foreach (var obj in video.Get())
{
gpus.Add(obj["Name"].ToString());
}
}

foreach (var gpu in gpus)
{
if (gpu.Contains("intel", StringComparison.OrdinalIgnoreCase))
{
vendors.AddMissing(HwCompany.Intel);
}
else if (gpu.Contains("nvidia", StringComparison.OrdinalIgnoreCase))
{
vendors.AddMissing(HwCompany.Nvidia);
}
else if (gpu.Contains("amd", StringComparison.OrdinalIgnoreCase))
{
vendors.AddMissing(HwCompany.AMD);
}
else if (gpu.Contains("vmware", StringComparison.OrdinalIgnoreCase))
{
vendors.AddMissing(HwCompany.VMware);
}
else
{
return new List<HwCompany> { HwCompany.Uknown };
}
}

if (vendors.Count > 0)
{
return vendors;
}
}
catch (Exception e)
{
logger.Error(e, "Failed to get GPU vendor.");
}

return new List<HwCompany> { HwCompany.Uknown };
}
}
}
116 changes: 85 additions & 31 deletions source/Playnite.Common/Extensions/BitmapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,77 @@

namespace System.Drawing.Imaging
{
public class BitmapLoadProperties
public class BitmapLoadProperties: IEquatable<BitmapLoadProperties>
{
public DpiScale? DpiScale { get; set; }
public int MaxDecodePixelWidth { get; set; } = 0;
public int MaxDecodePixelHeight { get; set; } = 0;
public string Source { get; set; }

public BitmapLoadProperties(int decodePixelWidth)
public BitmapLoadProperties(int decodePixelWidth, int decodePixelHeight)
{
MaxDecodePixelWidth = decodePixelWidth;
MaxDecodePixelHeight = decodePixelHeight;
}

public BitmapLoadProperties(int decodePixelWidth, DpiScale? dpiScale)
public BitmapLoadProperties(int decodePixelWidth, int decodePixelHeight, DpiScale? dpiScale)
{
MaxDecodePixelWidth = decodePixelWidth;
MaxDecodePixelHeight = decodePixelHeight;
DpiScale = dpiScale;
}

public bool Equals(BitmapLoadProperties other)
{
if (other is null)
{
return false;
}

if (DpiScale?.Equals(other.DpiScale) == false)
{
return false;
}

if (MaxDecodePixelWidth != other.MaxDecodePixelWidth)
{
return false;
}

if (MaxDecodePixelHeight != other.MaxDecodePixelHeight)
{
return false;
}

if (!string.Equals(Source, other.Source, StringComparison.Ordinal))
{
return false;
}

return true;
}

public override bool Equals(object obj) => Equals(obj as BitmapLoadProperties);

public override int GetHashCode() =>
(Source == null ? 0 : Source.GetHashCode()) ^
(DpiScale == null ? 0 : DpiScale.GetHashCode()) ^
MaxDecodePixelWidth.GetHashCode() ^
MaxDecodePixelHeight.GetHashCode();

public static bool operator ==(BitmapLoadProperties obj1, BitmapLoadProperties obj2)
{
return obj1?.Equals(obj2) == true;
}

public static bool operator !=(BitmapLoadProperties obj1, BitmapLoadProperties obj2)
{
return obj1?.Equals(obj2) == false;
}

public override string ToString()
{
return $"{MaxDecodePixelWidth}x{MaxDecodePixelHeight};{DpiScale?.DpiScaleX}x{DpiScale?.DpiScaleY};{Source}";
}
}

Expand Down Expand Up @@ -107,21 +163,45 @@ public static BitmapImage BitmapFromStream(Stream stream, BitmapLoadProperties l
try
{
var properties = Images.GetImageProperties(stream);
var aspect = new AspectRatio(properties.Width, properties.Height);
stream.Seek(0, SeekOrigin.Begin);
var bitmap = new BitmapImage();
bitmap.BeginInit();

if (loadProperties?.MaxDecodePixelWidth > 0 && properties?.Width > loadProperties?.MaxDecodePixelWidth)
{
if (loadProperties.DpiScale != null)
{
bitmap.DecodePixelWidth = Convert.ToInt32(loadProperties.MaxDecodePixelWidth * loadProperties.DpiScale.Value.DpiScaleX);
bitmap.DecodePixelWidth = (int)Math.Round(loadProperties.MaxDecodePixelWidth * loadProperties.DpiScale.Value.DpiScaleX);
}
else
{
bitmap.DecodePixelWidth = loadProperties.MaxDecodePixelWidth;
}
}
bitmap.StreamSource = stream;

if (loadProperties?.MaxDecodePixelHeight > 0 && properties?.Height > loadProperties?.MaxDecodePixelHeight)
{
if (loadProperties.DpiScale != null)
{
bitmap.DecodePixelHeight = Convert.ToInt32(loadProperties.MaxDecodePixelHeight * loadProperties.DpiScale.Value.DpiScaleY);
}
else
{
bitmap.DecodePixelHeight = loadProperties.MaxDecodePixelHeight;
}
}

if (bitmap.DecodePixelHeight != 0 && bitmap.DecodePixelWidth == 0)
{
bitmap.DecodePixelWidth = (int)Math.Round(aspect.GetWidth(bitmap.DecodePixelHeight));
}
else if (bitmap.DecodePixelWidth != 0 && bitmap.DecodePixelHeight == 0)
{
bitmap.DecodePixelHeight = (int)Math.Round(aspect.GetHeight(bitmap.DecodePixelWidth));
}

bitmap.StreamSource = stream;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze();
Expand Down Expand Up @@ -178,32 +258,6 @@ public static Bitmap ToBitmap(this BitmapImage bitmapImage)
}
}

public static BitmapImage ToBitmapImage(this Bitmap bitmap, BitmapLoadProperties loadProperties = null)
{
using (var memory = new MemoryStream())
{
bitmap.Save(memory, ImageFormat.Png);
memory.Seek(0, SeekOrigin.Begin);
var properties = Images.GetImageProperties(memory);
memory.Seek(0, SeekOrigin.Begin);
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
if (loadProperties.DpiScale != null)
{
bitmapImage.DecodePixelWidth = Convert.ToInt32(loadProperties.MaxDecodePixelWidth * loadProperties.DpiScale.Value.DpiScaleX);
}
else
{
bitmapImage.DecodePixelWidth = loadProperties.MaxDecodePixelWidth;
}
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
}

public static BitmapImage TgaToBitmap(string tgaPath)
{
return TgaToBitmap(new TGA(tgaPath));
Expand Down
27 changes: 12 additions & 15 deletions source/Playnite.Common/Sizes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,7 @@ public AspectRatio(int width, int height)
Height = height;
}

public override bool Equals(object obj)
{
if (obj is AspectRatio other)
{
return other.Height == Height && other.Width == Width;
}
else
{
return false;
}
}
public override bool Equals(object obj) => Equals(obj as AspectRatio);

public bool Equals(AspectRatio other)
{
Expand All @@ -71,10 +61,17 @@ public bool Equals(AspectRatio other)

public override int GetHashCode()
{
var hashCode = 859600377;
hashCode = hashCode * -1521134295 + Width.GetHashCode();
hashCode = hashCode * -1521134295 + Height.GetHashCode();
return hashCode;
return Height.GetHashCode() ^ Width.GetHashCode();
}

public static bool operator ==(AspectRatio obj1, AspectRatio obj2)
{
return obj1?.Equals(obj2) == true;
}

public static bool operator !=(AspectRatio obj1, AspectRatio obj2)
{
return obj1?.Equals(obj2) == false;
}

public override string ToString()
Expand Down
8 changes: 4 additions & 4 deletions source/Playnite.DesktopApp/Controls/GameListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public override void OnApplyTemplate()
var sourceBinding = new PriorityBinding();
sourceBinding.Bindings.Add(new Binding()
{
Path = new PropertyPath(nameof(GamesCollectionViewEntry.IconObjectCached)),
Path = new PropertyPath(nameof(GamesCollectionViewEntry.DetailsListIconObjectCached)),
IsAsync = mainModel.AppSettings.AsyncImageLoading,
Converter = new NullToDependencyPropertyUnsetConverter(),
Mode = BindingMode.OneWay
});
sourceBinding.Bindings.Add(new Binding()
{
Path = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultIconObjectCached)),
Path = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultDetailsListIconObjectCached)),
Converter = new NullToDependencyPropertyUnsetConverter(),
Mode = BindingMode.OneWay
});
Expand All @@ -111,14 +111,14 @@ public override void OnApplyTemplate()
var sourceBinding = new PriorityBinding();
sourceBinding.Bindings.Add(new Binding()
{
Path = new PropertyPath(nameof(GamesCollectionViewEntry.CoverImageObjectCached)),
Path = new PropertyPath(nameof(GamesCollectionViewEntry.GridViewCoverObjectCached)),
IsAsync = mainModel.AppSettings.AsyncImageLoading,
Converter = new NullToDependencyPropertyUnsetConverter(),
Mode = BindingMode.OneWay
});
sourceBinding.Bindings.Add(new Binding()
{
Path = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultCoverImageObjectCached)),
Path = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultGridViewCoverObjectCached)),
Converter = new NullToDependencyPropertyUnsetConverter(),
Mode = BindingMode.OneWay
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@
<CheckBox Content="{DynamicResource LOCSettingsShowBackImageOnGridView}" Margin="25,15,0,0"
IsChecked="{Binding Settings.ShowBackImageOnGridView}"
IsEnabled="{Binding Settings.ShowBackgroundImageOnWindow}"/>

<CheckBox Content="{DynamicResource LOCSettingsBackgroundImageAnimation}" Margin="0,15,0,0"
IsChecked="{Binding Settings.BackgroundImageAnimation}"/>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="Playnite.DesktopApp.Controls.SettingsSections.NoSettingsAvailable"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Playnite.DesktopApp.Controls.SettingsSections"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Text="{DynamicResource LOCSettingsNoSettingsAvailable}"
Style="{DynamicResource BaseTextBlockStyle}"
VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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.Navigation;
using System.Windows.Shapes;

namespace Playnite.DesktopApp.Controls.SettingsSections
{
/// <summary>
/// Interaction logic for EmptyParent.xaml
/// </summary>
public partial class NoSettingsAvailable : UserControl
{
public NoSettingsAvailable()
{
InitializeComponent();
}
}
}
Loading

0 comments on commit 48f339f

Please sign in to comment.