Skip to content

Commit b6136ac

Browse files
authored
refactor: remove OutputDirectory, run simulation entirely in AppDirectory (#68)
All simulation files (Client.exe, Upgrade.exe, .server, report) now land in AppDirectory. No separate output directory needed. This completes the simulation-in-place workflow: the entire update process happens inside the old app directory.
1 parent 75d2320 commit b6136ac

4 files changed

Lines changed: 10 additions & 31 deletions

File tree

src/Models/SimulateConfigModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ public partial class SimulateConfigModel : ObservableObject
1515
[ObservableProperty] private int _appType = 1;
1616
[ObservableProperty] private string _appSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6";
1717
[ObservableProperty] private string _productId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a";
18-
[ObservableProperty] private string _outputDirectory = string.Empty;
1918
public int ServerPort { get; set; } = 5000;
2019
}

src/Services/SimulationService.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public async Task<SimulationResult> RunAsync(
3030
Log("STEP 1: Validating inputs", progress);
3131
Validate(config);
3232

33-
// 2. Prepare output
34-
Log($"STEP 2: Preparing {config.OutputDirectory}", progress);
35-
Directory.CreateDirectory(config.OutputDirectory);
33+
// 2. Prepare app directory
34+
Log($"STEP 2: Preparing {config.AppDirectory}", progress);
35+
Directory.CreateDirectory(config.AppDirectory);
3636

3737
// 3. Compile test apps to .exe
3838
Log("STEP 3: Compiling test apps", progress);
@@ -60,18 +60,17 @@ public async Task<SimulationResult> RunAsync(
6060
await DotNetPublishAsync(upgradeProj, exeDir);
6161
Log($" Upgrade.exe → {exeDir}", progress);
6262

63-
// Copy to simulation output AND install path (GeneralUpdate StartApp looks here)
64-
var clientDest = Path.Combine(config.OutputDirectory, "Client.exe");
63+
// Copy compiled apps into app directory (where the update will run)
64+
var clientDest = Path.Combine(config.AppDirectory, "Client.exe");
6565
File.Copy(Path.Combine(exeDir, "ClientSample.exe"), clientDest, true);
6666

6767
var upgradeExe = Path.Combine(exeDir, "UpgradeSample.exe");
68-
File.Copy(upgradeExe, Path.Combine(config.OutputDirectory, "Upgrade.exe"), true);
6968
File.Copy(upgradeExe, Path.Combine(config.AppDirectory, "Upgrade.exe"), true);
7069
Log($" Upgrade.exe → {config.AppDirectory}", progress);
7170

7271
// 4. Start server
7372
Log("STEP 4: Starting local server", progress);
74-
var serverPatchDir = Path.Combine(config.OutputDirectory, ".server");
73+
var serverPatchDir = Path.Combine(config.AppDirectory, ".server");
7574
Directory.CreateDirectory(serverPatchDir);
7675
var patchName = Path.GetFileName(config.PatchFilePath);
7776
var patchDest = Path.Combine(serverPatchDir, patchName);
@@ -87,11 +86,11 @@ public async Task<SimulationResult> RunAsync(
8786

8887
// 5. Run client
8988
Log("STEP 5: Running Client.exe", progress);
90-
var clientExe = Path.Combine(config.OutputDirectory, "Client.exe");
89+
var clientExe = Path.Combine(config.AppDirectory, "Client.exe");
9190
var clientArgs = new List<string>
9291
{
9392
"--server-url", _server.BaseUrl,
94-
"--install-path", config.OutputDirectory,
93+
"--install-path", config.AppDirectory,
9594
"--current-version", config.CurrentVersion,
9695
"--app-secret", config.AppSecretKey,
9796
"--product-id", config.ProductId,
@@ -160,8 +159,6 @@ private void Validate(SimulateConfigModel config)
160159
throw new DirectoryNotFoundException($"App directory not found: {config.AppDirectory}");
161160
if (!File.Exists(config.PatchFilePath))
162161
throw new FileNotFoundException($"Patch file not found: {config.PatchFilePath}");
163-
if (string.IsNullOrWhiteSpace(config.OutputDirectory))
164-
throw new ArgumentException("Output directory is required");
165162
try
166163
{
167164
var psi = new ProcessStartInfo("dotnet", "--version") { RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true };

src/ViewModels/SimulateViewModel.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,12 @@ public int AppTypeIndex
8383

8484
[RelayCommand] async Task SelectAppDir() { var p = await PickFolder(_loc["Sim.SelectAppDir"]); if (p != null) Config.AppDirectory = p; }
8585
[RelayCommand] async Task SelectPatch() { var p = await PickFile(_loc["Sim.SelectPatch"]); if (p != null) Config.PatchFilePath = p; }
86-
[RelayCommand] async Task SelectOutputDir() { var p = await PickFolder(_loc["Sim.SelectOutput"]); if (p != null) Config.OutputDirectory = p; }
8786

8887
[RelayCommand]
8988
async Task StartSimulation()
9089
{
9190
if (string.IsNullOrWhiteSpace(Config.AppDirectory)) { Status = _loc["Sim.ValidateDirs"]; return; }
9291
if (string.IsNullOrWhiteSpace(Config.PatchFilePath)) { Status = _loc["Sim.ValidateDirs"]; return; }
93-
if (string.IsNullOrWhiteSpace(Config.OutputDirectory)) { Status = _loc["Sim.ValidateDirs"]; return; }
9492

9593
IsRunning = true; StartButtonText = "⏳ Running..."; Log.Clear(); Status = _loc["Sim.Starting"];
9694
try
@@ -107,15 +105,15 @@ async Task StartSimulation()
107105
}
108106
L($"Result: {(result.Success ? "PASS" : "FAIL")}");
109107
foreach (var note in result.Notes) L($" Note: {note}");
110-
var reportPath = await _report.GenerateAsync(Config, result, Config.OutputDirectory);
108+
var reportPath = await _report.GenerateAsync(Config, result, Config.AppDirectory);
111109
L(_loc.T("Sim.Report", reportPath));
112110
}
113111
catch (Exception ex)
114112
{
115113
Status = $"Error: {ex.Message}";
116114
L($"FATAL: {ex}");
117115
var failResult = new SimulationResult { Success = false, ErrorMessage = ex.Message };
118-
var reportPath = await _report.GenerateAsync(Config, failResult, Config.OutputDirectory);
116+
var reportPath = await _report.GenerateAsync(Config, failResult, Config.AppDirectory);
119117
L(_loc.T("Sim.Report", reportPath));
120118
}
121119
finally { IsRunning = false; StartButtonText = _loc["Sim.Start"]; }

src/Views/SimulateView.axaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,6 @@
6666
</StackPanel>
6767
</Border>
6868

69-
<!-- Output -->
70-
<Border Padding="16" CornerRadius="8" Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}">
71-
<StackPanel Spacing="10">
72-
<TextBlock Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Output]}"
73-
FontSize="14" FontWeight="SemiBold"/>
74-
<Grid ColumnDefinitions="Auto,*,Auto">
75-
<TextBlock Grid.Column="0" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.OutputDir]}"
76-
VerticalAlignment="Center" Width="100"/>
77-
<TextBox Grid.Column="1" Text="{Binding Config.OutputDirectory}" IsReadOnly="True" Margin="8,0"/>
78-
<Button Grid.Column="2" Content="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Select]}"
79-
Command="{Binding SelectOutputDirCommand}" MinWidth="80"/>
80-
</Grid>
81-
</StackPanel>
82-
</Border>
83-
8469
<!-- Run -->
8570
<Button Content="{Binding StartButtonText}"
8671
Command="{Binding StartSimulationCommand}"

0 commit comments

Comments
 (0)