forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
95 lines (80 loc) · 4.17 KB
/
Program.cs
File metadata and controls
95 lines (80 loc) · 4.17 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma warning disable SA1516 // Elements should be separated by blank line
using System;
using System.IO;
using System.Linq;
using System.Text;
const bool isDebugOrRelease = false;
const string platform = "x64";
const string configuration = isDebugOrRelease ? "Debug" : "Release";
string mark = $"<!--ST.Tools.DesktopBridgeLink({configuration}-{platform})-->";
//const string Mark_CEF_x64 = "<!--CEF(x64)-->";
var src_path = Path.Combine(ProjectPathUtil.projPath, "src");
var bridge_app_path = Path.Combine(ProjectPathUtil.projPath, "src", ProjectPathUtil.ProjectDir_AvaloniaAppBridge);
var bridge_console_path = Path.Combine(ProjectPathUtil.projPath, "src", ProjectPathUtil.ProjectDir_ConsoleAppBridge);
var bridge_app_pack_path = Path.Combine(ProjectPathUtil.projPath, "src", ProjectPathUtil.ProjectDir_ConsoleAppBridgePackage);
if (Directory.Exists(bridge_app_path) && Directory.Exists(bridge_console_path))
{
var pub_path = $@"\bin\{configuration}\Publish\win10-{platform}";
var bridgeProjPath = ProjectPathUtil.projPath + Path.DirectorySeparatorChar + "src" + Path.DirectorySeparatorChar + "ST.Client.Desktop.Avalonia.App.Bridge.Package";
var bridgeProjFilePath = bridgeProjPath + Path.DirectorySeparatorChar + "ST.Client.Desktop.Avalonia.App.Bridge.Package.wapproj";
var csprojContent = File.ReadAllText(bridgeProjFilePath);
var csprojContentLines = csprojContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
StringBuilder s = new();
var index = Array.FindIndex(csprojContentLines, x => x.Trim() == mark);
if (index < 0)
{
Console.WriteLine("Cannot find mark.");
Console.ReadKey();
return;
}
var top = csprojContentLines.Take(index).ToArray();
var bottom = csprojContentLines.Skip(index).ToArray();
index = Array.FindIndex(bottom, x => x.Trim() == "</ItemGroup>");
bottom = bottom.Skip(index + 1).ToArray();
Array.ForEach(top, x => s.AppendLine(x));
s.Append(" ").AppendLine(mark);
var bridge_app_path2 = bridge_app_path + pub_path;
//var bridge_console_path2 = bridge_console_path + pub_path;
if (Directory.Exists(bridge_app_path2)/* && Directory.Exists(bridge_console_path2)*/)
{
s.AppendLine(" <ItemGroup Condition=\"'$(Configuration)|$(Platform)'=='" + configuration + "|" + (platform.StartsWith("arm") ? platform.ToUpper() : platform) + "'\">");
EachDirs(bridge_app_path2, bridge_app_path2);
//EachFiles(bridge_console_path2, Directory.GetFiles(bridge_console_path2, "Steam++.Console*"));
s.AppendLine(" </ItemGroup>");
}
void EachDirs(string rootPath, params string[] dirs)
{
foreach (var dir in dirs)
{
var files = Directory.GetFiles(dir);
EachFiles(rootPath, files);
var dirs_ = Directory.GetDirectories(dir);
var ignoreRootDirNames = new[] { IOPath.DirName_AppData, IOPath.DirName_Cache, "Logs" };
EachDirs(rootPath, dirs_.Where(x => !ignoreRootDirNames.Contains(new DirectoryInfo(x).Name)).ToArray());
}
}
void EachFiles(string rootPath, params string[] files)
{
foreach (var file in files)
{
if (Path.GetExtension(file).Equals(".xml", StringComparison.OrdinalIgnoreCase) ||
Path.GetExtension(file).Equals(".pdb", StringComparison.OrdinalIgnoreCase))
{
continue;
}
var includePath = ".." + file.Substring(src_path.Length, file.Length - src_path.Length);
s.AppendFormat(" <Content Include=\"{0}\">", includePath);
s.AppendLine();
var linkPath = file.Substring(rootPath.Length, file.Length - rootPath.Length).Trim(Path.DirectorySeparatorChar);
s.AppendFormat(" <Link>{0}</Link>", linkPath);
s.AppendLine();
s.AppendLine(" <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>");
s.AppendLine(" </Content>");
}
}
Array.ForEach(bottom, x => s.AppendLine(x));
csprojContent = s.ToString();
File.WriteAllText(bridgeProjFilePath, csprojContent);
Console.WriteLine("OK");
}
#pragma warning restore SA1516 // Elements should be separated by blank line