Files
Sourcetrail/deployment/windows/CoatiSetup/SetupCreateStartMenuShortcutLib/CreateStartMenuShortcut.cs
T
Manuel Dobusch 04196db81d ui: windows installer
Created a windows installer (vs deployment project).
2015-12-02 14:50:02 +01:00

68 lines
2.1 KiB
C#

using IWshRuntimeLibrary;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Threading.Tasks;
namespace SetupCreateStartMenuShortcutLib
{
[RunInstaller(true)]
public partial class CreateStartMenuShortcut : System.Configuration.Install.Installer
{
public CreateStartMenuShortcut()
{
InitializeComponent();
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
string app = System.Reflection.Assembly.GetExecutingAssembly().Location;
string name = "install\\" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
int nameIdx = app.LastIndexOf(name);
string appDirectory = app.Substring(0, nameIdx);
app = appDirectory + "Coati.exe";
WshShell shell = new WshShell();
string shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu) + "Coati.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "Fast source code reading and navigation";
shortcut.TargetPath = app;
shortcut.WorkingDirectory = appDirectory;
shortcut.Save();
}
protected override void OnAfterRollback(IDictionary savedState)
{
base.OnAfterRollback(savedState);
DeleteDesktopShortcut();
}
protected override void OnAfterUninstall(IDictionary savedState)
{
base.OnAfterUninstall(savedState);
DeleteDesktopShortcut();
}
private void DeleteDesktopShortcut()
{
object shDesktop = (object)"Desktop";
WshShell shell = new WshShell();
string shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu) + "Coati.lnk";
if (System.IO.File.Exists(shortcutAddress))
{
System.IO.File.Delete(shortcutAddress);
}
}
}
}