mirror of
https://github.com/Syping/ragephoto-cli.git
synced 2025-12-04 16:51:48 +01:00
register environment path while install
This commit is contained in:
parent
ed51804c85
commit
4e03eeb837
3 changed files with 76 additions and 8 deletions
|
|
@ -93,7 +93,7 @@ Section -UninstallPrevious
|
||||||
ReadRegStr $0 ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString"
|
ReadRegStr $0 ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString"
|
||||||
${If} $0 != ""
|
${If} $0 != ""
|
||||||
${GetParent} $0 $1
|
${GetParent} $0 $1
|
||||||
ExecWait "$0 /S _?=$1"
|
ExecWait '"$0" /S "_?=$1"'
|
||||||
${EndIf}
|
${EndIf}
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
|
|
@ -132,10 +132,13 @@ WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}"
|
||||||
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${APP_VERSION}"
|
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${APP_VERSION}"
|
||||||
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${APP_CREATOR}"
|
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${APP_CREATOR}"
|
||||||
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
|
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
|
||||||
|
|
||||||
|
ExecWait '"$INSTDIR/${APP_EXECUTABLE}" path register'
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section Uninstall
|
Section Uninstall
|
||||||
${INSTALL_TYPE}
|
${INSTALL_TYPE}
|
||||||
|
ExecWait '"$INSTDIR/${APP_EXECUTABLE}" path unregister'
|
||||||
!include ".nsis/uninstall.nsh"
|
!include ".nsis/uninstall.nsh"
|
||||||
Delete "$INSTDIR\uninstall.exe"
|
Delete "$INSTDIR\uninstall.exe"
|
||||||
RmDir "$INSTDIR"
|
RmDir "$INSTDIR"
|
||||||
|
|
|
||||||
76
Commands.cs
76
Commands.cs
|
|
@ -1,10 +1,12 @@
|
||||||
using System.CommandLine;
|
using Microsoft.Win32;
|
||||||
|
using System.CommandLine;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
namespace RagePhoto.Cli;
|
namespace RagePhoto.Cli;
|
||||||
|
|
||||||
internal static class Commands {
|
internal static class Commands {
|
||||||
|
|
||||||
internal static void Create(String format, String jpegFile, String outputFile, String? description, String? json, String? title) {
|
internal static void CreateFunction(String format, String jpegFile, String outputFile, String? description, String? json, String? title) {
|
||||||
try {
|
try {
|
||||||
using Photo photo = new();
|
using Photo photo = new();
|
||||||
|
|
||||||
|
|
@ -72,7 +74,7 @@ internal static class Commands {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Get(String inputFile, String dataType, String outputFile) {
|
internal static void GetFunction(String inputFile, String dataType, String outputFile) {
|
||||||
try {
|
try {
|
||||||
using Photo photo = new();
|
using Photo photo = new();
|
||||||
|
|
||||||
|
|
@ -147,7 +149,7 @@ internal static class Commands {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Set(String inputFile, String? format, String? jpegFile, String? description, String? json, String? title, bool updateSign, String? outputFile) {
|
internal static void SetFunction(String inputFile, String? format, String? jpegFile, String? description, String? json, String? title, bool updateSign, String? outputFile) {
|
||||||
if (format == null && jpegFile == null && description == null
|
if (format == null && jpegFile == null && description == null
|
||||||
&& json == null && title == null && !updateSign) {
|
&& json == null && title == null && !updateSign) {
|
||||||
Console.Error.WriteLine("No value has being set");
|
Console.Error.WriteLine("No value has being set");
|
||||||
|
|
@ -228,6 +230,48 @@ internal static class Commands {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void PathFunction(String command) {
|
||||||
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
if (command == "register" || command == "unregister") {
|
||||||
|
String appPath = Path.GetDirectoryName(Environment.ProcessPath) ??
|
||||||
|
throw new Exception("Application path can not be found");
|
||||||
|
String fullAppPath = Path.TrimEndingDirectorySeparator(Path.GetFullPath(appPath));
|
||||||
|
using RegistryKey environmentKey = Registry.LocalMachine.OpenSubKey(
|
||||||
|
@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true) ??
|
||||||
|
throw new Exception("Environment registry key can not be opened");
|
||||||
|
String? path = environmentKey.GetValue(
|
||||||
|
"Path", null, RegistryValueOptions.DoNotExpandEnvironmentNames) as String ??
|
||||||
|
throw new Exception("Path registry value is invalid");
|
||||||
|
List<String> paths = [.. path.Split(';', StringSplitOptions.RemoveEmptyEntries)];
|
||||||
|
for (Int32 i = 0; i < paths.Count; i++) {
|
||||||
|
if (!String.Equals(
|
||||||
|
fullAppPath,
|
||||||
|
Path.TrimEndingDirectorySeparator(Path.GetFullPath(paths[i])),
|
||||||
|
StringComparison.OrdinalIgnoreCase))
|
||||||
|
continue;
|
||||||
|
if (command == "register")
|
||||||
|
return;
|
||||||
|
paths.RemoveAt(i);
|
||||||
|
environmentKey.SetValue("Path", String.Join(";", paths), RegistryValueKind.ExpandString);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (command == "unregister")
|
||||||
|
return;
|
||||||
|
paths.Add(fullAppPath);
|
||||||
|
environmentKey.SetValue("Path", String.Join(";", paths), RegistryValueKind.ExpandString);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.Error.WriteLine("Invalid path command supplied");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Environment.Exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static Command CreateCommand {
|
internal static Command CreateCommand {
|
||||||
get {
|
get {
|
||||||
Argument<String> formatArgument = new("format") {
|
Argument<String> formatArgument = new("format") {
|
||||||
|
|
@ -256,7 +300,7 @@ internal static class Commands {
|
||||||
Command createCommand = new("create", "Create Photo") {
|
Command createCommand = new("create", "Create Photo") {
|
||||||
formatArgument, jpegArgument, outputArgument, descriptionOption, jsonOption, titleOption
|
formatArgument, jpegArgument, outputArgument, descriptionOption, jsonOption, titleOption
|
||||||
};
|
};
|
||||||
createCommand.SetAction(result => Create(
|
createCommand.SetAction(result => CreateFunction(
|
||||||
result.GetRequiredValue(formatArgument),
|
result.GetRequiredValue(formatArgument),
|
||||||
result.GetRequiredValue(jpegArgument),
|
result.GetRequiredValue(jpegArgument),
|
||||||
result.GetRequiredValue(outputArgument),
|
result.GetRequiredValue(outputArgument),
|
||||||
|
|
@ -290,7 +334,7 @@ internal static class Commands {
|
||||||
Command getCommand = new("get", "Get Photo Data") {
|
Command getCommand = new("get", "Get Photo Data") {
|
||||||
inputArgument, dataTypeArgument, outputOption
|
inputArgument, dataTypeArgument, outputOption
|
||||||
};
|
};
|
||||||
getCommand.SetAction(result => Get(
|
getCommand.SetAction(result => GetFunction(
|
||||||
result.GetRequiredValue(inputArgument),
|
result.GetRequiredValue(inputArgument),
|
||||||
result.GetRequiredValue(dataTypeArgument),
|
result.GetRequiredValue(dataTypeArgument),
|
||||||
result.GetRequiredValue(outputOption)));
|
result.GetRequiredValue(outputOption)));
|
||||||
|
|
@ -327,7 +371,7 @@ internal static class Commands {
|
||||||
Command setCommand = new("set", "Set Photo Data") {
|
Command setCommand = new("set", "Set Photo Data") {
|
||||||
inputArgument, formatOption, jpegOption, descriptionOption, jsonOption, titleOption, updateSignOption, outputOption
|
inputArgument, formatOption, jpegOption, descriptionOption, jsonOption, titleOption, updateSignOption, outputOption
|
||||||
};
|
};
|
||||||
setCommand.SetAction(result => Set(
|
setCommand.SetAction(result => SetFunction(
|
||||||
result.GetRequiredValue(inputArgument),
|
result.GetRequiredValue(inputArgument),
|
||||||
result.GetValue(formatOption),
|
result.GetValue(formatOption),
|
||||||
result.GetValue(jpegOption),
|
result.GetValue(jpegOption),
|
||||||
|
|
@ -339,4 +383,22 @@ internal static class Commands {
|
||||||
return setCommand;
|
return setCommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static Command PathCommand {
|
||||||
|
get {
|
||||||
|
Argument<String> commandArgument = new("command") {
|
||||||
|
Description = "Path Command"
|
||||||
|
};
|
||||||
|
commandArgument.CompletionSources.Add(_ => [
|
||||||
|
new ("register"),
|
||||||
|
new ("unregister")]);
|
||||||
|
Command pathCommand = new("path", "Register/Unregister Path") {
|
||||||
|
commandArgument
|
||||||
|
};
|
||||||
|
pathCommand.Hidden = true;
|
||||||
|
pathCommand.SetAction(result => PathFunction(
|
||||||
|
result.GetRequiredValue(commandArgument)));
|
||||||
|
return pathCommand;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.CommandLine;
|
using System.CommandLine;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
namespace RagePhoto.Cli;
|
namespace RagePhoto.Cli;
|
||||||
|
|
||||||
internal static class Program {
|
internal static class Program {
|
||||||
|
|
@ -7,6 +8,8 @@ internal static class Program {
|
||||||
RootCommand rootCommand = new("ragephoto-cli Application") {
|
RootCommand rootCommand = new("ragephoto-cli Application") {
|
||||||
Commands.CreateCommand, Commands.GetCommand, Commands.SetCommand
|
Commands.CreateCommand, Commands.GetCommand, Commands.SetCommand
|
||||||
};
|
};
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
rootCommand.Add(Commands.PathCommand);
|
||||||
rootCommand.Parse(args).Invoke();
|
rootCommand.Parse(args).Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue