diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp index 58b8cf0611..3ef3635bbe 100644 --- a/Applications/Welcome/main.cpp +++ b/Applications/Welcome/main.cpp @@ -24,16 +24,21 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include +#include #include +#include #include #include #include #include #include +#include #include #include #include +#include #include #include @@ -47,46 +52,77 @@ struct ContentPage { Vector content; }; +Optional> parse_welcome_file(const String& path) +{ + const auto error = Optional>(); + auto file = Core::File::construct(path); + + if (!file->open(Core::IODevice::ReadOnly)) + return error; + + Vector pages; + StringBuilder current_output_line; + bool started = false; + ContentPage current; + while (true) { + auto buffer = file->read_line(4096); + if (buffer.is_null()) { + if (file->error()) { + file->close(); + return error; + } else { + break; + } + } + + auto line = String((char*)buffer.data()); + if (line.length() > 1) + line = line.substring(0, line.length() - 1); // remove newline + switch (line[0]) { + case '*': + dbg() << "menu_item line:\t" << line; + if (started) + pages.append(current); + else + started = true; + + current = {}; + current.menu_name = line.substring(2, line.length() - 2); + break; + case '>': + dbg() << "title line:\t" << line; + current.title = line.substring(2, line.length() - 2); + break; + case '\n': + dbg() << "newline"; + + if (current_output_line.to_string() != String::empty()) + current.content.append(current_output_line.to_string()); + current_output_line.clear(); + break; + case '#': + dbg() << "comment line:\t" << line; + break; + default: + dbg() << "content line:\t" << line; + if (current_output_line.length() != 0) + current_output_line.append(' '); + current_output_line.append(line); + break; + } + } + + if (started) { + current.content.append(current_output_line.to_string()); + pages.append(current); + } + + file->close(); + return pages; +} + int main(int argc, char** argv) { - Vector pages = { - { - "Welcome", - "Welcome", - { - "Welcome to the exciting new world of Serenity, where the year is 1998 and the leading OS vendor has decided to merge their flagship product with a Unix-like kernel.", - "Sit back and relax as you take a brief tour of the options available on this screen.", - "If you want to explore an option, just click it.", - }, - }, - { - "Register Now", - "Register Now!", - { - "Registering your copy of Serenity opens the doors to full integration of Serenity into your life, your being, and your soul.", - "By registering Serenity, you enter into the draw to win a lifetime supply of milk, delivered fresh each day by a mystical horse wearing a full tuxedo.", - "To register, simply write your contact details on a piece of paper and hold it up to your monitor.", - }, - }, - { - "Connect to the Internet", - "Connect to the Internet", - { - "On the Internet, you can correspond through electronic mail (e-mail), get the latest news and financial information, and visit Web sites around the world, most of which will make you really angry.", - "Serenity includes several internet applications, such as an IRC (Internet relay chat) client, 4chan browser, telnet server, and basic utilities like ping.", - "Come chat with us today! How bad can it be?", - }, - }, - { - "Have fun", - "Play Some Games!", - { - "Serenity includes several games built right into the base system. These include the classic game Snake and the anti-productivity mainstay Minesweeper.", - "With a little extra effort, you can even play the original id Software hit DOOM, albeit without sound. No sound just means you won't alert your boss, so it's more of a feature than a limitation.", - }, - }, - }; - if (pledge("stdio shared_buffer rpath unix cpath fattr", nullptr) < 0) { perror("pledge"); return 1; @@ -99,12 +135,20 @@ int main(int argc, char** argv) return 1; } - if (unveil("/res/fonts", "r") < 0) { + if (unveil("/res", "r") < 0) { perror("unveil"); return 1; } + unveil(nullptr, nullptr); + Optional> _pages = parse_welcome_file("/res/welcome.txt"); + if (!_pages.has_value()) { + GUI::MessageBox::show("Could not open Welcome file.", "Welcome", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, nullptr); + return 1; + } + auto pages = _pages.value(); + auto window = GUI::Window::construct(); window->set_title("Welcome to Serenity"); Gfx::Rect window_rect { 0, 0, 640, 360 }; diff --git a/Base/res/welcome.txt b/Base/res/welcome.txt new file mode 100644 index 0000000000..ce7fd219d0 --- /dev/null +++ b/Base/res/welcome.txt @@ -0,0 +1,41 @@ +* Welcome +> Welcome to SerenityOS! +Welcome to the exciting new world of Serenity, where the year is 1998 and the +leading OS vendor has decided to merge their flagship product with a Unix-like +kernel. + +Sit back and relax as you take a brief tour of the options available on this +screen. + +If you want to explore an option, just click it. + +* Registration +> Register now! +Registering your copy of Serenity opens the doors to full integration of +Serenity into your life, your being, and your soul. + +By registering Serenity, you enter into the draw to win a lifetime supply of +milk, delivered fresh each day by a mystical horse wearing a full tuxedo. + +To register, simply write your contact details on a piece of paper and hold it +up to your monitor. + +* Internet +> Connect to the Internet! +On the Internet, you can correspond through electronic mail (e-mail), get the +latest news and financial information, and visit Web sites around the world, +most of which will make you really angry. + +Serenity includes several internet applications, such as an IRC (Internet relay +chat) client, 4chan browser, telnet server, and basic utilities like ping. + +Come chat with us today! How bad can it be? + +* Fun & Games +> Play some games! +Serenity includes several games built right into the base system. These include +the classic game Snake and the anti-productivity mainstay Minesweeper. + +With a little extra effort, you can even play the original id Software hit DOOM, +albeit without sound. No sound just means you won't alert your boss, so it's +more of a feature than a limitation.