This repository was archived by the owner on Jan 5, 2023. It is now read-only.
forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEmbeddedFileHelper.cs
More file actions
72 lines (60 loc) · 2.45 KB
/
EmbeddedFileHelper.cs
File metadata and controls
72 lines (60 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.IO;
using System.Reflection;
namespace ElectronNET.CLI
{
public static class EmbeddedFileHelper
{
private const string ResourcePath = "ElectronNET.CLI.{0}";
private const string ResourcePath2 = "ElectronNet.CLI.{0}";
private static Stream GetTestResourceFileStream(string folderAndFileInProjectPath)
{
var asm = Assembly.GetExecutingAssembly();
var resource = string.Format(ResourcePath, folderAndFileInProjectPath);
var resource2 = string.Format(ResourcePath2, folderAndFileInProjectPath);
var stream = asm.GetManifestResourceStream(resource) ?? asm.GetManifestResourceStream(resource2);
if(stream is null)
{
PrintAllResources();
Console.WriteLine("Was missing resource: {0}", resource);
return null;
}
else
{
return stream;
}
}
public static void PrintAllResources()
{
var asm = Assembly.GetExecutingAssembly();
foreach (var n in asm.GetManifestResourceNames())
{
Console.WriteLine("Found resource : {0}", n);
}
}
public static void DeployEmbeddedFile(string targetPath, string file, string namespacePath = "")
{
using (var fileStream = File.Create(Path.Combine(targetPath, file)))
{
var streamFromEmbeddedFile = GetTestResourceFileStream("ElectronHost." + namespacePath + file);
if (streamFromEmbeddedFile == null)
{
Console.WriteLine("Error: Couldn't find embedded file: " + file);
}
streamFromEmbeddedFile.CopyTo(fileStream);
}
}
public static void DeployEmbeddedFileToTargetFile(string targetPath, string embeddedFile, string targetFile, string namespacePath = "")
{
using (var fileStream = File.Create(Path.Combine(targetPath, targetFile)))
{
var streamFromEmbeddedFile = GetTestResourceFileStream("ElectronHost." + namespacePath + embeddedFile);
if (streamFromEmbeddedFile == null)
{
Console.WriteLine("Error: Couldn't find embedded file: " + embeddedFile);
}
streamFromEmbeddedFile.CopyTo(fileStream);
}
}
}
}