-
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.
Reverts #14
- Loading branch information
Showing
19 changed files
with
573 additions
and
181 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
namespace OrnaLibs; | ||
|
||
/// <summary> | ||
/// Информация о приложении | ||
/// </summary> | ||
public partial struct Application | ||
{ | ||
/// <summary> | ||
/// Регистрация приложения | ||
/// </summary> | ||
public void Registration() | ||
{ | ||
if (OperatingSystem.IsWindows()) | ||
RegistrationWindows(); | ||
} | ||
|
||
/// <summary> | ||
/// Удаление записи о приложении | ||
/// </summary> | ||
public void Unregistration() | ||
{ | ||
if (OperatingSystem.IsWindows()) | ||
RegistryKeys.LocalMachineUninstallX86.DeleteSubKey(Name, false); | ||
} | ||
|
||
/// <summary> | ||
/// Регистрация сервиса | ||
/// </summary> | ||
public void RegistrationService() | ||
{ | ||
if (string.IsNullOrWhiteSpace(ServicePath)) | ||
throw new ArgumentNullException(nameof(ServicePath)); | ||
if (OperatingSystem.IsWindows()) | ||
CreateWindowsService(); | ||
} | ||
|
||
/// <summary> | ||
/// Удаление сервиса | ||
/// </summary> | ||
public void UnregistrationService() | ||
{ | ||
if (string.IsNullOrWhiteSpace(ServicePath)) | ||
throw new ArgumentNullException(nameof(ServicePath)); | ||
if (OperatingSystem.IsWindows()) | ||
Utils.CMD($"sc stop {Name} && sc delete {Name}"); | ||
} | ||
} |
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 @@ | ||
namespace OrnaLibs; | ||
|
||
public partial struct Application | ||
{ | ||
/// <summary> | ||
/// Название приложения | ||
/// </summary> | ||
public string Name { get; init; } | ||
|
||
/// <summary> | ||
/// Версия приложения | ||
/// </summary> | ||
public Version? Version { get; init; } | ||
|
||
/// <summary> | ||
/// Отображаемое название приложения | ||
/// </summary> | ||
public string DisplayName { get; init; } | ||
|
||
/// <summary> | ||
/// Разработчик приложения (Организация в GitHub) | ||
/// </summary> | ||
public string CompanyName { get; init; } | ||
|
||
/// <summary> | ||
/// Путь до исполняемого файла | ||
/// </summary> | ||
public string AppPath { get; init; } | ||
|
||
/// <summary> | ||
/// Путь до иконки приложения | ||
/// </summary> | ||
public string IconPath { get; init; } | ||
|
||
/// <summary> | ||
/// Путь до конфигуратора | ||
/// </summary> | ||
public string Configurator { get; init; } | ||
|
||
/// <summary> | ||
/// Путь до деинсталятора | ||
/// </summary> | ||
public string Uninstaller { get; init; } | ||
|
||
/// <summary> | ||
/// Путь до сервис-приложения | ||
/// </summary> | ||
public string ServicePath { get; init; } | ||
} |
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,38 @@ | ||
using Microsoft.Win32; | ||
using System.Runtime.Versioning; | ||
using System.Text; | ||
|
||
namespace OrnaLibs; | ||
|
||
public partial struct Application | ||
{ | ||
[SupportedOSPlatform("windows")] | ||
private void RegistrationWindows() | ||
{ | ||
using var reg = RegistryKeys.LocalMachineUninstallX86.CreateSubKey(Name, true); | ||
reg.SetValue("Publisher", CompanyName, RegistryValueKind.String); | ||
reg.SetValue("EstimatedSize", new FileInfo(AppPath).Length / 1024, RegistryValueKind.DWord); | ||
reg.SetValue("InstallLocation", Path.GetDirectoryName(AppPath)!, RegistryValueKind.String); | ||
if (Version is { }) | ||
reg.SetValue("DisplayVersion", Version.ToString(), RegistryValueKind.String); | ||
if (!string.IsNullOrWhiteSpace(DisplayName)) | ||
reg.SetValue("DisplayName", DisplayName, RegistryValueKind.String); | ||
if (!string.IsNullOrWhiteSpace(IconPath)) | ||
reg.SetValue("DisplayIcon", IconPath, RegistryValueKind.String); | ||
if (!string.IsNullOrWhiteSpace(Configurator)) | ||
reg.SetValue("ModifyPath", Configurator, RegistryValueKind.String); | ||
if (!string.IsNullOrWhiteSpace(Uninstaller)) | ||
reg.SetValue("UninstallString", Uninstaller, RegistryValueKind.String); | ||
} | ||
|
||
[SupportedOSPlatform("windows")] | ||
private void CreateWindowsService() | ||
{ | ||
var builder = new StringBuilder("New-Service"); | ||
builder.AppendFormat(" -Name \"{0}\"", Name); | ||
builder.AppendFormat(" -DisplayName \"{0}\"", DisplayName); | ||
builder.AppendFormat(" -BinaryPathName \"{0}\"", ServicePath); | ||
builder.AppendFormat(" -StartupType \"{0}\"", "Automatic"); | ||
Utils.PowerShell(builder.ToString()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using OrnaLibs.DataTypes; | ||
using System.Globalization; | ||
|
||
namespace OrnaLibs | ||
|
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,28 @@ | ||
namespace OrnaLibs.DataTypes | ||
{ | ||
public struct RequiredDirectory(string path) | ||
{ | ||
private void RecursiveCreate() | ||
{ | ||
var elems = new Queue<string>(path.Split(Path.DirectorySeparatorChar)); | ||
var _path = elems.Dequeue(); | ||
do | ||
{ | ||
_path = Path.Combine(_path, elems.Dequeue()); | ||
if(!Directory.Exists(_path)) | ||
Directory.CreateDirectory(_path); | ||
} | ||
while (elems.Count > 0); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
if (!Directory.Exists(path)) | ||
RecursiveCreate(); | ||
return path; | ||
} | ||
|
||
public static implicit operator RequiredDirectory(string path) => new(path); | ||
public static implicit operator string(RequiredDirectory dir) => dir.ToString(); | ||
} | ||
} |
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
Oops, something went wrong.