Skip to content

Commit

Permalink
Setup: Add to $PATH during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaier committed Jun 7, 2013
1 parent 736d276 commit b08985d
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
78 changes: 78 additions & 0 deletions SimpleDLNA/PathEnvironmentInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Win32;

namespace NMaier.SimpleDlna.GUI
{
[RunInstaller(true)]
public class PathEnvironmentInstaller : Installer
{
private const string keyEnvironmentPath = "EnvironmentPath";
private const string keyRegPath = "PATH";
private const string keyRegEnvironment = "Environment";
private readonly DirectoryInfo directory = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
if (!directory.Exists) {
return;
}

using (var registry = Registry.CurrentUser.OpenSubKey(keyRegEnvironment, true)) {
var path = registry.GetValue(keyRegPath, string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames) as string;
if (path == null) {
return;
}
var exists = from p in path.Split(';')
where StringComparer.CurrentCultureIgnoreCase.Equals(p, directory.FullName)
select p;
if (exists.Count() > 0) {
return;
}
stateSaver[keyEnvironmentPath] = path;
var newpath = directory.FullName;
if (!string.IsNullOrWhiteSpace(path)) {
newpath = string.Format("{0};{1}", path, newpath);
}
registry.SetValue(keyRegPath, newpath, registry.GetValueKind(keyRegPath));
}
}
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
if (!directory.Exists) {
return;
}

using (var registry = Registry.CurrentUser.OpenSubKey(keyRegEnvironment, true)) {
var path = registry.GetValue(keyRegPath, string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames) as string;
if (path == null) {
return;
}
var cleaned = string.Join(";", from p in path.Split(';')
where !StringComparer.CurrentCultureIgnoreCase.Equals(p, directory.FullName)
select p);
if (StringComparer.CurrentCultureIgnoreCase.Equals(path, cleaned)) {
return;
}
registry.SetValue(keyRegPath, cleaned, registry.GetValueKind(keyRegPath));
}
}

public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
if (!savedState.Contains(keyEnvironmentPath)) {
return;
}
using (var registry = Registry.CurrentUser.OpenSubKey(keyRegEnvironment, true)) {
registry.SetValue(keyRegPath, savedState[keyEnvironmentPath], registry.GetValueKind(keyRegPath));
}
}
}
}
42 changes: 42 additions & 0 deletions setup/setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,48 @@
{
"CustomAction"
{
"{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_2DB3E06ADD2B4B768C233310277DA233"
{
"Name" = "8:Primary output from SimpleDLNA (Active)"
"Condition" = "8:"
"Object" = "8:_D76DE9BBA3294BD69BDD0AC9BB0554D7"
"FileType" = "3:2"
"InstallAction" = "3:1"
"Arguments" = "8:"
"EntryPoint" = "8:"
"Sequence" = "3:1"
"Identifier" = "8:_BA6A93EC_79DB_47C8_9B40_34390CFBBECA"
"InstallerClass" = "11:TRUE"
"CustomActionData" = "8:"
}
"{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_6C66D35A142E4BA981141352DF824B33"
{
"Name" = "8:Primary output from SimpleDLNA (Active)"
"Condition" = "8:"
"Object" = "8:_D76DE9BBA3294BD69BDD0AC9BB0554D7"
"FileType" = "3:2"
"InstallAction" = "3:4"
"Arguments" = "8:"
"EntryPoint" = "8:"
"Sequence" = "3:1"
"Identifier" = "8:_F1F56558_9E4A_4B50_9D65_19C596ED4FAA"
"InstallerClass" = "11:TRUE"
"CustomActionData" = "8:"
}
"{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_9E408D24E6BE43ADBE44D054D3FFB179"
{
"Name" = "8:Primary output from SimpleDLNA (Active)"
"Condition" = "8:"
"Object" = "8:_D76DE9BBA3294BD69BDD0AC9BB0554D7"
"FileType" = "3:2"
"InstallAction" = "3:3"
"Arguments" = "8:"
"EntryPoint" = "8:"
"Sequence" = "3:1"
"Identifier" = "8:_E090906C_4FA4_4AF1_9AE4_C9219B448401"
"InstallerClass" = "11:TRUE"
"CustomActionData" = "8:"
}
}
"DefaultFeature"
{
Expand Down

0 comments on commit b08985d

Please sign in to comment.