Skip to content

Commit

Permalink
(cli) implement micro patches command
Browse files Browse the repository at this point in the history
  • Loading branch information
melo936 committed Aug 11, 2024
1 parent a7f40e7 commit 856ed50
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 65 deletions.
52 changes: 52 additions & 0 deletions lib/commands/playbook_patches_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'dart:async';
import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:revitool/services/registry_utils_service.dart';
import 'package:revitool/services/updates_service.dart';
import 'package:win32_registry/win32_registry.dart';

class PlaybookPatchesCommand extends Command<String> {
static final _updatesService = UpdatesService();

static const tag = "[Playbook Patches]";

@override
String get description {
return '[$tag] A command to apply micro patches to the ReviOS system';
}

@override
String get name => 'playbook-patches';

PlaybookPatchesCommand() {
argParser.addCommand('apply');
}

@override
FutureOr<String>? run() async {
switch (argResults?.command?.name) {
case 'apply':
await applyPatches();
break;
default:
stdout.writeln('''
Something went wrong. Please try again.
''');
exit(1);
}
exit(0);
}

Future<void> applyPatches() async {
// remove 'OneDrive' from explorer TODO: Remove this section after a new PB is released
RegistryUtilsService.writeDword(
Registry.classesRoot,
r'CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
'System.IsPinnedToNameSpaceTree',
0);

// After July 2024 Windows updates, modifying 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' seems to crash the process of applying playbook
_updatesService.enablePauseUpdatesWU();
}
}
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:mixin_logger/mixin_logger.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:revitool/commands/ms_store_command.dart';
import 'package:revitool/commands/playbook_patches_command.dart';
import 'package:revitool/commands/recommendation_command.dart';
import 'package:revitool/commands/security_command.dart';
import 'package:revitool/commands/win_package_command.dart';
Expand Down Expand Up @@ -58,7 +59,8 @@ Future<void> main(List<String> args) async {
final runner = CommandRunner<String>("revitool", "Revision Tool CLI")
..addCommand(MSStoreCommand())
..addCommand(DefenderCommand())
..addCommand(WindowsPackageCommand());
..addCommand(WindowsPackageCommand())
..addCommand(PlaybookPatchesCommand());
// ..addCommand(RecommendationCommand());
await runner.run(args);
exit(0);
Expand Down
5 changes: 5 additions & 0 deletions lib/services/registry_utils_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class RegistryUtilsService {

static bool get isSupported {
return _validate() ||
readString(
RegistryHive.localMachine,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion',
'EditionSubVersion') ==
'ReviOS' ||
readString(
RegistryHive.localMachine,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion',
Expand Down
10 changes: 4 additions & 6 deletions lib/services/win_package_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';
import 'package:collection/collection.dart';
import 'package:path/path.dart' as p;
import 'package:process_run/shell.dart';
import 'package:revitool/commands/playbook_patches_command.dart';

import 'package:revitool/services/network_service.dart';
import 'package:revitool/services/registry_utils_service.dart';
Expand Down Expand Up @@ -80,12 +81,9 @@ class WinPackageService {

Future<void> installPackage(final WinPackageType packageType) async {
if (packageType == WinPackageType.systemComponentsRemoval) {
// remove 'OneDrive' from explorer TODO: Remove this section after a new PB is released
RegistryUtilsService.writeDword(
Registry.classesRoot,
r'CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
'System.IsPinnedToNameSpaceTree',
0);
// TODO: Remove this section after a new PB is released
final pbPatches = PlaybookPatchesCommand();
await pbPatches.applyPatches();
}

if (!await File("$directoryExe\\cab-installer.ps1").exists()) {
Expand Down
Loading

0 comments on commit 856ed50

Please sign in to comment.