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
26 changes: 2 additions & 24 deletions src/Models/SimulateConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,16 @@ namespace GeneralUpdate.Tools.Models;
public record PlatformItem(int Value, string DisplayName) { public override string ToString() => DisplayName; }
public record AppTypeItem(int Value, string DisplayName) { public override string ToString() => DisplayName; }

/// <summary>
/// Configuration for the simulate-update module.
/// </summary>
public partial class SimulateConfigModel : ObservableObject
{
/// <summary>User-provided old-version app directory to test against.</summary>
[ObservableProperty] private string _appDirectory = string.Empty;

/// <summary>Path to a patch .zip generated by the Patch module.</summary>
[ObservableProperty] private string _patchFilePath = string.Empty;

/// <summary>The current version of the app being tested.</summary>
[ObservableProperty] private string _currentVersion = "1.0.0.0";

/// <summary>The target version the patch upgrades to.</summary>
[ObservableProperty] private string _targetVersion = "2.0.0.0";

/// <summary>Platform selector.</summary>
[ObservableProperty] private PlatformItem _platform = new(1, "Windows");

/// <summary>AppType selector.</summary>
[ObservableProperty] private AppTypeItem _appType = new(1, "ClientApp");

/// <summary>Application secret key for the update API.</summary>
[ObservableProperty] private int _platform = 1;
[ObservableProperty] private int _appType = 1;
[ObservableProperty] private string _appSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6";

/// <summary>Product identifier.</summary>
[ObservableProperty] private string _productId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a";

/// <summary>Directory where client.cs / upgrade.cs and server are generated.</summary>
[ObservableProperty] private string _outputDirectory = string.Empty;

/// <summary>Server port assigned at runtime (set by SimulationService).</summary>
public int ServerPort { get; set; } = 5000;
}
4 changes: 2 additions & 2 deletions src/Services/ReportGeneratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public async Task<string> GenerateAsync(
sb.AppendLine("|-------|-------|");
sb.AppendLine($"| Patch | {EscapeMd(config.PatchFilePath)} |");
sb.AppendLine($"| App Directory | {EscapeMd(config.AppDirectory)} |");
sb.AppendLine($"| Platform | {config.Platform.DisplayName} |");
sb.AppendLine($"| AppType | {config.AppType.DisplayName} |");
sb.AppendLine($"| Platform | {config.Platform} |");
sb.AppendLine($"| AppType | {config.AppType} |");
sb.AppendLine($"| Version | {config.CurrentVersion} → {config.TargetVersion} |");
sb.AppendLine($"| Server Port | {config.ServerPort} |");
sb.AppendLine($"| Simulation Time | {DateTime.Now:yyyy-MM-dd HH:mm:ss} |");
Expand Down
2 changes: 1 addition & 1 deletion src/Services/SimulationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<SimulationResult> RunAsync(

var hash = ComputeQuickHash(patchDest);
LocalUpdateServerFiles.Register(patchName, patchDest);
_server.Updates.Add((config.CurrentVersion, config.TargetVersion, hash, patchDest, config.AppType.Value));
_server.Updates.Add((config.CurrentVersion, config.TargetVersion, hash, patchDest, config.AppType));

await _server.StartAsync(config.ServerPort);
Log($" Server running on {_server.BaseUrl}", progress);
Expand Down
24 changes: 21 additions & 3 deletions src/ViewModels/SimulateViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
Expand Down Expand Up @@ -36,8 +37,26 @@ public partial class SimulateViewModel : ViewModelBase
public SimulateViewModel()
{
_status = _loc["Patch.Ready"];
Config.Platform = Platforms[0];
Config.AppType = AppTypes[0];
}

/// <summary>
/// Maps Config.Platform (int) to Platforms collection index.
/// 1 (Windows) → 0, 2 (Linux) → 1.
/// </summary>
public int PlatformIndex
{
get => Config.Platform == 2 ? 1 : 0;
set => Config.Platform = value == 1 ? 2 : 1;
}

/// <summary>
/// Maps Config.AppType (int) to AppTypes collection index.
/// 1 (ClientApp) → 0, 2 (UpgradeApp) → 1.
/// </summary>
public int AppTypeIndex
{
get => Config.AppType == 2 ? 1 : 0;
set => Config.AppType = value == 1 ? 2 : 1;
}

async Task<string?> PickFolder(string title)
Expand Down Expand Up @@ -87,7 +106,6 @@ async Task StartSimulation()
foreach (var note in result.Notes)
L($" Note: {note}");

// Generate report
var reportPath = await _report.GenerateAsync(Config, result, Config.OutputDirectory);
L($"Report: {reportPath}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Views/SimulateView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
<Grid ColumnDefinitions="Auto,*,Auto,*">
<TextBlock Grid.Column="0" Text="Platform" VerticalAlignment="Center"/>
<ComboBox Grid.Column="1" ItemsSource="{Binding Platforms}"
SelectedItem="{Binding Config.Platform}" Margin="8,0,16,0"/>
SelectedIndex="{Binding PlatformIndex}" Margin="8,0,16,0"/>
<TextBlock Grid.Column="2" Text="AppType" VerticalAlignment="Center"/>
<ComboBox Grid.Column="3" ItemsSource="{Binding AppTypes}"
SelectedItem="{Binding Config.AppType}" Margin="8,0"/>
SelectedIndex="{Binding AppTypeIndex}" Margin="8,0"/>
</Grid>
<Grid ColumnDefinitions="Auto,*,Auto,*">
<TextBlock Grid.Column="0" Text="AppSecret" VerticalAlignment="Center"/>
Expand Down
Loading