-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
98 changed files
with
5,233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.24720.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "EasyJunction", "EasyJunction\EasyJunction.vbproj", "{CEF85D25-B848-49DF-B373-F884C5175F3E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CEF85D25-B848-49DF-B373-F884C5175F3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CEF85D25-B848-49DF-B373-F884C5175F3E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CEF85D25-B848-49DF-B373-F884C5175F3E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CEF85D25-B848-49DF-B373-F884C5175F3E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
Imports System.Reflection | ||
|
||
Public NotInheritable Class App | ||
|
||
#Region "Entry points" | ||
|
||
Public NotInheritable Class EntryPoints | ||
|
||
Private Sub New() | ||
End Sub | ||
|
||
Public Shared Sub Main(Args As String()) | ||
|
||
Dim entryPoint As String = Args.FirstOrDefault | ||
Dim path As String = GetPath(Args) | ||
|
||
Select Case Args.FirstOrDefault | ||
Case Is = String.Empty | ||
General() | ||
|
||
Case Is = DirectoryUtils.Directory | ||
CreateJunction(path) | ||
|
||
Case Is = "-install" | ||
Install(path) | ||
|
||
Case Is = "-uninstall" | ||
Uninstall(path) | ||
|
||
End Select | ||
|
||
End Sub | ||
|
||
Private Shared Sub General() | ||
|
||
If ShouldLaunchInstalledApp() Then | ||
'Launch actual installed file | ||
Dim file As New FileInfo(App.InstallLocation.FullName + "\EasyJunction.exe") | ||
If file.Exists Then | ||
file.Launch() | ||
End If | ||
|
||
Else | ||
SetupWindow.Open() | ||
|
||
End If | ||
|
||
End Sub | ||
|
||
Private Shared Sub CreateJunction(LinkFolder As String) | ||
If Directory.Exists(LinkFolder) Then | ||
JunctionWizardWindow.Open(LinkFolder) | ||
End If | ||
End Sub | ||
|
||
Private Shared Sub Install(InstallFolder As String) | ||
App.Install(New DirectoryInfo(InstallFolder)) | ||
End Sub | ||
|
||
Private Shared Sub Uninstall(InstallFolder As String) | ||
App.Uninstall(New DirectoryInfo(InstallFolder)) | ||
End Sub | ||
|
||
Private Shared Function GetPath(Args As String()) As String | ||
If Args.Count > 1 Then | ||
Return Args(1) | ||
Else | ||
If Directory.Exists(Args.FirstOrDefault) Then | ||
Return Args.FirstOrDefault | ||
Else | ||
Return String.Empty | ||
End If | ||
End If | ||
End Function | ||
|
||
Private Shared Function ShouldLaunchInstalledApp() As Boolean | ||
|
||
Return (App.IsInstalled AndAlso | ||
App.Version = WindowsInstaller.InstallVersion AndAlso | ||
Not App.StartupPath.Directory.IsSameAs(App.InstallLocation) AndAlso | ||
New FileInfo(InstallLocation.FullName + "\EasyJunction.exe").Exists) | ||
|
||
End Function | ||
|
||
End Class | ||
|
||
#End Region | ||
#Region "Properties" | ||
|
||
Public Shared ReadOnly Property StartupPath As FileInfo = | ||
New FileInfo(Assembly.GetExecutingAssembly.Location) | ||
|
||
Public Shared ReadOnly Property Version As Version = | ||
Assembly.GetExecutingAssembly.GetName.Version | ||
|
||
Public Shared ReadOnly Property SizeOnDisk As Long = | ||
StartupPath.Length | ||
|
||
Public Shared ReadOnly Property IsInstalled As Boolean | ||
Get | ||
Return WindowsInstaller.IsInstalled | ||
End Get | ||
End Property | ||
|
||
Public Shared ReadOnly Property InstallLocation As DirectoryInfo | ||
Get | ||
Return WindowsInstaller.InstallLocation | ||
End Get | ||
End Property | ||
|
||
Public Shared ReadOnly Property IsCurrentVersionInstalled As Boolean | ||
Get | ||
Return (WindowsInstaller.IsInstalled AndAlso Version = WindowsInstaller.InstallVersion) | ||
End Get | ||
End Property | ||
|
||
Public Shared ReadOnly Property InstallExecutable As FileInfo | ||
Get | ||
Return New FileInfo(InstallLocation.FullName + "\EasyJunction.exe") | ||
End Get | ||
End Property | ||
|
||
#End Region | ||
#Region "Install / Uninstall" | ||
|
||
Public Shared Sub PrepareToInstall(Folder As DirectoryInfo) | ||
|
||
'If UAC.HasAdminAccess Then | ||
Install(Folder) | ||
'Else | ||
' StartupPath.Launch("-install " + Folder.AsStringPath) | ||
'End If | ||
|
||
End Sub | ||
|
||
Public Shared Sub PrepareToUninstall() | ||
|
||
Dim targetFile As New FileInfo(My.Computer.FileSystem.SpecialDirectories.Temp + "\" + "EasyJunction.exe") | ||
StartupPath.CopyTo(targetFile, True) | ||
|
||
targetFile.Launch("-uninstall " + StartupPath.Directory.AsStringPath) | ||
|
||
End Sub | ||
|
||
Private Shared Sub Install(Folder As DirectoryInfo, Optional SupressDeletionMessage As Boolean = False) | ||
|
||
Try | ||
|
||
KillActiveInstances() | ||
|
||
If (Not SupressDeletionMessage) AndAlso | ||
(Folder.Exists AndAlso Folder.GetFiles.Count > 0) Then | ||
If Not MessageBox.Show("This folder is not empty, and will be cleared before install. Do you want to continue?", | ||
"Folder contains files", MessageBoxButton.YesNoCancel) = MessageBoxResult.Yes Then _ | ||
Exit Sub | ||
|
||
Folder.Delete(True) | ||
|
||
End If | ||
|
||
Folder.Create() | ||
|
||
Dim targetFile As New FileInfo(Folder.FullName + "\EasyJunction.exe") | ||
StartupPath.CopyTo(targetFile, True) | ||
|
||
WindowsInstaller.AddItemToWindowsDeletionList(StartupPath) | ||
WindowsInstaller.InstallTo(Folder) | ||
StartMenu.AddToAllAppsMenu(Folder) | ||
|
||
targetFile.Launch() | ||
|
||
Catch ex As Exception | ||
MessageBox.Show("The app was not properly installed, you might want to try installing again." + vbNewLine + vbNewLine + ex.Message, | ||
"The app was not properly installed.") | ||
SetupWindow.Open() | ||
End Try | ||
|
||
End Sub | ||
|
||
Private Shared Sub Uninstall(InstallFolder As DirectoryInfo) | ||
|
||
Try | ||
|
||
ContextMenuItem.Uninstall() | ||
WindowsInstaller.Uninstall() | ||
WindowsInstaller.AddItemToWindowsDeletionList(StartupPath) | ||
StartMenu.RemoveFromAllAppsMenu() | ||
|
||
KillActiveInstances() | ||
InstallFolder.Delete(True) | ||
|
||
Catch UAex As IOException | ||
MessageBox.Show("The install folder, or exe file inside, could not be deleted, it can be deleted manually." + vbNewLine + vbNewLine + UAex.GetType.FullName + ":" + vbNewLine + UAex.Message, | ||
"The app was not fully uninstalled.") | ||
|
||
Catch ex As Exception | ||
MessageBox.Show("The app was not properly uninstalled, you might want to try installing again and then uninstalling." + vbNewLine + vbNewLine + ex.GetType.FullName + ":" + vbNewLine + ex.Message, | ||
"The app was not properly uninstalled.") | ||
|
||
End Try | ||
|
||
SetupWindow.Open() | ||
|
||
End Sub | ||
|
||
Public Shared Sub Upgrade() | ||
Install(InstallLocation, True) | ||
End Sub | ||
|
||
Private Shared Sub KillActiveInstances() | ||
|
||
Dim currentID As Integer = Process.GetCurrentProcess.Id | ||
For Each instance In Process.GetProcessesByName("EasyJunction") | ||
|
||
If Not instance.Id = currentID Then | ||
|
||
instance.Kill() | ||
instance.WaitForExit(10000) | ||
|
||
End If | ||
Next | ||
|
||
End Sub | ||
|
||
#End Region | ||
|
||
End Class |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
Imports System.Reflection | ||
Imports System.Runtime.InteropServices | ||
Imports Microsoft.Win32 | ||
|
||
Public NotInheritable Class ContextMenuItem | ||
|
||
Private Shared Keys As String() = | ||
{FolderKey, DesktopKey, LibraryKey} | ||
|
||
Private Const FolderKey As String = | ||
"Directory\Background" | ||
|
||
Private Const DesktopKey As String = | ||
"DesktopBackground" | ||
|
||
Private Const LibraryKey As String = | ||
"LibraryFolder\Background" | ||
|
||
Private Shared Command As String = | ||
String.Format("{0}{1}{0} {0}%V{0}", ControlChars.Quote, Assembly.GetExecutingAssembly.Location) | ||
|
||
Private Sub New() | ||
End Sub | ||
|
||
Public Shared ReadOnly Property IsInstalled As Boolean | ||
Get | ||
Return GetIsInstalled() | ||
End Get | ||
End Property | ||
|
||
Public Shared Sub Install() | ||
|
||
For Each key In Keys | ||
CreateItem(key, "CreateJunction", "Create new junction point", Command) | ||
Next | ||
|
||
NotifyContextMenusChange() | ||
|
||
End Sub | ||
|
||
Public Shared Sub Uninstall() | ||
|
||
For Each key In Keys | ||
RemoveItem(key, "CreateJunction") | ||
Next | ||
|
||
NotifyContextMenusChange() | ||
|
||
End Sub | ||
|
||
Private Shared Function GetIsInstalled() As Boolean | ||
|
||
Dim i As Integer = 0 | ||
For Each key In Keys | ||
If Exists(key, "CreateJunction", Command) Then | ||
i += 1 | ||
End If | ||
Next | ||
|
||
Return (i = 3) | ||
|
||
End Function | ||
|
||
Private Shared Sub CreateItem(ShellTypeKey As String, CommandName As String, CommandDisplayName As String, Command As String) | ||
|
||
Dim stKey As RegistryKey = Nothing | ||
Dim shellKey As RegistryKey = Nothing | ||
Dim commandKey As RegistryKey = Nothing | ||
Dim commandSubKey As RegistryKey = Nothing | ||
|
||
Try | ||
|
||
stKey = Registry.CurrentUser.CreateSubKey("software\classes\" + ShellTypeKey) | ||
shellKey = stKey.CreateSubKey("shell") | ||
commandKey = shellKey.CreateSubKey(CommandName) | ||
commandSubKey = commandKey.CreateSubKey("command") | ||
|
||
commandKey.SetValue("", CommandDisplayName) | ||
commandSubKey.SetValue("", Command) | ||
|
||
Catch ex As Exception | ||
Finally | ||
If stKey IsNot Nothing Then stKey.Close() | ||
If shellKey IsNot Nothing Then stKey.Close() | ||
If commandKey IsNot Nothing Then stKey.Close() | ||
If commandSubKey IsNot Nothing Then stKey.Close() | ||
End Try | ||
|
||
End Sub | ||
|
||
Private Shared Sub RemoveItem(ShellTypeKey As String, CommandName As String) | ||
Registry.CurrentUser.DeleteSubKeyTree(String.Format("software\classes\{0}\shell\{1}", ShellTypeKey, CommandName), False) | ||
End Sub | ||
|
||
Private Shared Function Exists(ShellTypeKey As String, CommandName As String, Optional Command As String = Nothing) As Boolean | ||
|
||
Try | ||
Using key = Registry.CurrentUser.OpenSubKey(String.Format("software\classes\{0}\shell\{1}\command", ShellTypeKey, CommandName)) | ||
If key IsNot Nothing Then | ||
Return (key.GetValue("", "") = Command) | ||
End If | ||
End Using | ||
Catch ex As Exception | ||
End Try | ||
|
||
Return False | ||
|
||
End Function | ||
|
||
<DllImport("shell32.dll")> | ||
Private Shared Sub SHChangeNotify(ByVal wEventId As Integer, ByVal uFlags As Integer, ByVal dwItem1 As Integer, ByVal dwItem2 As Integer) | ||
End Sub | ||
|
||
Private Shared Sub NotifyContextMenusChange() | ||
Const SHCNE_ASSOCCHANGED = &H8000000 | ||
Const SHCNF_IDLIST = 0 | ||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0) | ||
End Sub | ||
|
||
End Class |
Oops, something went wrong.