-
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.
Merge pull request #34 from FaithBeam/install
Add Start Menu Installer
- Loading branch information
Showing
9 changed files
with
207 additions
and
7 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
YMouseButtonControl.Core/Services/StartMenuInstaller/IStartMenuInstallerService.cs
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,8 @@ | ||
namespace YMouseButtonControl.Core.Services.StartMenuInstaller; | ||
|
||
public interface IStartMenuInstallerService | ||
{ | ||
bool InstallStatus(); | ||
void Install(); | ||
void Uninstall(); | ||
} |
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
49 changes: 49 additions & 0 deletions
49
YMouseButtonControl.Linux/Services/StartMenuInstallerService.cs
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,49 @@ | ||
using YMouseButtonControl.Core.Services.StartMenuInstaller; | ||
|
||
namespace YMouseButtonControl.Linux.Services; | ||
|
||
public class StartMenuInstallerService : IStartMenuInstallerService | ||
{ | ||
private const string DesktopFile = """ | ||
[Desktop Entry] | ||
Type=Application | ||
Exec={0} | ||
Path={1} | ||
Hidden=false | ||
NoDisplay=false | ||
X-GNOME-Autostart-enabled=true | ||
Name=YMouseButtonControl | ||
Comment=YMouseButtonControl | ||
"""; | ||
|
||
private readonly string _localShare = Environment.GetFolderPath( | ||
Environment.SpecialFolder.LocalApplicationData | ||
); | ||
|
||
private readonly string _desktopFilePath; | ||
|
||
public StartMenuInstallerService() | ||
{ | ||
var applicationsDir = Path.Combine(_localShare, "applications"); | ||
_desktopFilePath = Path.Combine(applicationsDir, "YMouseButtonControl.desktop"); | ||
} | ||
|
||
public bool InstallStatus() => | ||
File.Exists(_desktopFilePath) | ||
&& File.ReadAllText(_desktopFilePath).Contains($"Exec={GetCurExePath()}"); | ||
|
||
public void Install() => | ||
File.WriteAllText( | ||
_desktopFilePath, | ||
string.Format(DesktopFile, GetCurExePath(), GetCurExeParentPath()) | ||
); | ||
|
||
public void Uninstall() => File.Delete(_desktopFilePath); | ||
|
||
private static string GetCurExeParentPath() => | ||
Path.GetDirectoryName(GetCurExePath()) | ||
?? throw new Exception("Error retrieving parent of process path"); | ||
|
||
private static string GetCurExePath() => | ||
Environment.ProcessPath ?? throw new Exception("Error retrieving process path"); | ||
} |
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,21 @@ | ||
using YMouseButtonControl.Core.Services.StartMenuInstaller; | ||
|
||
namespace YMouseButtonControl.MacOS.Services; | ||
|
||
public class StartMenuInstaller : IStartMenuInstallerService | ||
{ | ||
public bool InstallStatus() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void Install() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void Uninstall() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
YMouseButtonControl.Windows/Services/StartMenuInstallerService.cs
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,70 @@ | ||
using System; | ||
using System.IO; | ||
using WindowsShortcutFactory; | ||
using YMouseButtonControl.Core.Services.StartMenuInstaller; | ||
|
||
namespace YMouseButtonControl.Windows.Services; | ||
|
||
public class StartMenuInstallerService : IStartMenuInstallerService | ||
{ | ||
private readonly string _roamingAppDataFolder = Environment.GetFolderPath( | ||
Environment.SpecialFolder.ApplicationData | ||
); | ||
|
||
private readonly string _roamingYMouseButtonsFolder; | ||
|
||
private readonly string _roamingYmouseButtonsShortcutPath; | ||
|
||
public StartMenuInstallerService() | ||
{ | ||
_roamingYMouseButtonsFolder = Path.Combine( | ||
_roamingAppDataFolder, | ||
"Microsoft", | ||
"Windows", | ||
"Start Menu", | ||
"Programs", | ||
"YMouseButtonControl" | ||
); | ||
_roamingYmouseButtonsShortcutPath = Path.Combine( | ||
_roamingYMouseButtonsFolder, | ||
"YMouseButtonControl.lnk" | ||
); | ||
} | ||
|
||
public bool InstallStatus() | ||
{ | ||
if (!File.Exists(_roamingYmouseButtonsShortcutPath)) | ||
{ | ||
return false; | ||
} | ||
using var shortcut = WindowsShortcut.Load(_roamingYmouseButtonsShortcutPath); | ||
return shortcut.Path == GetCurExePath(); | ||
} | ||
|
||
public void Install() | ||
{ | ||
if (File.Exists(_roamingYmouseButtonsShortcutPath)) | ||
{ | ||
File.Delete(_roamingYmouseButtonsShortcutPath); | ||
} | ||
|
||
if (!Directory.Exists(_roamingYMouseButtonsFolder)) | ||
{ | ||
Directory.CreateDirectory(_roamingYMouseButtonsFolder); | ||
} | ||
|
||
using var shortcut = new WindowsShortcut(); | ||
shortcut.Path = GetCurExePath(); | ||
shortcut.WorkingDirectory = GetCurExeParentPath(); | ||
shortcut.Save(_roamingYmouseButtonsShortcutPath); | ||
} | ||
|
||
public void Uninstall() => File.Delete(_roamingYmouseButtonsShortcutPath); | ||
|
||
private static string GetCurExeParentPath() => | ||
Path.GetDirectoryName(GetCurExePath()) | ||
?? throw new Exception("Error retrieving parent of process path"); | ||
|
||
private static string GetCurExePath() => | ||
Environment.ProcessPath ?? throw new Exception("Error retrieving process path"); | ||
} |
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
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
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
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