Skip to content

Commit d504726

Browse files
committed
feature: 新增bowl组件
1 parent 9ab7561 commit d504726

16 files changed

+404
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# 检查是否提供了参数
4+
if [ "$#" -ne 1 ]; then
5+
echo "Usage: install_package.sh <package-file>"
6+
exit 1
7+
fi
8+
9+
PACKAGE_FILE=\$1
10+
11+
# 检查文件类型并安装
12+
if [[ "$PACKAGE_FILE" == *.rpm ]]; then
13+
if command -v rpm &> /dev/null; then
14+
sudo rpm -ivh "$PACKAGE_FILE"
15+
elif command -v dnf &> /dev/null; then
16+
sudo dnf install -y "$PACKAGE_FILE"
17+
elif command -v yum &> /dev/null; then
18+
sudo yum install -y "$PACKAGE_FILE"
19+
else
20+
echo "RPM package manager not found."
21+
exit 1
22+
fi
23+
elif [[ "$PACKAGE_FILE" == *.deb ]]; then
24+
if command -v dpkg &> /dev/null; then
25+
sudo dpkg -i "$PACKAGE_FILE"
26+
sudo apt-get install -f -y # 修复依赖问题
27+
else
28+
echo "DEB package manager not found."
29+
exit 1
30+
fi
31+
else
32+
echo "Unsupported package format."
33+
exit 1
34+
fi
35+
36+
echo "Installation of $PACKAGE_FILE completed."
Binary file not shown.
Binary file not shown.
Binary file not shown.
773 KB
Binary file not shown.
415 KB
Binary file not shown.
398 KB
Binary file not shown.

src/c#/GeneralUpdate.Bowl/Bowl.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using GeneralUpdate.Bowl.Strategys;
4+
5+
namespace GeneralUpdate.Bowl;
6+
7+
public class Bowl
8+
{
9+
private IStrategy _strategy;
10+
11+
public Bowl(MonitorParameter parameter = null)
12+
{
13+
CreateStrategy();
14+
_strategy!.SetParameter(parameter);
15+
}
16+
17+
private void CreateStrategy()
18+
{
19+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
20+
{
21+
_strategy = new WindowStrategy();
22+
}
23+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
24+
{
25+
_strategy = new LinuxStrategy();
26+
}
27+
}
28+
29+
public Bowl SetParameter(MonitorParameter parameter)
30+
{
31+
if(parameter.Verify())
32+
throw new ArgumentException("Parameter contains illegal values");
33+
34+
_strategy.SetParameter(parameter);
35+
return this;
36+
}
37+
38+
public void Launch() => _strategy.Launch();
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>12</LangVersion>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<None Update="Applications\Windows\procdump.exe">
11+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
12+
</None>
13+
<None Update="Applications\Windows\procdump64.exe">
14+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
15+
</None>
16+
<None Update="Applications\Windows\procdump64a.exe">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Applications\Linux\procdump-3.3.0-0.cm2.x86_64.rpm">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Applications\Linux\procdump-3.3.0-0.el8.x86_64.rpm">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</None>
25+
<None Update="Applications\Linux\procdump_3.3.0_amd64.deb">
26+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27+
</None>
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
3+
using System.IO;
4+
5+
namespace GeneralUpdate.Bowl.Strategys;
6+
7+
public abstract class AbstractStrategy : IStrategy
8+
{
9+
protected MonitorParameter _parameter;
10+
11+
private readonly IReadOnlyList<string> _sensitiveCharacter = new List<string>
12+
{
13+
"Exit",
14+
"exit"
15+
};
16+
17+
public virtual void Launch()
18+
{
19+
Backup();
20+
Startup(_parameter.ProcessNameOrId, _parameter.InnerArguments);
21+
}
22+
23+
private void Startup(string appName, string arguments)
24+
{
25+
var startInfo = new ProcessStartInfo
26+
{
27+
FileName = appName,
28+
Arguments = arguments,
29+
RedirectStandardOutput = true,
30+
UseShellExecute = false,
31+
CreateNoWindow = true
32+
};
33+
34+
var process = new Process { StartInfo = startInfo };
35+
process.OutputDataReceived += OutputHandler;
36+
process.ErrorDataReceived += OutputHandler;
37+
process.Start();
38+
process.StandardOutput.ReadToEnd();
39+
process.WaitForExit();
40+
}
41+
42+
private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
43+
{
44+
var data = outLine.Data;
45+
if (!string.IsNullOrEmpty(data))
46+
{
47+
foreach (var sensitive in _sensitiveCharacter)
48+
{
49+
if (data.Contains(sensitive)){
50+
Restore();
51+
Process.Start(_parameter.ProcessNameOrId, _parameter.Arguments);
52+
break;
53+
}
54+
}
55+
}
56+
}
57+
58+
private void Backup()
59+
{
60+
var backupPath = _parameter.Target;
61+
var sourcePath = _parameter.Source;
62+
63+
if (Directory.Exists(backupPath))
64+
{
65+
Directory.Delete(backupPath, true);
66+
}
67+
68+
Directory.CreateDirectory(backupPath);
69+
70+
foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
71+
{
72+
Directory.CreateDirectory(dirPath.Replace(sourcePath, backupPath));
73+
}
74+
75+
foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories))
76+
{
77+
File.Copy(newPath, newPath.Replace(sourcePath, backupPath), true);
78+
}
79+
}
80+
81+
private void Restore()
82+
{
83+
var restorePath = _parameter.Target;
84+
var backupPath = _parameter.Source;
85+
86+
if (Directory.Exists(restorePath))
87+
{
88+
Directory.Delete(restorePath, true);
89+
}
90+
91+
Directory.CreateDirectory(restorePath);
92+
93+
foreach (string dirPath in Directory.GetDirectories(backupPath, "*", SearchOption.AllDirectories))
94+
{
95+
Directory.CreateDirectory(dirPath.Replace(backupPath, restorePath));
96+
}
97+
98+
foreach (string newPath in Directory.GetFiles(backupPath, "*.*", SearchOption.AllDirectories))
99+
{
100+
File.Copy(newPath, newPath.Replace(backupPath, restorePath), true);
101+
}
102+
}
103+
104+
public void SetParameter(MonitorParameter parameter) => _parameter = parameter;
105+
}

0 commit comments

Comments
 (0)