Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #67

Merged
merged 33 commits into from
Nov 14, 2024
Merged

Dev #67

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d7bee81
feature: 添加单元测试
JusterZhu Sep 3, 2024
e62dcff
refactor: 移除,除core库以外的所有驱动相关代码
JusterZhu Sep 6, 2024
e830f11
feature: add bowl.jpeg
JusterZhu Sep 7, 2024
c438a89
refactor: 重构管道机制
JusterZhu Sep 10, 2024
2b5d8cd
remove: 移除冗余代码
JusterZhu Sep 12, 2024
10d6099
refactor: refactor client core
JusterZhu Sep 20, 2024
aa6eb9b
refactor: refactor Generalupdate.zip
JusterZhu Sep 20, 2024
06c5ed8
refactor: Generalupdate.client
JusterZhu Sep 20, 2024
e400d9f
refactor: refactor generalupdate.upgrad
JusterZhu Sep 20, 2024
94e4729
refactor: refactor generalupdate.common
JusterZhu Sep 20, 2024
85c7a08
refactor: generalupdate.core
JusterZhu Sep 20, 2024
4bdd786
refactor: refactor generalupdate.differential
JusterZhu Sep 20, 2024
ea06802
refactor: generalupdate.upgrad
JusterZhu Sep 20, 2024
7c479c0
Update DriverMiddleware.cs
JusterZhu Sep 21, 2024
cbbd68f
Update GeneralUpdateBootstrap.cs
JusterZhu Sep 21, 2024
cb7ff3f
Update WindowsStrategy.cs
JusterZhu Sep 21, 2024
7dda81e
Update RestoreDriverCommand.cs
JusterZhu Sep 21, 2024
22fb2e1
Create FileExtensions.cs
JusterZhu Sep 22, 2024
0e03e47
拆分黑名单逻辑
JusterZhu Sep 23, 2024
c025d33
Update GeneralUpdateBootstrap.cs
JusterZhu Sep 24, 2024
75dd3e8
Update DifferentialCore.cs
JusterZhu Sep 24, 2024
086622b
Update FileExtensions.cs
JusterZhu Sep 24, 2024
ba8df21
Update GeneralUpdateOSS.cs
JusterZhu Oct 1, 2024
371aa96
Update GeneralUpdateBootstrap.cs
JusterZhu Oct 1, 2024
4e44f0b
Update GeneralClientBootstrap.cs
JusterZhu Oct 1, 2024
99972c3
Update GeneralUpdateOSS.cs
JusterZhu Oct 2, 2024
69a18a6
Update GeneralClientOSS.cs
JusterZhu Oct 3, 2024
2566e73
refactor: Reconstruct the entire structure
JusterZhu Nov 4, 2024
a6d0679
驱动更新实现
JusterZhu Nov 6, 2024
855ce67
调整命名空间
JusterZhu Nov 10, 2024
5e9018c
更新最新C# 语法
JusterZhu Nov 13, 2024
2b8a7d1
添加测试代码
JusterZhu Nov 13, 2024
a64f25c
完善bowl组件
JusterZhu Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added imgs/bowl.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions src/c#/GeneralUpdate.Bowl.Test/GeneralUpdate.Bowl.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/c#/GeneralUpdate.Bowl.Test/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GeneralUpdate.Bowl.Test;

public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
40 changes: 40 additions & 0 deletions src/c#/GeneralUpdate.Bowl/Applications/Windows/export.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@echo off
setlocal

if "%~1"=="" (
echo Please provide the export path as the first parameter.
exit /b 1
)

set exportDir=%~1

if not exist "%exportDir%" (
mkdir "%exportDir%"
)

set outputFile=%exportDir%\driverInfo.txt

:: 导出驱动信息
driverquery /v /fo table > "%outputFile%"
echo %outputFile% Export successfully.

:: 导出系统信息
set systemInfoFile=%exportDir%\systeminfo.txt
systeminfo > "%systemInfoFile%"
echo %systemInfoFile% Export successfully.

:: 获取当前日期
for /f "tokens=1-4 delims=/- " %%i in ('date /t') do (
set yyyy=%%i
set mm=%%j
set dd=%%k
)

:: 设置日志文件名
set logFile=%exportDir%\systemlog.evtx

:: 导出系统日志
wevtutil epl System "%logFile%" /q:"*[System[TimeCreated[timediff(@SystemTime) <= 86400000]]]"
echo %logFile% Export successfully.

endlocal
55 changes: 38 additions & 17 deletions src/c#/GeneralUpdate.Bowl/Bowl.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,60 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.Json;
using GeneralUpdate.Bowl.Strategys;
using GeneralUpdate.Common.Shared.Object;

namespace GeneralUpdate.Bowl;

public class Bowl
/// <summary>
/// Surveillance Main Program.
/// </summary>
public sealed class Bowl
{
private IStrategy _strategy;
private static IStrategy? _strategy;

public Bowl(MonitorParameter parameter = null)
{
CreateStrategy();
_strategy!.SetParameter(parameter);
}
private Bowl() { }

private void CreateStrategy()
private static void CreateStrategy()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
_strategy = new WindowStrategy();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
/*else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
_strategy = new LinuxStrategy();
}
}*/

if (_strategy == null)
throw new PlatformNotSupportedException("Unsupported operating system");
}

public static void Launch(MonitorParameter? monitorParameter = null)
{
monitorParameter ??= CreateParameter();
CreateStrategy();
_strategy?.SetParameter(monitorParameter);
_strategy?.Launch();
}

public Bowl SetParameter(MonitorParameter parameter)
private static MonitorParameter CreateParameter()
{
if(parameter.Verify())
throw new ArgumentException("Parameter contains illegal values");
var json = Environment.GetEnvironmentVariable("ProcessInfo", EnvironmentVariableTarget.User);
if(string.IsNullOrWhiteSpace(json))
throw new ArgumentNullException("ProcessInfo environment variable not set !");

_strategy.SetParameter(parameter);
return this;
var processInfo = JsonSerializer.Deserialize<ProcessInfo>(json);
return new MonitorParameter
{
ProcessNameOrId = processInfo.AppName,
DumpFileName = $"{processInfo.LastVersion}_fail.dmp",
FailFileName = $"{processInfo.LastVersion}_fail.json",
TargetPath = processInfo.InstallPath,
FailDirectory = Path.Combine(processInfo.InstallPath, "fail", processInfo.LastVersion),
BackupDirectory = Path.Combine(processInfo.InstallPath, processInfo.LastVersion),
ExtendedField = processInfo.LastVersion
};
}

public void Launch() => _strategy.Launch();
}
11 changes: 11 additions & 0 deletions src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
<None Update="Applications\Linux\procdump_3.3.0_amd64.deb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Applications\Windows\export.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GeneralUpdate.Common\GeneralUpdate.Common.csproj" />
</ItemGroup>

</Project>
87 changes: 18 additions & 69 deletions src/c#/GeneralUpdate.Bowl/Strategys/AbstractStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using GeneralUpdate.Common.FileBasic;

namespace GeneralUpdate.Bowl.Strategys;

public abstract class AbstractStrategy : IStrategy
{
protected MonitorParameter _parameter;

private readonly IReadOnlyList<string> _sensitiveCharacter = new List<string>
{
"Exit",
"exit"
};
protected List<string> OutputList = new ();

public void SetParameter(MonitorParameter parameter) => _parameter = parameter;

public virtual void Launch()
{
Backup();
Startup(_parameter.ProcessNameOrId, _parameter.InnerArguments);
Startup(_parameter.InnerApp, _parameter.InnerArguments);
}

private void Startup(string appName, string arguments)
{
if (Directory.Exists(_parameter.FailDirectory))
{
Directory.Delete(_parameter.FailDirectory, true);
}
Directory.CreateDirectory(_parameter.FailDirectory);

var startInfo = new ProcessStartInfo
{
FileName = appName,
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
Expand All @@ -35,71 +40,15 @@ private void Startup(string appName, string arguments)
process.OutputDataReceived += OutputHandler;
process.ErrorDataReceived += OutputHandler;
process.Start();
process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit(1000 * 10);
}

private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
var data = outLine.Data;
if (!string.IsNullOrEmpty(data))
{
foreach (var sensitive in _sensitiveCharacter)
{
if (data.Contains(sensitive)){
Restore();
Process.Start(_parameter.ProcessNameOrId, _parameter.Arguments);
break;
}
}
}
OutputList.Add(data);
}

private void Backup()
{
var backupPath = _parameter.Target;
var sourcePath = _parameter.Source;

if (Directory.Exists(backupPath))
{
Directory.Delete(backupPath, true);
}

Directory.CreateDirectory(backupPath);

foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
{
Directory.CreateDirectory(dirPath.Replace(sourcePath, backupPath));
}

foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(sourcePath, backupPath), true);
}
}

