mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
Welcome: Port to Core::Stream
This commit is contained in:
parent
bd66453e8d
commit
ca54a965a0
2 changed files with 19 additions and 18 deletions
|
@ -8,7 +8,8 @@
|
||||||
#include <AK/Random.h>
|
#include <AK/Random.h>
|
||||||
#include <Applications/Welcome/WelcomeWindowGML.h>
|
#include <Applications/Welcome/WelcomeWindowGML.h>
|
||||||
#include <LibConfig/Client.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
|
#include <LibCore/Stream.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/CheckBox.h>
|
#include <LibGUI/CheckBox.h>
|
||||||
|
@ -76,30 +77,30 @@ WelcomeWidget::WelcomeWidget()
|
||||||
};
|
};
|
||||||
|
|
||||||
open_and_parse_readme_file();
|
open_and_parse_readme_file();
|
||||||
open_and_parse_tips_file();
|
if (auto result = open_and_parse_tips_file(); result.is_error()) {
|
||||||
|
auto error = String::formatted("Opening \"{}/tips.txt\" failed: {}", Core::StandardPaths::documents_directory(), result.error());
|
||||||
|
m_tip_label->set_text(error);
|
||||||
|
warnln(error);
|
||||||
|
}
|
||||||
|
|
||||||
set_random_tip();
|
set_random_tip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WelcomeWidget::open_and_parse_tips_file()
|
ErrorOr<void> WelcomeWidget::open_and_parse_tips_file()
|
||||||
{
|
{
|
||||||
auto file = Core::File::construct("/home/anon/Documents/tips.txt");
|
auto path = String::formatted("{}/tips.txt", Core::StandardPaths::documents_directory());
|
||||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||||
m_tip_label->set_text("~/Documents/tips.txt has gone missing!");
|
auto buffered_file = TRY(Core::Stream::BufferedFile::create(move(file)));
|
||||||
return;
|
Array<u8, PAGE_SIZE> buffer;
|
||||||
}
|
|
||||||
|
|
||||||
while (file->can_read_line()) {
|
while (TRY(buffered_file->can_read_line())) {
|
||||||
auto line = file->read_line();
|
auto line = TRY(buffered_file->read_line(buffer));
|
||||||
auto* ch = line.characters();
|
if (line.starts_with('#') || line.is_empty())
|
||||||
switch (*ch) {
|
|
||||||
case '\n':
|
|
||||||
case '\r':
|
|
||||||
case '\0':
|
|
||||||
case '#':
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
m_tips.append(line);
|
m_tips.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void WelcomeWidget::open_and_parse_readme_file()
|
void WelcomeWidget::open_and_parse_readme_file()
|
||||||
|
|
|
@ -21,7 +21,7 @@ private:
|
||||||
virtual void paint_event(GUI::PaintEvent&) override;
|
virtual void paint_event(GUI::PaintEvent&) override;
|
||||||
|
|
||||||
void set_random_tip();
|
void set_random_tip();
|
||||||
void open_and_parse_tips_file();
|
ErrorOr<void> open_and_parse_tips_file();
|
||||||
void open_and_parse_readme_file();
|
void open_and_parse_readme_file();
|
||||||
|
|
||||||
RefPtr<GUI::Button> m_close_button;
|
RefPtr<GUI::Button> m_close_button;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue