Data.hpp 3.82 KB
Newer Older
Philip Müller's avatar
Philip Müller committed
1
/*
2 3
 *  This file is part of the mhwd - Manjaro Hardware Detection project
 *  
dec's avatar
dec committed
4 5 6
 *  mhwd - Manjaro Hardware Detection
 *  Roland Singer <roland@manjaro.org>
 *  Łukasz Matysiak <december0123@gmail.com>
Philip Müller's avatar
Philip Müller committed
7
 *  Filipe Marques <eagle.software3@gmail.com>
Philip Müller's avatar
Philip Müller committed
8
 *
dec's avatar
dec committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *  Copyright (C) 2007 Free Software Foundation, Inc.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
Philip Müller's avatar
Philip Müller committed
23 24 25 26 27
 */

#ifndef DATA_HPP_
#define DATA_HPP_

december0123's avatar
december0123 committed
28
#include <hd.h>
Philip Müller's avatar
Philip Müller committed
29 30
#include <sys/stat.h>
#include <sys/types.h>
december0123's avatar
december0123 committed
31

december0123's avatar
december0123 committed
32
#include <memory>
december0123's avatar
december0123 committed
33 34 35 36 37
#include <string>
#include <vector>

#include "Config.hpp"
#include "Device.hpp"
38 39
#include "const.h"
#include "vita/string.hpp"
december0123's avatar
december0123 committed
40

Philip Müller's avatar
Philip Müller committed
41 42
class Data {
public:
december0123's avatar
december0123 committed
43
    Data();
Łukasz Matysiak's avatar
Łukasz Matysiak committed
44
    ~Data() = default;
Philip Müller's avatar
Philip Müller committed
45 46

    struct Environment {
december0123's avatar
december0123 committed
47 48 49 50
            std::string PMCachePath {MHWD_PM_CACHE_DIR};
            std::string PMConfigPath {MHWD_PM_CONFIG};
            std::string PMRootPath {MHWD_PM_ROOT};
            bool syncPackageManagerDatabase = true;
december0123's avatar
december0123 committed
51 52
    };

december0123's avatar
december0123 committed
53
    Environment environment;
december0123's avatar
december0123 committed
54 55 56 57 58 59 60
    std::vector<std::shared_ptr<Device>> USBDevices;
    std::vector<std::shared_ptr<Device>> PCIDevices;
    std::vector<std::shared_ptr<Config>> installedUSBConfigs;
    std::vector<std::shared_ptr<Config>> installedPCIConfigs;
    std::vector<std::shared_ptr<Config>> allUSBConfigs;
    std::vector<std::shared_ptr<Config>> allPCIConfigs;
    std::vector<std::shared_ptr<Config>> invalidConfigs;
Philip Müller's avatar
Philip Müller committed
61

december0123's avatar
december0123 committed
62
    void updateInstalledConfigData();
december0123's avatar
december0123 committed
63
    void getAllDevicesOfConfig(std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices);
Philip Müller's avatar
Philip Müller committed
64

december0123's avatar
december0123 committed
65 66 67 68 69 70 71 72
    std::vector<std::shared_ptr<Config>> getAllDependenciesToInstall(std::shared_ptr<Config> config);
    void getAllDependenciesToInstall(std::shared_ptr<Config> config,
            std::vector<std::shared_ptr<Config>>& installedConfigs,
            std::vector<std::shared_ptr<Config>> *depends);
    std::shared_ptr<Config> getDatabaseConfig(const std::string configName,
            const std::string configType);
    std::vector<std::shared_ptr<Config>> getAllLocalConflicts(std::shared_ptr<Config> config);
    std::vector<std::shared_ptr<Config>> getAllLocalRequirements(std::shared_ptr<Config> config);
Philip Müller's avatar
Philip Müller committed
73 74

private:
december0123's avatar
december0123 committed
75 76
    void getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& devices,
            std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices);
december0123's avatar
december0123 committed
77 78 79
    void fillInstalledConfigs(std::string type);
    void fillDevices(std::string type);
    void fillAllConfigs(std::string type);
december0123's avatar
december0123 committed
80 81 82
    void setMatchingConfigs(const std::vector<std::shared_ptr<Device>>& devices,
            std::vector<std::shared_ptr<Config>>& configs, bool setAsInstalled);
    void setMatchingConfig(std::shared_ptr<Config> config, const std::vector<std::shared_ptr<Device>>& devices,
december0123's avatar
december0123 committed
83
            bool setAsInstalled);
december0123's avatar
december0123 committed
84
    void addConfigSorted(std::vector<std::shared_ptr<Config>>& configs, std::shared_ptr<Config> config);
85
    std::vector<std::string> getRecursiveDirectoryFileList(const std::string& directoryPath,
december0123's avatar
december0123 committed
86
            std::string onlyFilename = "");
Philip Müller's avatar
Philip Müller committed
87

december0123's avatar
december0123 committed
88 89 90
    Vita::string getRightConfigPath(Vita::string str, Vita::string baseConfigPath);
    std::vector<std::string> splitValue(Vita::string str, Vita::string onlyEnding = "");
    void updateConfigData();
Philip Müller's avatar
Philip Müller committed
91 92

    Vita::string from_Hex(uint16_t hexnum, int fill);
93
    std::string from_CharArray(char* c);
Philip Müller's avatar
Philip Müller committed
94 95 96
};

#endif /* DATA_HPP_ */