Skip to content

Commit

Permalink
Add evb file builder (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-jiao authored Mar 4, 2024
1 parent 882d14d commit c1bb288
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 381 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ jobs:
name: renamer-android
path: build/app/outputs/flutter-apk


build-and-release-windows:
runs-on: windows-latest

Expand All @@ -91,13 +90,17 @@ jobs:
node-version: 20
- name: install evb
run: npm install enigmavirtualbox -g
- name: create evb file
run: dart .\dev\windows_evb_config_generator.dart
- name: build single exe file
run: enigmavirtualbox cli ".\evb\renamer.evb"
run: enigmavirtualbox cli "renamer.evb"
- name: Windows Release
uses: actions/upload-artifact@v4
with:
name: renamer-win
path: renamer.exe
path: |
renamer.exe
renamer.evb
build-and-release-macos:
runs-on: macos-14
Expand Down Expand Up @@ -127,7 +130,7 @@ jobs:
path: build/macos/Build/Products/Release/renamer.dmg
- name: Build ios
run: |
flutter build ios --release --no-codesign
flutter build ios --release --no-codesign
ln -sf ./build/ios/iphoneos Payload
zip -r9 renamer-release.ipa Payload/runner.app
- name: ios Release
Expand Down
5 changes: 5 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
targets:
$default:
sources:
exclude:
- dev/**.dart
112 changes: 112 additions & 0 deletions dev/windows_evb_config_generator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import 'dart:io';

import 'package:xml/xml.dart';

void main() {
XmlBuilder builder = XmlBuilder();
builder.processing('xml', 'version="1.0" encoding="windows-1252"');
// evb needs absolute dir, in fact the relative dir works in wine, but not work on
// Windows runner of Github Actions. I cannot test it on a physical Windows machine.
final windowsBuildDir = Directory(r"build\windows\x64\runner\Release").absolute;
// use this for test: "build/linux/x64/release/bundle"
final entities = windowsBuildDir.listSync();
final input = entities.firstWhere((e) => e is File && e.path.endsWith('.exe'));
final output = File(input.name).absolute;
entities.removeWhere((e) => e is File && e.path.endsWith('.exe'));

builder.element('', nest: () {
builder.element('InputFile', nest: input.path);
builder.element('OutputFile', nest: output.path);
builder.element('Files', nest: () {
builder.element('Enabled', nest: 'True');
builder.element('DeleteExtractedOnExit', nest: 'False');
builder.element('CompressFiles', nest: 'False');
builder.element('Files', nest: () {
buildDir(builder, '%DEFAULT FOLDER%', entities);
});
});
builder.element('Registries', nest: () {
builder.element('Enabled', nest: 'False');
builder.element('Registries', nest: () {
buildRegistry(builder, 'Classes');
buildRegistry(builder, 'User');
buildRegistry(builder, 'Machine');
buildRegistry(builder, 'Users');
buildRegistry(builder, 'Config');
});
});
builder.element('Packaging', nest: () {
builder.element('Enabled', nest: 'False');
});
builder.element('Options', nest: () {
builder.element('ShareVirtualSystem', nest: 'False');
builder.element('MapExecutableWithTemporaryFile', nest: 'True');
builder.element('TemporaryFileMask');
builder.element('AllowRunningOfVirtualExeFiles', nest: 'True');
builder.element('ProcessesOfAnyPlatforms', nest: 'False');
});
builder.element('Storage', nest: () {
builder.element('Files', nest: () {
builder.element('Enabled', nest: 'False');
builder.element('Folder', nest: '%DEFAULT FOLDER%\\');
builder.element('RandomFileNames', nest: 'False');
builder.element('EncryptContent', nest: 'False');
});
});
});

final document = builder.buildDocument();
File('renamer.evb').writeAsStringSync(document.toXmlString(pretty: true), mode: FileMode.append);
}

void buildFile(XmlBuilder builder, String name, String path) {
builder.element('File', nest: () {
builder.element('Type', nest: 2);
builder.element('Name', nest: name);
builder.element('File', nest: path);
builder.element('ActiveX', nest: 'False');
builder.element('ActiveXInstall', nest: 'False');
builder.element('Action', nest: 0);
builder.element('OverwriteDateTime', nest: 'False');
builder.element('OverwriteAttributes', nest: 'False');
builder.element('PassCommandLine', nest: 'False');
builder.element('HideFromDialogs', nest: 0);
});
}

void buildDir(XmlBuilder builder, String name, List<FileSystemEntity> entities) {
builder.element('File', nest: () {
builder.element('Type', nest: 3);
builder.element('Name', nest: name);
builder.element('Action', nest: 0);
builder.element('OverwriteDateTime', nest: 'False');
builder.element('OverwriteAttributes', nest: 'False');
builder.element('HideFromDialogs', nest: 0);
builder.element('Files', nest: () {
entities.sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
for (final entity in entities) {
if (entity is Directory) {
buildDir(builder, entity.name, entity.listSync());
} else if (entity is File) {
buildFile(builder, entity.name, entity.absolute.path);
}
}
});
});
}

void buildRegistry(XmlBuilder builder, String name) {
builder.element('Registry', nest: () {
builder.element('Type', nest: 1);
builder.element('Virtual', nest: 'True');
builder.element('Name', nest: name);
builder.element('ValueType', nest: 0);
builder.element('Value');
builder.element('Registries');
});
}

extension on FileSystemEntity {
// get file name
String get name => path.substring(path.lastIndexOf(Platform.pathSeparator) + 1);
}
Loading

0 comments on commit c1bb288

Please sign in to comment.