~aleteoryx/muditaos

ref: master muditaos/module-services/service-fileindexer/Common.hpp -rw-r--r-- 1.1 KiB
2cd0e472 — Lefucjusz [BH-000] Update Harmony 2.10.0 changelog 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <array>
#include <algorithm>
#include <filesystem>
#include <array>

namespace service::detail
{
    namespace fs = std::filesystem;

    // File extensions indexing allow list
    constexpr std::array<std::string_view, 3> allowed_exts{".wav", ".mp3", ".flac"};

    // This is debug feature, it overrides allowed extension types above
    constexpr bool allow_all_exts = false;

    inline bool isExtSupported(const fs::path &path)
    {
        if (allow_all_exts) {
            return true;
        }

        return std::any_of(allowed_exts.begin(), allowed_exts.end(), [&path](const fs::path &ext) {
            if (path.has_extension() && path.extension() == ext) {
                return true;
            }
            // if empty string with extension only
            if (path == ext) {
                return true;
            }
            return false;
        });
    }
} // namespace service::detail