-
Notifications
You must be signed in to change notification settings - Fork 0
/
OmniSharpConfig.cs
57 lines (49 loc) · 1.83 KB
/
OmniSharpConfig.cs
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
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
namespace Int19h.Bannerlord.CSharp.Scripting {
[DataContract]
internal class OmniSharpConfig {
private static readonly DataContractJsonSerializer serializer = new(typeof(OmniSharpConfig));
[DataContract]
public class ScriptObject {
[DataMember]
public string? RspFilePath;
}
[DataMember]
public readonly ScriptObject Script = new();
public static void Update() {
var config = new OmniSharpConfig {
Script = {
RspFilePath = Scripts.RspFilePath
}
};
var json = new MemoryStream();
serializer.WriteObject(json, config);
json.Position = 0;
if (!Directory.Exists(Scripts.UserLocation)) {
try {
Directory.CreateDirectory(Scripts.UserLocation);
} catch (Exception) {
return;
}
}
var fileName = Path.Combine(Scripts.UserLocation, "omnisharp.json");
try {
using (var stream = File.Create(fileName)) {
json.CopyTo(stream);
}
} catch (Exception) {
}
fileName = Path.Combine(Scripts.UserLocation, "omnisharp.csproj");
try {
using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
using (var writer = new StreamWriter(stream)) {
writer.Write(@"<Project Sdk='Microsoft.NET.Sdk'><PropertyGroup><TargetFrameworks>net472</TargetFrameworks></PropertyGroup></Project>");
}
} catch (Exception) {
}
}
}
}