Codestyling...

This commit is contained in:
2019-12-06 21:09:52 +01:00
parent 800b81d88f
commit f9015f8022
21 changed files with 2883 additions and 3036 deletions
@@ -1,65 +1,56 @@
namespace Unosquare.WiringPi.Resources
{
using Native;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using Unosquare.WiringPi.Native;
namespace Unosquare.WiringPi.Resources {
/// <summary>
/// Provides access to embedded assembly files.
/// </summary>
internal static class EmbeddedResources {
/// <summary>
/// Provides access to embedded assembly files.
/// Initializes static members of the <see cref="EmbeddedResources"/> class.
/// </summary>
internal static class EmbeddedResources
{
/// <summary>
/// Initializes static members of the <see cref="EmbeddedResources"/> class.
/// </summary>
static EmbeddedResources()
{
ResourceNames =
new ReadOnlyCollection<string>(typeof(EmbeddedResources).Assembly.GetManifestResourceNames());
}
/// <summary>
/// Gets the resource names.
/// </summary>
/// <value>
/// The resource names.
/// </value>
public static ReadOnlyCollection<string> ResourceNames { get; }
/// <summary>
/// Extracts all the file resources to the specified base path.
/// </summary>
public static void ExtractAll()
{
var basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var executablePermissions = SysCall.StringToInteger("0777", IntPtr.Zero, 8);
foreach (var resourceName in ResourceNames)
{
var filename = resourceName.Substring($"{typeof(EmbeddedResources).Namespace}.".Length);
var targetPath = Path.Combine(basePath, filename);
if (File.Exists(targetPath)) return;
using (var stream = typeof(EmbeddedResources).Assembly
.GetManifestResourceStream(resourceName))
{
using (var outputStream = File.OpenWrite(targetPath))
{
stream?.CopyTo(outputStream);
}
try
{
SysCall.Chmod(targetPath, (uint)executablePermissions);
}
catch
{
/* Ignore */
}
}
}
}
}
static EmbeddedResources() => ResourceNames = new ReadOnlyCollection<String>(typeof(EmbeddedResources).Assembly.GetManifestResourceNames());
/// <summary>
/// Gets the resource names.
/// </summary>
/// <value>
/// The resource names.
/// </value>
public static ReadOnlyCollection<String> ResourceNames {
get;
}
/// <summary>
/// Extracts all the file resources to the specified base path.
/// </summary>
public static void ExtractAll() {
String basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Int32 executablePermissions = SysCall.StringToInteger("0777", IntPtr.Zero, 8);
foreach(String resourceName in ResourceNames) {
String filename = resourceName.Substring($"{typeof(EmbeddedResources).Namespace}.".Length);
String targetPath = Path.Combine(basePath, filename);
if(File.Exists(targetPath)) {
return;
}
using(Stream stream = typeof(EmbeddedResources).Assembly.GetManifestResourceStream(resourceName)) {
using(FileStream outputStream = File.OpenWrite(targetPath)) {
stream?.CopyTo(outputStream);
}
try {
_ = SysCall.Chmod(targetPath, (UInt32)executablePermissions);
} catch {
/* Ignore */
}
}
}
}
}
}