2017-10-04 23:11:23 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ElectronNET.CLI
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class EmbeddedFileHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
private const string ResourcePath = "ElectronNET.CLI.{0}";
|
|
|
|
|
|
|
2017-10-05 21:28:47 +02:00
|
|
|
|
private static Stream GetTestResourceFileStream(string folderAndFileInProjectPath)
|
2017-10-04 23:11:23 +02:00
|
|
|
|
{
|
|
|
|
|
|
var asm = Assembly.GetExecutingAssembly();
|
|
|
|
|
|
var resource = string.Format(ResourcePath, folderAndFileInProjectPath);
|
|
|
|
|
|
|
|
|
|
|
|
return asm.GetManifestResourceStream(resource);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-05 21:28:47 +02:00
|
|
|
|
private static string GetTestResourceFileContent(string folderAndFileInProjectPath)
|
2017-10-04 23:11:23 +02:00
|
|
|
|
{
|
|
|
|
|
|
var asm = Assembly.GetExecutingAssembly();
|
|
|
|
|
|
var resource = string.Format(ResourcePath, folderAndFileInProjectPath);
|
|
|
|
|
|
|
|
|
|
|
|
using (var stream = asm.GetManifestResourceStream(resource))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (stream != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var reader = new StreamReader(stream);
|
|
|
|
|
|
return reader.ReadToEnd();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return String.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-05 21:28:47 +02:00
|
|
|
|
public static void DeployEmbeddedFile(string targetPath, string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var fileStream = File.Create(Path.Combine(targetPath, file)))
|
|
|
|
|
|
{
|
|
|
|
|
|
var streamFromEmbeddedFile = GetTestResourceFileStream("ElectronHost." + file);
|
|
|
|
|
|
streamFromEmbeddedFile.CopyTo(fileStream);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-04 23:11:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|