mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:07:35 +00:00
lsusb: Port to Core::Stream
This commit is contained in:
parent
880b35739e
commit
75208f2333
1 changed files with 11 additions and 6 deletions
|
@ -12,7 +12,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <LibUSBDB/Database.h>
|
#include <LibUSBDB/Database.h>
|
||||||
|
@ -48,14 +48,19 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
while (usb_devices.has_next()) {
|
while (usb_devices.has_next()) {
|
||||||
auto full_path = LexicalPath(usb_devices.next_full_path());
|
auto full_path = LexicalPath(usb_devices.next_full_path());
|
||||||
|
|
||||||
auto proc_usb_device = Core::File::construct(full_path.string());
|
auto proc_usb_device = Core::Stream::File::open(full_path.string(), Core::Stream::OpenMode::Read);
|
||||||
if (!proc_usb_device->open(Core::OpenMode::ReadOnly)) {
|
if (proc_usb_device.is_error()) {
|
||||||
warnln("Failed to open {}: {}", proc_usb_device->name(), proc_usb_device->error_string());
|
warnln("Failed to open {}: {}", full_path.string(), proc_usb_device.error());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto contents = proc_usb_device->read_all();
|
auto contents = proc_usb_device.value()->read_all();
|
||||||
auto json_or_error = JsonValue::from_string(contents);
|
if (contents.is_error()) {
|
||||||
|
warnln("Failed to read {}: {}", full_path.string(), contents.error());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto json_or_error = JsonValue::from_string(contents.value());
|
||||||
if (json_or_error.is_error()) {
|
if (json_or_error.is_error()) {
|
||||||
warnln("Failed to decode JSON: {}", json_or_error.error());
|
warnln("Failed to decode JSON: {}", json_or_error.error());
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue