From 31d6cee09b1ad47a507f0e48733f7f32079a69b3 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 3 Feb 2025 11:54:48 -0700 Subject: [PATCH] Change out the file selector --- README.md | 3 +- cli/nbtcli.dart | 2 +- lib/Consts2.dart | 2 +- lib/Editor.dart | 36 ++++++++++++------- lib/pages/SNBTEditor.dart | 3 +- linux/flutter/generated_plugin_registrant.cc | 4 +++ linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 4 +-- pubspec.yaml | 5 +-- .../flutter/generated_plugin_registrant.cc | 3 ++ windows/flutter/generated_plugins.cmake | 1 + 11 files changed, 42 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index be63180..021c815 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The following is the build instructions for this project. 4. To build the installer you will need Inno Setup installed. 5. Add the path you installed IS to your path. 6. Run compile.bat to both build and generate the setup file which will be placed into the out folder. +7. Enable Developer Mode if you wish to run the output # MacOS @@ -36,6 +37,6 @@ The following is the build instructions for this project. 2. Install XCode 3. Install any necessary command line developer tools from XCode 4. Developer mode? -5. Run the command? `flutter build mac` or `flutter build macos` +5. Run the command `flutter build macos` **Testing needed** I do not own a Mac, testing by a Mac user will be required. diff --git a/cli/nbtcli.dart b/cli/nbtcli.dart index d7908be..727f854 100644 --- a/cli/nbtcli.dart +++ b/cli/nbtcli.dart @@ -12,7 +12,7 @@ Future main(List args) async { if (parsed.hasArg("help") || parsed.count == 0) { // Print help information print( - "NBT Editor Command Line Interface\nCopyright 2025 Piccari Creations\nLicensed under the GPL\nVersion: ${VERSION}\n\n"); + "NBT Editor Command Line Interface\nCopyright 2025 Piccari Creations\nLicensed under the GPL\nVersion: $VERSION\n\n"); var defaults = ArgumentsBuilder.builder() .withArgument(BoolArgument(name: "help", value: null)) diff --git a/lib/Consts2.dart b/lib/Consts2.dart index d2c2374..d39d3d1 100644 --- a/lib/Consts2.dart +++ b/lib/Consts2.dart @@ -1 +1 @@ -const VERSION = "1.1.020225+1616"; +const VERSION = "1.1.020325+1153"; diff --git a/lib/Editor.dart b/lib/Editor.dart index fc12590..36d6de4 100644 --- a/lib/Editor.dart +++ b/lib/Editor.dart @@ -1,6 +1,6 @@ import 'dart:typed_data'; -import 'package:file_picker/file_picker.dart'; +import 'package:file_selector/file_selector.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_treeview/flutter_treeview.dart'; @@ -16,7 +16,6 @@ import 'package:nbteditor/Constants.dart'; import 'package:nbteditor/Consts2.dart'; import 'package:nbteditor/SessionData.dart'; import 'package:nbteditor/main.dart'; -import 'package:nbteditor/pages/EditValue.dart'; import 'package:nbteditor/tags/ArrayEntry.dart'; import 'package:nbteditor/tags/CompoundTag.dart'; import 'package:nbteditor/tags/Tag.dart'; @@ -118,12 +117,15 @@ class EditorState extends State { Navigator.pushNamed(context, "/perms"); return; } + XTypeGroup typeGroup = const XTypeGroup( + label: 'NBT', extensions: ["nbt", "snbt", "dat"]); + var result = + await openFile(acceptedTypeGroups: [typeGroup]); String? filePath; - var result = await FilePicker.platform.pickFiles(); if (result != null) { // Do something with the selected file path print('Selected file path: $filePath'); - filePath = result.files.first.path; + filePath = result.path; } else { // User canceled the picker print('File selection canceled.'); @@ -136,8 +138,9 @@ class EditorState extends State { CompoundTag ct = CompoundTag(); if (filePath.endsWith(".txt") || filePath.endsWith(".snbt")) { ct = await SnbtIo.readFromFile(filePath) as CompoundTag; - } else + } else { ct = await NbtIo.read(filePath); + } SessionData.ROOT_TAG = ct; } @@ -190,11 +193,11 @@ class EditorState extends State { // Prompt for where to save print("Begin picking file to save to"); - var FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0)); + var FSL = await getSaveLocation(); String? filePath; if (FSL != null) { - filePath = FSL; + filePath = FSL.path; } if (filePath == null) { @@ -203,12 +206,15 @@ class EditorState extends State { } print(filePath); CompoundTag tag = controller.children[0].data as CompoundTag; + Uint8List data = Uint8List(0); if (result == null) { // Save uncompressed - NbtIo.write(filePath, tag); + data = await NbtIo.writeToStream(tag); } else { - NbtIo.writeCompressed(filePath, tag); + data = await NbtIo.writeToStreamCompressed(tag); } + var dataFile = XFile.fromData(data); + await dataFile.saveTo(filePath); }, ), ListTile( @@ -224,11 +230,11 @@ class EditorState extends State { } // Prompt for where to save print("Begin picking file to save to"); - var FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0)); + var FSL = await getSaveLocation(); String? filePath; if (FSL != null) { - filePath = FSL; + filePath = FSL.path; } if (filePath == null) { @@ -236,9 +242,13 @@ class EditorState extends State { return; } print(filePath); + Uint8List data = Uint8List(0); - SnbtIo.writeToFile( - filePath, controller.children[0].data as CompoundTag); + String str = SnbtIo.writeToString( + controller.children[0].data as CompoundTag); + + var dataFile = XFile.fromData(Uint8List.fromList(str.codeUnits)); + await dataFile.saveTo(filePath); }, ) ]), diff --git a/lib/pages/SNBTEditor.dart b/lib/pages/SNBTEditor.dart index b685405..ace6bec 100644 --- a/lib/pages/SNBTEditor.dart +++ b/lib/pages/SNBTEditor.dart @@ -7,7 +7,6 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart'; import 'package:libacflutter/Prompt.dart'; import 'package:nbteditor/Constants.dart'; import 'package:nbteditor/SessionData.dart'; -import 'package:nbteditor/pages/EditValue.dart'; class SnbtEdit extends StatefulWidget { const SnbtEdit({super.key}); @@ -46,7 +45,7 @@ class SnbtState extends State { type: InputPromptType.Text); }); }, - icon: Icon(CupertinoIcons.search)) + icon: const Icon(CupertinoIcons.search)) ], ), floatingActionButton: ElevatedButton( diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index f6f23bf..7299b5c 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,9 +6,13 @@ #include "generated_plugin_registrant.h" +#include #include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); + file_selector_plugin_register_with_registrar(file_selector_linux_registrar); g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index f16b4c3..786ff5c 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + file_selector_linux url_launcher_linux ) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 9e433e9..4e44bc8 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,10 +5,10 @@ import FlutterMacOS import Foundation -import file_picker +import file_selector_macos import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin")) + FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.yaml b/pubspec.yaml index 450eeee..1410082 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,13 +1,12 @@ name: nbteditor description: A Minecraft NBT Editor written in Flutter publish_to: "none" -version: 1.1.020225+1616 +version: 1.1.020325+1153 environment: sdk: ^3.6.1 dependencies: - file_picker: ^8.0.6 flutter: sdk: flutter flutter_code_editor: ^0.3.2 @@ -23,7 +22,9 @@ dependencies: libacflutter: hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/ version: ^1.0.013125+1423 + file_selector: ^1.0.3 + flutter_highlight: any dev_dependencies: flutter_test: sdk: flutter diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index a0d0bbe..4e586f9 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,10 +6,13 @@ #include "generated_plugin_registrant.h" +#include #include #include void RegisterPlugins(flutter::PluginRegistry* registry) { + FileSelectorWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FileSelectorWindows")); PermissionHandlerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index c20a586..1119879 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + file_selector_windows permission_handler_windows url_launcher_windows )