Path Regist 기능 추가 (Windows)
This commit is contained in:
parent
fd14b9fcc7
commit
9f75cdc6d6
3 changed files with 65 additions and 2 deletions
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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<bool>();
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
56
lib/cli/commands/install/regist_path.dart
Normal file
56
lib/cli/commands/install/regist_path.dart
Normal file
|
|
@ -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=%"'));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue