Skip to content

Commit

Permalink
feat: bin in environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Nov 30, 2024
1 parent 75d5680 commit 8018075
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
21 changes: 17 additions & 4 deletions build/MicaSetup/Helper/Setup/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,26 @@ public static void Install(Stream archiveStream, Action<double, string> progress
{
try
{
if (RuntimeHelper.IsElevated)
AddEnvironmentVariable(Option.Current.InstallLocation);

foreach (string directory in Directory.EnumerateDirectories(Option.Current.InstallLocation, "*", SearchOption.AllDirectories))
{
EnvironmentVariableHelper.AddDirectoryToSystemPath(Option.Current.InstallLocation);
if (new DirectoryInfo(directory).Name == "bin")
{
AddEnvironmentVariable(directory);
}
}
else

static void AddEnvironmentVariable(string directoryPath)
{
EnvironmentVariableHelper.AddDirectoryToUserPath(Option.Current.InstallLocation);
if (RuntimeHelper.IsElevated)
{
EnvironmentVariableHelper.AddDirectoryToSystemPath(directoryPath);
}
else
{
EnvironmentVariableHelper.AddDirectoryToUserPath(directoryPath);
}
}
}
catch (Exception e)
Expand Down
21 changes: 17 additions & 4 deletions build/MicaSetup/Helper/Setup/UninstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,26 @@ static int GetFileCount(string path)
{
try
{
if (RuntimeHelper.IsElevated)
RemoveEnvironmentVariable(Option.Current.InstallLocation);

foreach (string directory in Directory.EnumerateDirectories(Option.Current.InstallLocation, "*", SearchOption.AllDirectories))
{
EnvironmentVariableHelper.RemoveDirectoryFromSystemPath(Option.Current.InstallLocation);
if (new DirectoryInfo(directory).Name == "bin")
{
RemoveEnvironmentVariable(directory);
}
}
else

static void RemoveEnvironmentVariable(string directoryPath)
{
EnvironmentVariableHelper.RemoveDirectoryFromUserPath(Option.Current.InstallLocation);
if (RuntimeHelper.IsElevated)
{
EnvironmentVariableHelper.RemoveDirectoryFromSystemPath(directoryPath);
}
else
{
EnvironmentVariableHelper.RemoveDirectoryFromUserPath(directoryPath);
}
}
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion build/MicaSetup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static void Main()
option.OverlayInstallRemoveExt = "exe,dll,pdb";
option.OverlayInstallRemoveHandler = null!;
option.UnpackingPassword = null!;
option.EnvironmentVariable = null!;
option.IsEnvironmentVariable = false;
option.AppName = "MicaApp";
option.KeyName = "MicaApp";
option.ExeName = "MicaApp.exe";
Expand Down

0 comments on commit 8018075

Please sign in to comment.