mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Layout - Allow loading directly from a stream
This commit is contained in:
parent
56d77dee35
commit
ba99ecfbdc
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -118,20 +118,16 @@ public class DeviceLayout : IDeviceLayout
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="DeviceLayout"/> from the specified xml.
|
/// Creates a new <see cref="DeviceLayout"/> from the specified xml.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to the xml file.</param>
|
/// <param name="stream">The stream that contains the layout to be loaded.</param>
|
||||||
/// <param name="customDeviceDataType">The type of the custom data.</param>
|
/// <param name="customDeviceDataType">The type of the custom data.</param>
|
||||||
/// <param name="customLedDataType">The type of the custom data of the leds.</param>
|
/// <param name="customLedDataType">The type of the custom data of the leds.</param>
|
||||||
/// <returns>The deserialized <see cref="DeviceLayout"/>.</returns>
|
/// <returns>The deserialized <see cref="DeviceLayout"/>.</returns>
|
||||||
public static DeviceLayout? Load(string path, Type? customDeviceDataType = null, Type? customLedDataType = null)
|
public static DeviceLayout? Load(Stream stream, Type? customDeviceDataType = null, Type? customLedDataType = null)
|
||||||
{
|
{
|
||||||
if (!File.Exists(path)) return null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
XmlSerializer serializer = new(typeof(DeviceLayout));
|
XmlSerializer serializer = new(typeof(DeviceLayout));
|
||||||
using StreamReader reader = new(path);
|
DeviceLayout? layout = serializer.Deserialize(stream) as DeviceLayout;
|
||||||
|
|
||||||
DeviceLayout? layout = serializer.Deserialize(reader) as DeviceLayout;
|
|
||||||
if (layout != null)
|
if (layout != null)
|
||||||
layout.CustomData = layout.GetCustomData(layout.InternalCustomData, customDeviceDataType);
|
layout.CustomData = layout.GetCustomData(layout.InternalCustomData, customDeviceDataType);
|
||||||
|
|
||||||
@ -155,6 +151,21 @@ public class DeviceLayout : IDeviceLayout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="DeviceLayout"/> from the specified xml.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path to the xml file.</param>
|
||||||
|
/// <param name="customDeviceDataType">The type of the custom data.</param>
|
||||||
|
/// <param name="customLedDataType">The type of the custom data of the leds.</param>
|
||||||
|
/// <returns>The deserialized <see cref="DeviceLayout"/>.</returns>
|
||||||
|
public static DeviceLayout? Load(string path, Type? customDeviceDataType = null, Type? customLedDataType = null)
|
||||||
|
{
|
||||||
|
if (!File.Exists(path)) return null;
|
||||||
|
|
||||||
|
using Stream stream = File.OpenRead(path);
|
||||||
|
return Load(stream, customDeviceDataType, customLedDataType);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the deserialized custom data.
|
/// Gets the deserialized custom data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -177,4 +188,4 @@ public class DeviceLayout : IDeviceLayout
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user