private void Restore()
{
var restorePath = _parameter.Target;
var backupPath = _parameter.Source;

if (Directory.Exists(restorePath))
{
Directory.Delete(restorePath, true);
}

Directory.CreateDirectory(restorePath);

foreach (string dirPath in Directory.GetDirectories(backupPath, "*", SearchOption.AllDirectories))
{
Directory.CreateDirectory(dirPath.Replace(backupPath, restorePath));
}

foreach (string newPath in Directory.GetFiles(backupPath, "*.*", SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(backupPath, restorePath), true);
}
}

public void SetParameter(MonitorParameter parameter) => _parameter = parameter;
}
10 changes: 10 additions & 0 deletions src/c#/GeneralUpdate.Bowl/Strategys/Crash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace GeneralUpdate.Bowl.Strategys;

public class Crash
{
public MonitorParameter Parameter { get; set; }

public List<string> ProcdumpOutPutLines { get; set; }
}
28 changes: 14 additions & 14 deletions src/c#/GeneralUpdate.Bowl/Strategys/LinuxStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ namespace GeneralUpdate.Bowl.Strategys;

public class LinuxStrategy : AbstractStrategy
{
/*procdump-3.3.0-0.cm2.x86_64.rpm:
适合系统:此RPM包可能适用于基于CentOS或RHEL的某些派生版本,具体来说是CM2版本。CM2通常指的是ClearOS 7.x或类似的社区维护版本。
procdump-3.3.0-0.el8.x86_64.rpm:
适合系统:此RPM包适用于Red Hat Enterprise Linux 8 (RHEL 8)、CentOS 8及其他基于RHEL 8的发行版。
procdump_3.3.0_amd64.deb:
适合系统:此DEB包适用于Debian及其衍生发行版,如Ubuntu,适用于64位系统(amd64架构)。*/
/*procdump-3.3.0-0.cm2.x86_64.rpm:
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.

procdump-3.3.0-0.el8.x86_64.rpm:
Compatible Systems: This RPM package is suitable for Red Hat Enterprise Linux 8 (RHEL 8), CentOS 8, and other RHEL 8-based distributions.

procdump_3.3.0_amd64.deb:
Compatible Systems: This DEB package is suitable for Debian and its derivatives, such as Ubuntu, for 64-bit systems (amd64 architecture).*/

private IReadOnlyList<string> procdump_amd64 = new List<string> { "Ubuntu", "Debian" };
private IReadOnlyList<string> _rocdumpAmd64 = new List<string> { "Ubuntu", "Debian" };
private IReadOnlyList<string> procdump_el8_x86_64 = new List<string> { "Red Hat", "CentOS", "Fedora" };
private IReadOnlyList<string> procdump_cm2_x86_64 = new List<string> { "ClearOS" };

Expand Down Expand Up @@ -64,9 +66,9 @@ private void Install()

private string GetPacketName()
{
string packageFileName = string.Empty;
LinuxSystem system = GetSystem();
if (procdump_amd64.Contains(system.Name))
var packageFileName = string.Empty;
var system = GetSystem();
if (_rocdumpAmd64.Contains(system.Name))
{
packageFileName = $"procdump_3.3.0_amd64.deb";
}
Expand Down Expand Up @@ -105,9 +107,7 @@ private LinuxSystem GetSystem()

return new LinuxSystem(distro, version);
}
else
{
throw new FileNotFoundException("Cannot determine the Linux distribution. The /etc/os-release file does not exist.");
}

throw new FileNotFoundException("Cannot determine the Linux distribution. The /etc/os-release file does not exist.");
}
}
Loading
Loading