Skip to content

Commit

Permalink
feat: new option IsEnvironmentVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Nov 30, 2024
1 parent 00b91cc commit 75d5680
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 4 deletions.
5 changes: 5 additions & 0 deletions build/MicaSetup.Tools/MakeMica.Cli/Core/CSharpProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public static void SetupConfig(string csPath, MicaConfig config, bool isUninst =
}
}

if (config.IsEnvironmentVariable)
{
root = root.ReplaceOptionWithBoolean("IsEnvironmentVariable", config.IsEnvironmentVariable);
}

if (!string.IsNullOrWhiteSpace(config.Version))
{
if (Version.TryParse(config.Version, out _))
Expand Down
5 changes: 5 additions & 0 deletions build/MicaSetup.Tools/MakeMica.Shared/MicaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ public class MicaConfig
/// </summary>
public string? UnpackingPassword { get; set; } = null;

/// <summary>
/// Indicates whether to add environment variable
/// </summary>
public bool IsEnvironmentVariable { get; set; } = false;

/// <summary>
/// <see cref="MicaSetup.Option.MessageOfPage1"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"KeyName": "MicaApp",
"ExeName": "MicaApp.exe",
"Publisher": "Lemutec",
"Version": "1.0.0",
"Version": "${Package}${ExeName}|3",
"TargetFramework": "net472",
"Guid": "00000000-0000-0000-0000-000000000000",
"Favicon": null,
Expand Down Expand Up @@ -34,6 +34,7 @@
"IsRefreshExplorer": true,
"IsInstallCertificate": false,
"IsEnableUninstallDelayUntilReboot": true,
"IsEnvironmentVariable": false,
"OverlayInstallRemoveExt": "exe,dll,pdb",
"UnpackingPassword": null,
"MessageOfPage1": null,
Expand Down
19 changes: 19 additions & 0 deletions build/MicaSetup/Helper/Setup/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,25 @@ public static void Install(Stream archiveStream, Action<double, string> progress
}
}

if (Option.Current.IsEnvironmentVariable)
{
try
{
if (RuntimeHelper.IsElevated)
{
EnvironmentVariableHelper.AddDirectoryToSystemPath(Option.Current.InstallLocation);
}
else
{
EnvironmentVariableHelper.AddDirectoryToUserPath(Option.Current.InstallLocation);
}
}
catch (Exception e)
{
Logger.Error(e);
}
}

try
{
StartMenuHelper.AddToRecent(Path.Combine(Option.Current.InstallLocation, Option.Current.ExeName));
Expand Down
22 changes: 20 additions & 2 deletions build/MicaSetup/Helper/Setup/UninstallHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MicaSetup.Design.Controls;
using MicaSetup.Natives;
using MicaSetup.Natives;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -244,6 +243,25 @@ static int GetFileCount(string path)
}
}

if (Option.Current.IsEnvironmentVariable)
{
try
{
if (RuntimeHelper.IsElevated)
{
EnvironmentVariableHelper.RemoveDirectoryFromSystemPath(Option.Current.InstallLocation);
}
else
{
EnvironmentVariableHelper.RemoveDirectoryFromUserPath(Option.Current.InstallLocation);
}
}
catch (Exception e)
{
Logger.Error(e);
}
}

try
{
RegistyUninstallHelper.Delete(Option.Current.KeyName);
Expand Down
4 changes: 3 additions & 1 deletion build/MicaSetup/MicaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace MicaSetup;

[Description("Internal mark for setup and uninst")]
/// <summary>
/// Internal mark for setup and uninst
/// </summary>
internal static class MicaInfo
{
public const string Version = "2.3.0.0";
Expand Down
6 changes: 6 additions & 0 deletions build/MicaSetup/Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ public partial class Option
[Category("GlobalSetting")]
public string UnpackingPassword { get; set; } = null!;

/// <summary>
/// Indicates whether to add environment variable
/// </summary>
[Category("GlobalSetting")]
public bool IsEnvironmentVariable { get; set; } = false;

/// <summary>
/// Your Product Exe file name
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions build/MicaSetup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal static void Main()
option.OverlayInstallRemoveExt = "exe,dll,pdb";
option.OverlayInstallRemoveHandler = null!;
option.UnpackingPassword = null!;
option.EnvironmentVariable = null!;

Check failure on line 56 in build/MicaSetup/Program.cs

View workflow job for this annotation

GitHub Actions / build

'Option' does not contain a definition for 'EnvironmentVariable' and no accessible extension method 'EnvironmentVariable' accepting a first argument of type 'Option' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 56 in build/MicaSetup/Program.cs

View workflow job for this annotation

GitHub Actions / build

'Option' does not contain a definition for 'EnvironmentVariable' and no accessible extension method 'EnvironmentVariable' accepting a first argument of type 'Option' could be found (are you missing a using directive or an assembly reference?)
option.AppName = "MicaApp";
option.KeyName = "MicaApp";
option.ExeName = "MicaApp.exe";
Expand Down
1 change: 1 addition & 0 deletions build/MicaSetup/Program.un.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal static void Main()
option.IsRefreshExplorer = true;
option.IsInstallCertificate = false;
option.IsEnableUninstallDelayUntilReboot = true;
option.IsEnvironmentVariable = false;
option.AppName = "MicaApp";
option.KeyName = "MicaApp";
option.ExeName = "MicaApp.exe";
Expand Down

0 comments on commit 75d5680

Please sign in to comment.