-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.InitVSCode.cs
More file actions
43 lines (38 loc) · 1.36 KB
/
Program.InitVSCode.cs
File metadata and controls
43 lines (38 loc) · 1.36 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
using System;
using System.IO;
using System.Linq;
namespace CSharpScriptRunner
{
static partial class Program
{
static void InitVSCode()
{
const string VSCodeDir = ".vscode";
const string Filter = ".Templates.vscode.";
var templates = typeof(Program).Assembly.GetManifestResourceNames()
.Select(x => (i: x.IndexOf(Filter), s: x))
.Where(x => x.i > -1)
.Select(x => (name: x.s, File: Path.Combine(VSCodeDir, x.s.Substring(x.i + Filter.Length))));
var dir = new DirectoryInfo(VSCodeDir);
if (!dir.Exists)
{
dir.Create();
//dir.Attributes |= FileAttributes.Hidden;
}
foreach (var template in templates)
{
if (File.Exists(template.File))
{
WriteLine($"File '{template.File}' already exists.", ConsoleColor.Yellow);
continue;
}
using (var stream = typeof(Program).Assembly.GetManifestResourceStream(template.name))
using (var file = File.OpenWrite(template.File))
{
WriteLine($"Creating file '{template.File}'...", ConsoleColor.Green);
stream.CopyTo(file);
}
}
}
}
}