~aleteoryx/muditaos

e7f176ac31767811416de74d755b6609145c87ac — Jakub Pyszczak 5 years ago a617397
[EGD-4927] Change new filesystem

Due to vfs deprecation there is need to remove all vfs calls from code. This PR covers module apps.
M module-apps/application-music-player/ApplicationMusicPlayer.cpp => module-apps/application-music-player/ApplicationMusicPlayer.cpp +11 -15
@@ 5,11 5,12 @@
#include "windows/MusicPlayerAllSongsWindow.hpp"
#include "windows/MusicPlayerEmptyWindow.hpp"

#include <service-audio/AudioServiceAPI.hpp>
#include <i18n/i18n.hpp>
#include <filesystem>
#include <log/log.hpp>
#include <i18n/i18n.hpp>
#include <purefs/filesystem_paths.hpp>
#include <service-audio/AudioServiceAPI.hpp>
#include <time/ScopedTime.hpp>
#include <vfs.hpp>

namespace app
{


@@ 65,26 66,21 @@ namespace app

    std::vector<audio::Tags> ApplicationMusicPlayer::getMusicFilesList()
    {
        const char *musicFolder = USER_PATH("music");
        const auto musicFolder = purefs::dir::getUserDiskPath() / "music";
        std::vector<audio::Tags> musicFiles;
        LOG_INFO("Scanning music folder: %s", musicFolder);
        std::vector<vfs::DirectoryEntry> dirList;
        {
            auto time = utils::time::Scoped("listdir time");
            dirList   = vfs.listdir(musicFolder, "");
        }
        LOG_INFO("Scanning music folder: %s", musicFolder.c_str());
        {
            auto time = utils::time::Scoped("fetch tags time");
            for (vfs::DirectoryEntry ent : dirList) {
                if (ent.attributes != vfs::FileAttributes::Directory) {
                    const auto filePath = std::string(musicFolder) + "/" + ent.fileName;
            for (const auto &entry : std::filesystem::directory_iterator(musicFolder)) {
                if (!std::filesystem::is_directory(entry)) {
                    const auto filePath = entry.path();
                    auto fileTags       = getFileTags(filePath);
                    if (fileTags) {
                        musicFiles.push_back(*fileTags);
                        LOG_DEBUG(" - file %s found", ent.fileName.c_str());
                        LOG_DEBUG(" - file %s found", entry.path().c_str());
                    }
                    else {
                        LOG_ERROR("Not an audio file %s", ent.fileName.c_str());
                        LOG_ERROR("Not an audio file %s", entry.path().c_str());
                    }
                }
            }

M module-apps/application-settings-new/windows/QuotesMainWindow.cpp => module-apps/application-settings-new/windows/QuotesMainWindow.cpp +27 -10
@@ 10,19 10,17 @@
#include <InputEvent.hpp>
#include <i18n/i18n.hpp>
#include <json/json11.hpp>
#include <vfs.hpp>
#include <purefs/filesystem_paths.hpp>
#include <Utils.hpp>
#include <string>

namespace gui
{
    namespace quotes
    {
        inline static std::string path = "sys/data/applications/settings/quotes.json";
    } // namespace quotes

    QuotesMainWindow::QuotesMainWindow(app::Application *app) : BaseSettingsWindow(app, gui::window::name::quotes)
    {
        const auto quotesPath = purefs::dir::getCurrentOSPath() / "data/applications/settings/quotes.json";
        setTitle(utils::localize.get("app_settings_display_locked_screen_quotes"));
        readQuotes(quotes::path);
        readQuotes(quotesPath);
    }

    auto QuotesMainWindow::onInput(const InputEvent &inputEvent) -> bool


@@ 47,9 45,8 @@ namespace gui
    {
        std::string err;

        std::string fileContents = vfs.loadFileAsString(fn);

        auto obj = json11::Json::parse(fileContents, err).array_items();
        const auto fileContents = readFileToString(fn);
        auto obj                = json11::Json::parse(fileContents.c_str(), err).array_items();

        if (!err.empty()) {
            LOG_ERROR("Error while parsing quotes: %s", err.c_str());


@@ 90,4 87,24 @@ namespace gui
        optionSwitch = !optionSwitch;
        rebuildOptionList();
    }

    std::string QuotesMainWindow::readFileToString(const fs::path &fn)
    {
        constexpr auto tar_buf = 8192 * 4;
        auto file              = std::fopen(fn.c_str(), "r");
        if (!file) {
            return {};
        }
        const auto length = utils::filesystem::filelength(file);
        if (length >= tar_buf) {
            LOG_ERROR("File %s length is too high!", fn.c_str());
            std::fclose(file);
            return {};
        }
        auto buffer = std::make_unique<char[]>(length + 1);
        std::fread(buffer.get(), 1, length, file);
        std::fclose(file);
        return std::string(buffer.get());
    }

} // namespace gui

M module-apps/application-settings-new/windows/QuotesMainWindow.hpp => module-apps/application-settings-new/windows/QuotesMainWindow.hpp +1 -1
@@ 5,7 5,6 @@

#include "BaseSettingsWindow.hpp"

#include <vfs.hpp>

namespace gui
{


@@ 24,6 23,7 @@ namespace gui
      private:
        void readQuotes(fs::path fn);
        void switchHandler(bool &optionSwitch);
        [[nodiscard]] static std::string readFileToString(const fs::path &fn);

        std::list<std::pair<std::string, bool>> quotes;
    };