Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
YehudaKremer committed Nov 4, 2020
1 parent 92bd129 commit b3d72bc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 25 deletions.
11 changes: 8 additions & 3 deletions lib/msix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -66,7 +70,8 @@ class Msix {
}

Future<ProcessResult> _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';

Expand Down
27 changes: 18 additions & 9 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!'));
Expand All @@ -55,7 +60,8 @@ class Configuration {
/// Get the assets folder path from the .packages file
Future<void> _getAssetsFolderPath() async {
List<String> 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:'))
Expand Down Expand Up @@ -109,17 +115,20 @@ 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'));

if (!['x86', 'x64'].contains(architecture))
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!'));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
28 changes: 17 additions & 11 deletions lib/src/msixFiles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class MsixFiles {
Future<void> 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,
Expand Down Expand Up @@ -72,7 +73,8 @@ class MsixFiles {
</Package>''';

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'));
Expand All @@ -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!'));
}
Expand All @@ -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!'));
Expand Down
3 changes: 2 additions & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}

0 comments on commit b3d72bc

Please sign in to comment.