79 lines
1.9 KiB
C#
79 lines
1.9 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace StudioE5.SetupWizard;
|
|
|
|
public enum WizardStep
|
|
{
|
|
Welcome,
|
|
Prerequisites,
|
|
InstallVirtualEnvironment,
|
|
RestartRequired,
|
|
InstallPodman,
|
|
ConfigurePodman,
|
|
InstallAgent,
|
|
Finished,
|
|
Uninstall
|
|
}
|
|
|
|
public class InstallerState
|
|
{
|
|
[JsonPropertyName("step")]
|
|
public WizardStep Step { get; set; } = WizardStep.Welcome;
|
|
|
|
[JsonPropertyName("virtualEnvironmentInstalled")]
|
|
public bool VirtualEnvironmentInstalled { get; set; }
|
|
|
|
[JsonPropertyName("podmanInstalled")]
|
|
public bool PodmanInstalled { get; set; }
|
|
|
|
[JsonPropertyName("podmanConfigured")]
|
|
public bool PodmanConfigured { get; set; }
|
|
|
|
[JsonPropertyName("agentInstalled")]
|
|
public bool AgentInstalled { get; set; }
|
|
|
|
private static string StateFilePath
|
|
{
|
|
get
|
|
{
|
|
var dir = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
"studioE5",
|
|
"installer");
|
|
Directory.CreateDirectory(dir);
|
|
return Path.Combine(dir, "installer-state.json");
|
|
}
|
|
}
|
|
|
|
public static InstallerState Load()
|
|
{
|
|
var path = StateFilePath;
|
|
if (!File.Exists(path))
|
|
return new InstallerState();
|
|
|
|
try
|
|
{
|
|
var json = File.ReadAllText(path);
|
|
return JsonSerializer.Deserialize<InstallerState>(json) ?? new InstallerState();
|
|
}
|
|
catch
|
|
{
|
|
return new InstallerState();
|
|
}
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
var json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(StateFilePath, json);
|
|
}
|
|
|
|
public static void Delete()
|
|
{
|
|
var path = StateFilePath;
|
|
if (File.Exists(path))
|
|
File.Delete(path);
|
|
}
|
|
}
|