From c1bb288f35cbeab74939b55c0e00b87db0678074 Mon Sep 17 00:00:00 2001 From: Sun Jiao Date: Mon, 4 Mar 2024 23:57:07 +0800 Subject: [PATCH] Add evb file builder (#6) --- .github/workflows/main.yml | 11 +- build.yaml | 5 + dev/windows_evb_config_generator.dart | 112 ++++++++ evb/renamer.evb | 377 -------------------------- 4 files changed, 124 insertions(+), 381 deletions(-) create mode 100644 build.yaml create mode 100644 dev/windows_evb_config_generator.dart delete mode 100644 evb/renamer.evb diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea9e900..d553e8a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,7 +67,6 @@ jobs: name: renamer-android path: build/app/outputs/flutter-apk - build-and-release-windows: runs-on: windows-latest @@ -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 @@ -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 diff --git a/build.yaml b/build.yaml new file mode 100644 index 0000000..5fba043 --- /dev/null +++ b/build.yaml @@ -0,0 +1,5 @@ +targets: + $default: + sources: + exclude: + - dev/**.dart diff --git a/dev/windows_evb_config_generator.dart b/dev/windows_evb_config_generator.dart new file mode 100644 index 0000000..d7a3a1e --- /dev/null +++ b/dev/windows_evb_config_generator.dart @@ -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 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); +} diff --git a/evb/renamer.evb b/evb/renamer.evb deleted file mode 100644 index 8bf1fcd..0000000 --- a/evb/renamer.evb +++ /dev/null @@ -1,377 +0,0 @@ - -<> - D:\a\renamer\renamer\build\windows\x64\runner\Release\renamer.exe - D:\a\renamer\renamer\renamer.exe - - True - False - False - - - 3 - %DEFAULT FOLDER% - 0 - False - False - 0 - - - 3 - data - 0 - False - False - 0 - - - 2 - app.so - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\app.so - False - False - 0 - False - False - False - 0 - - - 3 - flutter_assets - 0 - False - False - 0 - - - 2 - AssetManifest.bin - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\AssetManifest.bin - False - False - 0 - False - False - False - 0 - - - 2 - AssetManifest.json - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\AssetManifest.json - False - False - 0 - False - False - False - 0 - - - 3 - assets - 0 - False - False - 0 - - - 2 - desktop.png - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\assets\desktop.png - False - False - 0 - False - False - False - 0 - - - - - 2 - FontManifest.json - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\FontManifest.json - False - False - 0 - False - False - False - 0 - - - 3 - fonts - 0 - False - False - 0 - - - 2 - MaterialIcons-Regular.otf - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\fonts\MaterialIcons-Regular.otf - False - False - 0 - False - False - False - 0 - - - - - 2 - NOTICES.Z - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\NOTICES.Z - False - False - 0 - False - False - False - 0 - - - 3 - packages - 0 - False - False - 0 - - - 3 - fluttertoast - 0 - False - False - 0 - - - 3 - assets - 0 - False - False - 0 - - - 2 - toastify.css - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\packages\fluttertoast\assets\toastify.css - False - False - 0 - False - False - False - 0 - - - 2 - toastify.js - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\packages\fluttertoast\assets\toastify.js - False - False - 0 - False - False - False - 0 - - - - - - - 3 - iconsax_flutter - 0 - False - False - 0 - - - 3 - fonts - 0 - False - False - 0 - - - 2 - FlutterIconsax.ttf - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\packages\iconsax_flutter\fonts\FlutterIconsax.ttf - False - False - 0 - False - False - False - 0 - - - - - - - - - 3 - shaders - 0 - False - False - 0 - - - 2 - ink_sparkle.frag - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\flutter_assets\shaders\ink_sparkle.frag - False - False - 0 - False - False - False - 0 - - - - - - - 2 - icudtl.dat - D:\a\renamer\renamer\build\windows\x64\runner\Release\data\icudtl.dat - False - False - 0 - False - False - False - 0 - - - - - 2 - desktop_drop_plugin.dll - D:\a\renamer\renamer\build\windows\x64\runner\Release\desktop_drop_plugin.dll - False - False - 0 - False - False - False - 0 - - - 2 - flutter_windows.dll - D:\a\renamer\renamer\build\windows\x64\runner\Release\flutter_windows.dll - False - False - 0 - False - False - False - 0 - - - 2 - permission_handler_windows_plugin.dll - D:\a\renamer\renamer\build\windows\x64\runner\Release\permission_handler_windows_plugin.dll - False - False - 0 - False - False - False - 0 - - - 2 - url_launcher_windows_plugin.dll - D:\a\renamer\renamer\build\windows\x64\runner\Release\url_launcher_windows_plugin.dll - False - False - 0 - False - False - False - 0 - - - - - - - False - - - 1 - True - Classes - 0 - - - - - 1 - True - User - 0 - - - - - 1 - True - Machine - 0 - - - - - 1 - True - Users - 0 - - - - - 1 - True - Config - 0 - - - - - - - False - - - False - True - - True - False - - - - False - %DEFAULT FOLDER%\ - False - False - - -