Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/c#/DifferentialTest/DifferentialCoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Moq;
using GeneralUpdate.Differential;
using GeneralUpdate.Core;
using GeneralUpdate.Differential.Abstractions;
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Core.Differential;

namespace DifferentialTest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Core.Differential;

namespace DifferentialTest.Matchers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Moq;
using GeneralUpdate.Core.FileSystem;
using GeneralUpdate.Differential.Abstractions;
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Core.Differential;

namespace DifferentialTest.Matchers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Core.Differential;

namespace DifferentialTest.Matchers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using GeneralUpdate.Core.HashAlgorithms;
using GeneralUpdate.Core.JsonContext;
using GeneralUpdate.Differential.Abstractions;
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Core.Differential;

namespace DifferentialTest.Matchers
{
Expand Down
2 changes: 1 addition & 1 deletion src/c#/DifferentialTest/Models/DiffProgressTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GeneralUpdate.Differential.Models;
using GeneralUpdate.Core.Models;

namespace DifferentialTest.Models
{
Expand Down
6 changes: 3 additions & 3 deletions src/c#/DifferentialTest/Pipeline/DiffPipelineBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Moq;
using GeneralUpdate.Differential.Abstractions;
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Differential.Models;
using GeneralUpdate.Differential.Pipeline;
using GeneralUpdate.Core.Differential;
using GeneralUpdate.Core.Models;
using GeneralUpdate.Core.Pipeline;

namespace DifferentialTest.Pipeline
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.IO.Compression;
using Moq;
using GeneralUpdate.Differential.Abstractions;
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Differential.Models;
using GeneralUpdate.Differential.Pipeline;
using GeneralUpdate.Core.Differential;
using GeneralUpdate.Core.Models;
using GeneralUpdate.Core.Pipeline;

namespace DifferentialTest.Pipeline
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GeneralUpdate.Differential.Pipeline;
using GeneralUpdate.Core.Pipeline;

namespace DifferentialTest.Pipeline
{
Expand Down
6 changes: 3 additions & 3 deletions src/c#/DifferentialTest/Pipeline/DiffPipelineTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Moq;
using GeneralUpdate.Differential.Abstractions;
using GeneralUpdate.Differential.Matchers;
using GeneralUpdate.Differential.Models;
using GeneralUpdate.Differential.Pipeline;
using GeneralUpdate.Core.Differential;
using GeneralUpdate.Core.Models;
using GeneralUpdate.Core.Pipeline;

namespace DifferentialTest.Pipeline
{
Expand Down
13 changes: 5 additions & 8 deletions src/c#/GeneralUpdate.Bowl/Bowl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
using GeneralUpdate.Bowl.Internal;
using GeneralUpdate.Bowl.Strategies;
using GeneralUpdate.Bowl.Strategys;
using GeneralUpdate.Core.FileSystem;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.JsonContext;
using GeneralUpdate.Core;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Bowl.FileSystem;
using GeneralUpdate.Bowl.Configuration;
using GeneralUpdate.Bowl.Ipc;

namespace GeneralUpdate.Bowl;

Expand Down Expand Up @@ -163,7 +161,7 @@
{
GeneralTracer.Info($"Bowl.HandleCrashAsync: restoring backup from " +
$"'{context.BackupDirectory}' to '{context.TargetPath}'.");
StorageManager.Restore(context.BackupDirectory, context.TargetPath);
StorageHelper.Restore(context.BackupDirectory, context.TargetPath);
restored = true;
GeneralTracer.Info("Bowl.HandleCrashAsync: restore completed.");
}
Expand Down Expand Up @@ -288,7 +286,7 @@
/// <summary>
/// Converts legacy <see cref="MonitorParameter"/> to the new <see cref="BowlContext"/>.
/// </summary>
public static BowlContext MapToContext(MonitorParameter p)

Check warning on line 289 in src/c#/GeneralUpdate.Bowl/Bowl.cs

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest)

'MonitorParameter' is obsolete: 'Use BowlContext instead. Will be removed in v10.'
{
return new BowlContext
{
Expand All @@ -310,7 +308,7 @@
/// Reads <c>ProcessInfo</c> environment variable and builds a legacy <see cref="MonitorParameter"/>.
/// Shared with the legacy static API for backward compatibility.
/// </summary>
internal static MonitorParameter CreateParameter()

Check warning on line 311 in src/c#/GeneralUpdate.Bowl/Bowl.cs

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest)

'MonitorParameter' is obsolete: 'Use BowlContext instead. Will be removed in v10.'
{
GeneralTracer.Info("Bowl.CreateParameter: reading ProcessInfo from environment variable.");

Expand All @@ -322,8 +320,7 @@
"ProcessInfo environment variable not set.");
}

var processInfo = JsonSerializer.Deserialize<ProcessInfo>(
json, ProcessInfoJsonContext.Default.ProcessInfo);
var processInfo = JsonSerializer.Deserialize<ProcessInfo>(json);
if (processInfo == null)
{
GeneralTracer.Fatal("Bowl.CreateParameter: failed to deserialize ProcessInfo JSON.");
Expand Down
18 changes: 18 additions & 0 deletions src/c#/GeneralUpdate.Bowl/Configuration/ProcessInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace GeneralUpdate.Bowl.Configuration;

/// <summary>
/// Minimal ProcessInfo for Bowl — only the fields needed for crash monitoring and rollback.
/// </summary>
public class ProcessInfo
{
[JsonPropertyName("AppName")]
public string AppName { get; set; } = string.Empty;

[JsonPropertyName("InstallPath")]
public string InstallPath { get; set; } = string.Empty;

[JsonPropertyName("LastVersion")]
public string LastVersion { get; set; } = string.Empty;
}
62 changes: 62 additions & 0 deletions src/c#/GeneralUpdate.Bowl/FileSystem/StorageHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.IO;
using System.Text.Json;

namespace GeneralUpdate.Bowl.FileSystem;

/// <summary>
/// Minimal file system utilities for Bowl (backup restore, directory cleanup, JSON serialization).
/// </summary>
public static class StorageHelper
{
public static void Restore(string backupPath, string sourcePath)
{
if (!Directory.Exists(sourcePath))
Directory.CreateDirectory(sourcePath);
CopyDirectory(backupPath, sourcePath);
}

private static void CopyDirectory(string sourceDir, string targetDir)
{
foreach (string dirPath in Directory.GetDirectories(sourceDir, "*", SearchOption.TopDirectoryOnly))
{
string newTargetDir = Path.Combine(targetDir, Path.GetFileName(dirPath));
Directory.CreateDirectory(newTargetDir);
CopyDirectory(dirPath, newTargetDir);
}

foreach (string filePath in Directory.GetFiles(sourceDir, "*.*", SearchOption.TopDirectoryOnly))
{
string newFilePath = Path.Combine(targetDir, Path.GetFileName(filePath));
File.Copy(filePath, newFilePath, true);
}
}

public static void DeleteDirectory(string targetDir)
{
foreach (var file in Directory.GetFiles(targetDir))
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}

foreach (var dir in Directory.GetDirectories(targetDir))
{
DeleteDirectory(dir);
}

Directory.Delete(targetDir, false);
}

public static void CreateJson<T>(string targetPath, T obj) where T : class
{
var folderPath = Path.GetDirectoryName(targetPath) ??
throw new ArgumentException("invalid path", nameof(targetPath));

if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);

var jsonString = JsonSerializer.Serialize(obj);
File.WriteAllText(targetPath, jsonString);
}
}
4 changes: 0 additions & 4 deletions src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="10.0.1" />
<PackageReference Include="System.Text.Json" Version="10.0.1" />
Expand Down
6 changes: 3 additions & 3 deletions src/c#/GeneralUpdate.Bowl/Internal/CrashReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Core.FileSystem;
using GeneralUpdate.Core;
using GeneralUpdate.Bowl.FileSystem;
using GeneralUpdate.Bowl;

namespace GeneralUpdate.Bowl.Internal;

Expand Down Expand Up @@ -38,7 +38,7 @@ public Task<string> GenerateReportAsync(
};

var failJsonPath = Path.Combine(context.FailDirectory, context.FailFileName);
StorageManager.CreateJson(failJsonPath, crash, CrashJsonContext.Default.Crash);
StorageHelper.CreateJson(failJsonPath, crash);

GeneralTracer.Info($"CrashReporter.GenerateReportAsync: report written to {failJsonPath}.");
return Task.FromResult(failJsonPath);
Expand Down
3 changes: 2 additions & 1 deletion src/c#/GeneralUpdate.Bowl/Internal/EnvironmentProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Bowl.Configuration;
using GeneralUpdate.Bowl.Ipc;

namespace GeneralUpdate.Bowl.Internal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Core;
using GeneralUpdate.Bowl;

namespace GeneralUpdate.Bowl.Internal;

Expand Down
41 changes: 41 additions & 0 deletions src/c#/GeneralUpdate.Bowl/Ipc/Environments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace GeneralUpdate.Bowl.Ipc;

/// <summary>
/// Secure IPC environment variable provider.
/// AES-encrypted temp files in a dedicated subdirectory, auto-deleted after read.
/// </summary>
public static class Environments
{
private static readonly byte[] _aesKey = SHA256.Create()
.ComputeHash(Encoding.UTF8.GetBytes("GeneralUpdate.IPC.EnvironmentProvider.v1"));
private static readonly byte[] _aesIV = new byte[16] { 0x47, 0x55, 0x50, 0x44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

private static string IpcDir
{
get
{
var dir = Path.Combine(Path.GetTempPath(), "GeneralUpdate", "ipc");
Directory.CreateDirectory(dir);
return dir;
}
}

public static void SetEnvironmentVariable(string key, string value)
{
var filePath = Path.Combine(IpcDir, $"{key}.enc");
var plainBytes = Encoding.UTF8.GetBytes(value);
IpcEncryption.EncryptToFile(plainBytes, filePath, _aesKey, _aesIV);
}
Comment on lines +14 to +33
Comment on lines +28 to +33

public static string GetEnvironmentVariable(string key)
{
var filePath = Path.Combine(Path.GetTempPath(), "GeneralUpdate", "ipc", $"{key}.enc");
var plainBytes = IpcEncryption.DecryptFromFile(filePath, _aesKey, _aesIV);
return plainBytes != null ? Encoding.UTF8.GetString(plainBytes) : string.Empty;
}
}
40 changes: 40 additions & 0 deletions src/c#/GeneralUpdate.Bowl/Ipc/IpcEncryption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.IO;
using System.Security.Cryptography;

namespace GeneralUpdate.Bowl.Ipc;

/// <summary>
/// Shared AES encryption utilities for IPC.
/// </summary>
public static class IpcEncryption
{
public static void EncryptToFile(byte[] plainBytes, string filePath, byte[] key, byte[] iv)
{
using var aes = Aes.Create();
aes.Key = key;
aes.IV = iv;
using var encryptor = aes.CreateEncryptor();
var cipher = encryptor.TransformFinalBlock(plainBytes, 0, plainBytes.Length);
File.WriteAllBytes(filePath, cipher);
}

public static byte[]? DecryptFromFile(string filePath, byte[] key, byte[] iv)
{
if (!File.Exists(filePath)) return null;

try
{
var cipher = File.ReadAllBytes(filePath);
using var aes = Aes.Create();
aes.Key = key;
aes.IV = iv;
using var decryptor = aes.CreateDecryptor();
return decryptor.TransformFinalBlock(cipher, 0, cipher.Length);
}
finally
{
try { File.Delete(filePath); } catch { /* best-effort cleanup */ }
}
}
Comment on lines +22 to +39
}
2 changes: 1 addition & 1 deletion src/c#/GeneralUpdate.Bowl/Strategies/LinuxBowlStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Bowl.Internal;
using GeneralUpdate.Core;
using GeneralUpdate.Bowl;

namespace GeneralUpdate.Bowl.Strategies;

Expand Down
2 changes: 1 addition & 1 deletion src/c#/GeneralUpdate.Bowl/Strategies/MacBowlStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Core;
using GeneralUpdate.Bowl;

namespace GeneralUpdate.Bowl.Strategies;

Expand Down
2 changes: 1 addition & 1 deletion src/c#/GeneralUpdate.Bowl/Strategies/ProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Core;
using GeneralUpdate.Bowl;

namespace GeneralUpdate.Bowl.Strategies;

Expand Down
6 changes: 3 additions & 3 deletions src/c#/GeneralUpdate.Bowl/Strategies/WindowsBowlStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Core.FileSystem;
using GeneralUpdate.Core;
using GeneralUpdate.Bowl.FileSystem;
using GeneralUpdate.Bowl;

namespace GeneralUpdate.Bowl.Strategies;

Expand Down Expand Up @@ -64,7 +64,7 @@ public Task PostProcessAsync(in BowlContext context,
private static void EnsureDirectory(string path)
{
if (Directory.Exists(path))
StorageManager.DeleteDirectory(path);
StorageHelper.DeleteDirectory(path);
Directory.CreateDirectory(path);
}
}
Loading
Loading