From 9f75cdc6d687fd346614de87b1a350858bd7ef94 Mon Sep 17 00:00:00 2001 From: "leedongmyung[desktop]" Date: Sun, 29 Oct 2023 12:09:45 +0900 Subject: [PATCH] =?UTF-8?q?Path=20Regist=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(Windows)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/cli/cli.dart | 1 - lib/cli/commands/command_install.dart | 10 +++- lib/cli/commands/install/regist_path.dart | 56 +++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 lib/cli/commands/install/regist_path.dart diff --git a/lib/cli/cli.dart b/lib/cli/cli.dart index e2f2d73..21b9001 100644 --- a/lib/cli/cli.dart +++ b/lib/cli/cli.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:io'; -import 'package:build_manager/application.dart'; import 'package:dart_framework/utils/system_util.dart'; import 'package:oto_cli/cli/commands/command_base.dart'; import 'package:oto_cli/cli/commands/command_manager.dart'; diff --git a/lib/cli/commands/command_install.dart b/lib/cli/commands/command_install.dart index 6831bbb..a179e4c 100644 --- a/lib/cli/commands/command_install.dart +++ b/lib/cli/commands/command_install.dart @@ -5,6 +5,7 @@ import 'package:dart_framework/utils/os_startup.dart'; import 'package:oto_cli/cli/cli.dart'; import 'package:oto_cli/cli/commands/command_base.dart'; import 'package:oto_cli/cli/commands/command_const.dart'; +import 'package:oto_cli/cli/commands/install/regist_path.dart'; class CommandInstall extends CommandBase { @override @@ -27,6 +28,9 @@ class CommandInstall extends CommandBase { var installFilePath = '$installPath\\$label.exe'; await target.copy(installFilePath); + //Regist path + RegistPath.OS?.add(installPath); + //Create startup await OSStartup.registStartup(installFilePath, label, arguments: ['start']); @@ -54,10 +58,14 @@ class CommandUninstall extends CommandBase { var c = Completer(); var label = CLI.serviceName; if (await OSStartup.isRegistedStartup(label)) { + var installPath = CommandConstant.OS!.installPath; //To-do: Proccess kill + //Regist path + RegistPath.OS?.add(installPath); + //Remove Installed file - var installDir = Directory(CommandConstant.OS!.installPath); + var installDir = Directory(installPath); if (installDir.existsSync()) { await installDir.delete(recursive: true); } diff --git a/lib/cli/commands/install/regist_path.dart b/lib/cli/commands/install/regist_path.dart new file mode 100644 index 0000000..b2b3ab9 --- /dev/null +++ b/lib/cli/commands/install/regist_path.dart @@ -0,0 +1,56 @@ +import 'dart:io'; + +import 'package:dart_framework/platform/process.dart'; + +class RegistPath { + static RegistPath? _instance; + // ignore: library_private_types_in_public_api + static RegistPath? get OS { + if (_instance == null) { + if (Platform.isMacOS) { + _instance = _RegistPathOSX(); + } else if (Platform.isLinux) { + _instance = _RegistPathLinux(); + } else { + _instance = _RegistPathWindows(); + } + } + return _instance; + } + + void add(String path) { + _instance?.add(path); + } + + void remove(String path) { + _instance?.remove(path); + } +} + +class _RegistPathOSX extends RegistPath { + @override + void add(String path) {} + + @override + void remove(String path) {} +} + +class _RegistPathLinux extends RegistPath { + @override + void add(String path) {} + + @override + void remove(String path) {} +} + +class _RegistPathWindows extends RegistPath { + @override + void add(String path) { + ProcessExecutor.run(StringBuffer('setx path "%path%;$path"')); + } + + @override + void remove(String path) { + ProcessExecutor.run(StringBuffer('setx path "%path:$path=%"')); + } +}