From b3d72bc1f0e4555432789b0d9f9aeff8dc2e2d7b Mon Sep 17 00:00:00 2001 From: Yehuda Kremer Date: Wed, 4 Nov 2020 12:26:22 +0200 Subject: [PATCH] code refactoring --- lib/msix.dart | 11 ++++++++--- lib/src/configuration.dart | 27 ++++++++++++++++++--------- lib/src/constants.dart | 3 ++- lib/src/msixFiles.dart | 28 +++++++++++++++++----------- lib/src/utils.dart | 3 ++- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/lib/msix.dart b/lib/msix.dart index 16f5851..3da2ac3 100644 --- a/lib/msix.dart +++ b/lib/msix.dart @@ -39,12 +39,16 @@ class Msix { print(white('singing.... ')); var signResults = await _sign(); - if (!signResults.stdout.toString().contains('Number of files successfully Signed: 1') && + if (!signResults.stdout + .toString() + .contains('Number of files successfully Signed: 1') && signResults.stderr.toString().length > 0) { print(red(signResults.stdout)); print(red(signResults.stderr)); - if (signResults.stdout.toString().contains('Error: SignerSign() failed.') && + if (signResults.stdout + .toString() + .contains('Error: SignerSign() failed.') && !isNullOrStringNull(_configuration.certificateSubject)) { printCertificateSubjectHelp(); } @@ -66,7 +70,8 @@ class Msix { } Future _pack() async { - var msixPath = '${_configuration.buildFilesFolder}\\${_configuration.appName}.msix'; + var msixPath = + '${_configuration.buildFilesFolder}\\${_configuration.appName}.msix'; var makeappxPath = '${_configuration.msixToolkitPath()}/Redist.${_configuration.architecture}/makeappx.exe'; diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index 6e1a5c2..3402df4 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -12,7 +12,8 @@ class Configuration { String msixVersion = '1.0.0.0'; String appDescription; String certificateSubject; - String buildFilesFolder = '${Directory.current.path}/build/windows/runner/Release'; + String buildFilesFolder = + '${Directory.current.path}/build/windows/runner/Release'; String certificatePath; String certificatePassword; String displayName; @@ -40,13 +41,17 @@ class Configuration { publisherName = pubspec['msix_config']['publisher_name'].toString(); identityName = pubspec['msix_config']['identity_name'].toString(); msixVersion = pubspec['msix_config']['msix_version'].toString(); - certificateSubject = pubspec['msix_config']['certificate_subject'].toString(); + certificateSubject = + pubspec['msix_config']['certificate_subject'].toString(); certificatePath = pubspec['msix_config']['certificate_path'].toString(); - certificatePassword = pubspec['msix_config']['certificate_password'].toString(); + certificatePassword = + pubspec['msix_config']['certificate_password'].toString(); logoPath = pubspec['msix_config']['logo_path'].toString(); - startMenuIconPath = pubspec['msix_config']['start_menu_icon_path'].toString(); + startMenuIconPath = + pubspec['msix_config']['start_menu_icon_path'].toString(); tileIconPath = pubspec['msix_config']['tile_icon_path'].toString(); - iconsBackgroundColor = pubspec['msix_config']['icons_background_color'].toString(); + iconsBackgroundColor = + pubspec['msix_config']['icons_background_color'].toString(); architecture = pubspec['msix_config']['architecture'].toString(); } print(green('done!')); @@ -55,7 +60,8 @@ class Configuration { /// Get the assets folder path from the .packages file Future _getAssetsFolderPath() async { List packages = - (await File('${Directory.current.path}/.packages').readAsString()).split('\n'); + (await File('${Directory.current.path}/.packages').readAsString()) + .split('\n'); msixAssetsPath = packages .firstWhere((package) => package.contains('msix:')) @@ -109,7 +115,8 @@ class Configuration { print(yellow( 'https://drive.google.com/file/d/1oAsnrp2Kf-jZ_kaRjyF5llQ0YZy1IwNe/view?usp=sharing')); exit(0); - } else if (extension(certificatePath) == '.pfx' && isNullOrStringNull(certificatePassword)) + } else if (extension(certificatePath) == '.pfx' && + isNullOrStringNull(certificatePassword)) throw (red( 'Certificate password is empty, check "msix_config: certificate_password" at pubspec.yaml')); @@ -117,9 +124,11 @@ class Configuration { throw (red( 'Architecture can be "x86" or "x64", check "msix_config: architecture" at pubspec.yaml')); - if (!iconsBackgroundColor.contains('#')) iconsBackgroundColor = '#$iconsBackgroundColor'; + if (!iconsBackgroundColor.contains('#')) + iconsBackgroundColor = '#$iconsBackgroundColor'; if (!RegExp(r'^#(?:[0-9a-fA-F]{3}){1,2}$').hasMatch(iconsBackgroundColor)) - throw (red('Icons background color can be only in this format: "#ffffff"')); + throw (red( + 'Icons background color can be only in this format: "#ffffff"')); print(green('done!')); } diff --git a/lib/src/constants.dart b/lib/src/constants.dart index 75081ed..9083916 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -1,6 +1,7 @@ import 'package:ansicolor/ansicolor.dart'; -const String defaultCertificateSubject = 'CN=Msix Testing, O=Msix Testing Corporation, C=US'; +const String defaultCertificateSubject = + 'CN=Msix Testing, O=Msix Testing Corporation, C=US'; final AnsiPen white = AnsiPen()..white(bold: true); final AnsiPen red = AnsiPen()..red(bold: true); final AnsiPen green = AnsiPen()..green(bold: true); diff --git a/lib/src/msixFiles.dart b/lib/src/msixFiles.dart index b8404fa..4df4509 100644 --- a/lib/src/msixFiles.dart +++ b/lib/src/msixFiles.dart @@ -25,10 +25,11 @@ class MsixFiles { Future copyIcons() async { stdout.write(white('copy icons.. ')); - _configuration.logoPath = await _copyIcon( - _configuration.logoPath, File('${_configuration.defaultsIconsFolderPath()}/icon.png').path); + _configuration.logoPath = await _copyIcon(_configuration.logoPath, + File('${_configuration.defaultsIconsFolderPath()}/icon.png').path); - _configuration.startMenuIconPath = await _copyIcon(_configuration.startMenuIconPath, + _configuration.startMenuIconPath = await _copyIcon( + _configuration.startMenuIconPath, File('${_configuration.defaultsIconsFolderPath()}/44_44.png').path); _configuration.tileIconPath = await _copyIcon(_configuration.tileIconPath, @@ -72,7 +73,8 @@ class MsixFiles { '''; try { - await File('${_configuration.buildFilesFolder}\\AppxManifest.xml').create() + await File('${_configuration.buildFilesFolder}\\AppxManifest.xml') + .create() ..writeAsString(manifestContent); } catch (e) { throw (red('fail to create manifest file: $e')); @@ -87,8 +89,8 @@ class MsixFiles { _vCLibsFiles = await allDirectoryFiles( '${_configuration.vcLibsFolderPath()}/${_configuration.architecture}'); - _vCLibsFiles.forEach((file) async => - await File(file.path).copy('${_configuration.buildFilesFolder}/${basename(file.path)}')); + _vCLibsFiles.forEach((file) async => await File(file.path) + .copy('${_configuration.buildFilesFolder}/${basename(file.path)}')); print(green('done!')); } @@ -97,12 +99,16 @@ class MsixFiles { stdout.write(white('cleaning temporary files.. ')); try { - await File('${_configuration.buildFilesFolder}/AppxManifest.xml').delete(); - await Directory('${_configuration.buildFilesFolder}/icons').delete(recursive: true); - _vCLibsFiles.forEach((file) async => - await File('${_configuration.buildFilesFolder}/${basename(file.path)}').delete()); + await File('${_configuration.buildFilesFolder}/AppxManifest.xml') + .delete(); + await Directory('${_configuration.buildFilesFolder}/icons') + .delete(recursive: true); + _vCLibsFiles.forEach((file) async => await File( + '${_configuration.buildFilesFolder}/${basename(file.path)}') + .delete()); } catch (e) { - print(red('fail to clean temporary files from ${_configuration.buildFilesFolder}: $e')); + print(red( + 'fail to clean temporary files from ${_configuration.buildFilesFolder}: $e')); } print(green('done!')); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 385d589..f30a441 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -33,6 +33,7 @@ printTestCertificateHelp() { print(''); print(yellow( 'This msix installer is signed with TEST certificate,\nif you have not yet installed this test certificate please read the following guide:')); - print('https://www.advancedinstaller.com/install-test-certificate-from-msix.html'); + print( + 'https://www.advancedinstaller.com/install-test-certificate-from-msix.html'); print(''); }