Data.hpp 3.78 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
#include <string>
#include <vector>

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

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

Łukasz Matysiak's avatar
Łukasz Matysiak committed
47 48
    struct Environment
    {
december0123's avatar
december0123 committed
49 50 51 52
            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
53 54
    };

december0123's avatar
december0123 committed
55
    Environment environment;
december0123's avatar
december0123 committed
56 57 58 59 60 61 62
    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
63

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

december0123's avatar
december0123 committed
67 68 69 70 71 72 73 74
    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
75 76

private:
december0123's avatar
december0123 committed
77 78
    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
79
    void fillInstalledConfigs(std::string type);
80
    void fillDevices(hw_item hw, std::vector<std::shared_ptr<Device>>& devices);
december0123's avatar
december0123 committed
81
    void fillAllConfigs(std::string type);
december0123's avatar
december0123 committed
82 83 84
    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
85
            bool setAsInstalled);
86
    void addConfigSorted(std::vector<std::shared_ptr<Config>>& configs, std::shared_ptr<Config> newConfig);
87
    std::vector<std::string> getRecursiveDirectoryFileList(const std::string& directoryPath,
december0123's avatar
december0123 committed
88
            std::string onlyFilename = "");
Philip Müller's avatar
Philip Müller committed
89

december0123's avatar
december0123 committed
90 91
    Vita::string getRightConfigPath(Vita::string str, Vita::string baseConfigPath);
    void updateConfigData();
Philip Müller's avatar
Philip Müller committed
92 93

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

#endif /* DATA_HPP_ */