Wiindows Path 제대로 동작 안하는 문제 수정
This commit is contained in:
parent
ba481d14f2
commit
44bd15559b
2 changed files with 31 additions and 8 deletions
|
|
@ -1,13 +1,10 @@
|
|||
import 'package:oto_cli/cli/commands/command_exe.dart';
|
||||
import 'package:oto_cli/cli/commands/command_install.dart';
|
||||
import 'package:oto_cli/cli/commands/command_start.dart';
|
||||
|
||||
import 'package:oto_cli/cli/cli.dart';
|
||||
import 'package:oto_cli/cli/commands/command_template.dart';
|
||||
import 'package:oto_cli/oto/application.dart';
|
||||
import 'package:oto_cli/cli/commands/command_install.dart';
|
||||
import 'package:oto_cli/cli/commands/command_exe.dart';
|
||||
import 'package:oto_cli/cli/commands/command_start.dart';
|
||||
|
||||
void main(List<String> arguments) async {
|
||||
var app = Application.instance;
|
||||
CLI.initialize('OTO', arguments, [
|
||||
CommandTemplate(),
|
||||
CommandInstall(),
|
||||
|
|
|
|||
|
|
@ -112,15 +112,41 @@ class _RegistPathLinux extends RegistPath {
|
|||
|
||||
/// ************* WINDOWS ***************
|
||||
class _RegistPathWindows extends RegistPath {
|
||||
var setUserPath = '''
|
||||
@echo off
|
||||
set "PathUser="
|
||||
for /F "skip=2 tokens=1,2*" %%G in ('%SystemRoot%\\System32\\reg.exe query "HKCU\\Environment" /v "Path" 2^>nul') do if /I "%%G" == "Path" (
|
||||
if /I "%%H" == "REG_EXPAND_SZ" (set "PathExpand=1" & set "PathUser=%%I") else if /I "%%H" == "REG_SZ" set "PathUser=%%I"
|
||||
)
|
||||
''';
|
||||
|
||||
@override
|
||||
Future add(String path) async {
|
||||
await ProcessExecutor.run(StringBuffer('setx path "%path%;$path"'));
|
||||
var shell = StringBuffer(setUserPath);
|
||||
shell.writeln('setx path "%PathUser%;$path');
|
||||
await ProcessExecutor.run(shell);
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
@override
|
||||
Future remove(String path) async {
|
||||
await ProcessExecutor.run(StringBuffer('setx path "%path:$path=%"'));
|
||||
var userPath = Platform.environment['UserProfile'];
|
||||
var pathTxt = File('$userPath\\path.txt');
|
||||
var shell = StringBuffer(setUserPath);
|
||||
shell.writeln('echo "%PathUser%" > ${pathTxt.path}');
|
||||
await ProcessExecutor.run(StringBuffer(shell));
|
||||
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
|
||||
if (pathTxt.existsSync()) {
|
||||
var contents = pathTxt.readAsStringSync();
|
||||
contents = contents.replaceAll(';$path', '');
|
||||
contents = contents.trimLeft();
|
||||
contents = contents.trimRight();
|
||||
print('New User Path =====> $contents');
|
||||
await ProcessExecutor.run(StringBuffer('setx path "$contents"'));
|
||||
pathTxt.deleteSync();
|
||||
}
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue