Skip to content

Commit 8447385

Browse files
authored
Merge pull request #68 from GeneralLibrary/dev
Dev
2 parents a42bdc8 + fff595a commit 8447385

File tree

252 files changed

+3746
-8969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+3746
-8969
lines changed

imgs/bowl.jpeg

100 KB
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@echo off
2+
setlocal
3+
4+
if "%~1"=="" (
5+
echo Please provide the export path as the first parameter.
6+
exit /b 1
7+
)
8+
9+
set exportDir=%~1
10+
11+
if not exist "%exportDir%" (
12+
mkdir "%exportDir%"
13+
)
14+
15+
set outputFile=%exportDir%\driverInfo.txt
16+
17+
:: 导出驱动信息
18+
driverquery /v /fo table > "%outputFile%"
19+
echo %outputFile% Export successfully.
20+
21+
:: 导出系统信息
22+
set systemInfoFile=%exportDir%\systeminfo.txt
23+
systeminfo > "%systemInfoFile%"
24+
echo %systemInfoFile% Export successfully.
25+
26+
:: 获取当前日期
27+
for /f "tokens=1-4 delims=/- " %%i in ('date /t') do (
28+
set yyyy=%%i
29+
set mm=%%j
30+
set dd=%%k
31+
)
32+
33+
:: 设置日志文件名
34+
set logFile=%exportDir%\systemlog.evtx
35+
36+
:: 导出系统日志
37+
wevtutil epl System "%logFile%" /q:"*[System[TimeCreated[timediff(@SystemTime) <= 86400000]]]"
38+
echo %logFile% Export successfully.
39+
40+
endlocal

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

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,64 @@
11
using System;
2+
using System.IO;
23
using System.Runtime.InteropServices;
4+
using System.Text.Json;
35
using GeneralUpdate.Bowl.Strategys;
6+
using GeneralUpdate.Common.AOT.JsonContext;
7+
using GeneralUpdate.Common.Shared.Object;
48

59
namespace GeneralUpdate.Bowl;
610

7-
public class Bowl
11+
/// <summary>
12+
/// Surveillance Main Program.
13+
/// </summary>
14+
public sealed class Bowl
815
{
9-
private IStrategy _strategy;
16+
private static IStrategy? _strategy;
1017

11-
public Bowl(MonitorParameter parameter = null)
12-
{
13-
CreateStrategy();
14-
_strategy!.SetParameter(parameter);
15-
}
18+
private Bowl() { }
1619

17-
private void CreateStrategy()
20+
private static void CreateStrategy()
1821
{
1922
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2023
{
2124
_strategy = new WindowStrategy();
2225
}
23-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
26+
/*else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
2427
{
2528
_strategy = new LinuxStrategy();
26-
}
29+
}*/
30+
31+
if (_strategy == null)
32+
throw new PlatformNotSupportedException("Unsupported operating system");
33+
}
34+
35+
public static void Launch(MonitorParameter? monitorParameter = null)
36+
{
37+
monitorParameter ??= CreateParameter();
38+
CreateStrategy();
39+
_strategy?.SetParameter(monitorParameter);
40+
_strategy?.Launch();
2741
}
2842

29-
public Bowl SetParameter(MonitorParameter parameter)
43+
private static MonitorParameter CreateParameter()
3044
{
31-
if(parameter.Verify())
32-
throw new ArgumentException("Parameter contains illegal values");
45+
var json = Environment.GetEnvironmentVariable("ProcessInfo", EnvironmentVariableTarget.User);
46+
if(string.IsNullOrWhiteSpace(json))
47+
throw new ArgumentNullException("ProcessInfo environment variable not set !");
48+
49+
var processInfo = JsonSerializer.Deserialize<ProcessInfo>(json, ProcessInfoJsonContext.Default.ProcessInfo);
50+
if(processInfo == null)
51+
throw new ArgumentNullException("ProcessInfo json deserialize fail!");
3352

34-
_strategy.SetParameter(parameter);
35-
return this;
53+
return new MonitorParameter
54+
{
55+
ProcessNameOrId = processInfo.AppName,
56+
DumpFileName = $"{processInfo.LastVersion}_fail.dmp",
57+
FailFileName = $"{processInfo.LastVersion}_fail.json",
58+
TargetPath = processInfo.InstallPath,
59+
FailDirectory = Path.Combine(processInfo.InstallPath, "fail", processInfo.LastVersion),
60+
BackupDirectory = Path.Combine(processInfo.InstallPath, processInfo.LastVersion),
61+
ExtendedField = processInfo.LastVersion
62+
};
3663
}
37-
38-
public void Launch() => _strategy.Launch();
3964
}

src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
<None Update="Applications\Linux\procdump_3.3.0_amd64.deb">
2626
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2727
</None>
28+
<None Update="Applications\Windows\export.bat">
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
</None>
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<PackageReference Include="System.Text.Json" Version="9.0.0" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<ProjectReference Include="..\GeneralUpdate.Common\GeneralUpdate.Common.csproj" />
2839
</ItemGroup>
2940

3041
</Project>
Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.IO;
5+
using GeneralUpdate.Common.FileBasic;
46

57
namespace GeneralUpdate.Bowl.Strategys;
68

79
public abstract class AbstractStrategy : IStrategy
810
{
911
protected MonitorParameter _parameter;
10-
11-
private readonly IReadOnlyList<string> _sensitiveCharacter = new List<string>
12-
{
13-
"Exit",
14-
"exit"
15-
};
12+
protected List<string> OutputList = new ();
13+
14+
public void SetParameter(MonitorParameter parameter) => _parameter = parameter;
1615

1716
public virtual void Launch()
1817
{
19-
Backup();
20-
Startup(_parameter.ProcessNameOrId, _parameter.InnerArguments);
18+
Startup(_parameter.InnerApp, _parameter.InnerArguments);
2119
}
2220

2321
private void Startup(string appName, string arguments)
2422
{
23+
if (Directory.Exists(_parameter.FailDirectory))
24+
{
25+
Directory.Delete(_parameter.FailDirectory, true);
26+
}
27+
Directory.CreateDirectory(_parameter.FailDirectory);
28+
2529
var startInfo = new ProcessStartInfo
2630
{
2731
FileName = appName,
2832
Arguments = arguments,
2933
RedirectStandardOutput = true,
34+
RedirectStandardError = true,
3035
UseShellExecute = false,
3136
CreateNoWindow = true
3237
};
@@ -35,71 +40,15 @@ private void Startup(string appName, string arguments)
3540
process.OutputDataReceived += OutputHandler;
3641
process.ErrorDataReceived += OutputHandler;
3742
process.Start();
38-
process.StandardOutput.ReadToEnd();
39-
process.WaitForExit();
43+
process.BeginOutputReadLine();
44+
process.BeginErrorReadLine();
45+
process.WaitForExit(1000 * 10);
4046
}
4147

4248
private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
4349
{
4450
var data = outLine.Data;
4551
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-
}
52+
OutputList.Add(data);
5653
}
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;
10554
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace GeneralUpdate.Bowl.Strategys;
4+
5+
public class Crash
6+
{
7+
public MonitorParameter Parameter { get; set; }
8+
9+
public List<string> ProcdumpOutPutLines { get; set; }
10+
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ namespace GeneralUpdate.Bowl.Strategys;
88

99
public class LinuxStrategy : AbstractStrategy
1010
{
11-
/*procdump-3.3.0-0.cm2.x86_64.rpm:
12-
适合系统:此RPM包可能适用于基于CentOS或RHEL的某些派生版本,具体来说是CM2版本。CM2通常指的是ClearOS 7.x或类似的社区维护版本。
13-
procdump-3.3.0-0.el8.x86_64.rpm:
14-
适合系统:此RPM包适用于Red Hat Enterprise Linux 8 (RHEL 8)、CentOS 8及其他基于RHEL 8的发行版。
15-
procdump_3.3.0_amd64.deb:
16-
适合系统:此DEB包适用于Debian及其衍生发行版,如Ubuntu,适用于64位系统(amd64架构)。*/
11+
/*procdump-3.3.0-0.cm2.x86_64.rpm:
12+
Compatible Systems: This RPM package may be suitable for certain CentOS or RHEL-based derivatives, specifically the CM2 version. CM2 typically refers to ClearOS 7.x or similar community-maintained versions.
13+
14+
procdump-3.3.0-0.el8.x86_64.rpm:
15+
Compatible Systems: This RPM package is suitable for Red Hat Enterprise Linux 8 (RHEL 8), CentOS 8, and other RHEL 8-based distributions.
16+
17+
procdump_3.3.0_amd64.deb:
18+
Compatible Systems: This DEB package is suitable for Debian and its derivatives, such as Ubuntu, for 64-bit systems (amd64 architecture).*/
1719

18-
private IReadOnlyList<string> procdump_amd64 = new List<string> { "Ubuntu", "Debian" };
20+
private IReadOnlyList<string> _rocdumpAmd64 = new List<string> { "Ubuntu", "Debian" };
1921
private IReadOnlyList<string> procdump_el8_x86_64 = new List<string> { "Red Hat", "CentOS", "Fedora" };
2022
private IReadOnlyList<string> procdump_cm2_x86_64 = new List<string> { "ClearOS" };
2123

@@ -64,9 +66,9 @@ private void Install()
6466

6567
private string GetPacketName()
6668
{
67-
string packageFileName = string.Empty;
68-
LinuxSystem system = GetSystem();
69-
if (procdump_amd64.Contains(system.Name))
69+
var packageFileName = string.Empty;
70+
var system = GetSystem();
71+
if (_rocdumpAmd64.Contains(system.Name))
7072
{
7173
packageFileName = $"procdump_3.3.0_amd64.deb";
7274
}
@@ -105,9 +107,7 @@ private LinuxSystem GetSystem()
105107

106108
return new LinuxSystem(distro, version);
107109
}
108-
else
109-
{
110-
throw new FileNotFoundException("Cannot determine the Linux distribution. The /etc/os-release file does not exist.");
111-
}
110+
111+
throw new FileNotFoundException("Cannot determine the Linux distribution. The /etc/os-release file does not exist.");
112112
}
113113
}

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22

33
public class MonitorParameter
44
{
5-
public string Target { get; set; }
6-
7-
public string Source { get; set; }
5+
public MonitorParameter() { }
86

9-
public string ProcessNameOrId { get; set; }
7+
public string TargetPath { get; set; }
108

11-
public string DumpPath { get; set; }
9+
public string FailDirectory { get; set; }
1210

11+
public string BackupDirectory { get; set; }
12+
13+
public string ProcessNameOrId { get; set; }
14+
1315
public string DumpFileName { get; set; }
1416

15-
public string Arguments { get; set; }
17+
public string FailFileName { get; set; }
1618

17-
internal string InnerArguments => $"-e -ma {ProcessNameOrId} {DumpPath}";
19+
internal string InnerArguments { get; set; }
1820

19-
internal string InnerAppName { get; set; }
20-
21-
public bool Verify()
22-
{
23-
return string.IsNullOrEmpty(Target) &&
24-
string.IsNullOrEmpty(Source) &&
25-
string.IsNullOrEmpty(ProcessNameOrId) &&
26-
string.IsNullOrEmpty(DumpPath) &&
27-
string.IsNullOrEmpty(DumpFileName) &&
28-
string.IsNullOrEmpty(Arguments);
29-
}
21+
internal string InnerApp { get; set; }
22+
23+
/// <summary>
24+
/// Upgrade: upgrade mode. This mode is primarily used in conjunction with GeneralUpdate for internal use. Please do not modify it arbitrarily when the default mode is activated.
25+
/// Normal: Normal mode,This mode can be used independently to monitor a single program. If the program crashes, it will export the crash information.
26+
/// </summary>
27+
public string WorkModel { get; set; } = "Upgrade";
28+
29+
public string ExtendedField { get; set; }
3030
}

0 commit comments

Comments
 (0)