forked from allista/AT_Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KSP_AVC_Updater.cs
81 lines (76 loc) · 2.22 KB
/
KSP_AVC_Updater.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// KSP_AVC_Updater.cs
//
// Author:
// Allis Tauri <[email protected]>
//
// Copyright (c) 2015 Allis Tauri
using System;
using System.IO;
using System.Reflection;
namespace AT_Utils
{
public class KSP_AVC_Info
{
public string Name;
public Version ModVersion;
public Version MinKSPVersion;
public Version MaxKSPVersion;
public string VersionURL;
public string UpgradeURL;
public string ChangeLogURL;
public string PluginDir;
public string VersionFile { get { return Path.Combine(PluginDir, string.Format("{0}.version", Name)); } }
public KSP_AVC_Info()
{
Name = Assembly.GetCallingAssembly().GetName().Name;
ModVersion = Assembly.GetCallingAssembly().GetName().Version;
MinKSPVersion = new Version(1,0,0);
MaxKSPVersion = new Version(1,0,0);
VersionURL = "";
UpgradeURL = "";
ChangeLogURL = "";
PluginDir = Name;
}
}
public static class KSP_AVC_Updater
{
public static void UpdateFor(params KSP_AVC_Info[] infos)
{
foreach(var info in infos)
{
using(var file = new StreamWriter(info.VersionFile))
{
file.WriteLine(
@"{{
""NAME"":""{0}"",
""URL"":""{1}"",
""DOWNLOAD"":""{2}"",
""CHANGE_LOG_URL"":""{3}"",
""VERSION"":
{{", info.Name, info.VersionURL, info.UpgradeURL, info.ChangeLogURL);
file.WriteLine(" \"MAJOR\":{0},", info.ModVersion.Major);
file.WriteLine(" \"MINOR\":{0},", info.ModVersion.Minor);
file.WriteLine(" \"PATCH\":{0},", info.ModVersion.Build);
file.WriteLine(" \"BUILD\":{0}", info.ModVersion.Revision);
file.WriteLine(
@" },
""KSP_VERSION_MIN"":
{");
file.WriteLine(" \"MAJOR\":{0},", info.MinKSPVersion.Major);
file.WriteLine(" \"MINOR\":{0},", info.MinKSPVersion.Minor);
file.WriteLine(" \"PATCH\":{0}", info.MinKSPVersion.Build);
file.WriteLine(
@" },
""KSP_VERSION_MAX"":
{");
file.WriteLine(" \"MAJOR\":{0},", info.MaxKSPVersion.Major);
file.WriteLine(" \"MINOR\":{0},", info.MaxKSPVersion.Minor);
file.WriteLine(" \"PATCH\":{0}", info.MaxKSPVersion.Build);
file.WriteLine(
@" }
}");
}
}
}
}
}