Skip to content
Snippets Groups Projects
Mhwd.hpp 3.76 KiB
Newer Older
Philip Müller's avatar
Philip Müller committed
/*
 *  This file is part of the mhwd - Manjaro Hardware Detection project
 *  
dec's avatar
dec committed
 *  mhwd - Manjaro Hardware Detection
 *  Roland Singer <roland@manjaro.org>
 *  Łukasz Matysiak <december0123@gmail.com>
Philip Müller's avatar
Philip Müller committed
 *  Filipe Marques <eagle.software3@gmail.com>
Philip Müller's avatar
Philip Müller committed
 *
dec's avatar
dec committed
 *  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
 */

#ifndef MHWD_HPP_
#define MHWD_HPP_

december0123's avatar
december0123 committed
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <cstdio>
#include <cstdlib>
#include <memory>
#include <string>
#include <vector>

Philip Müller's avatar
Philip Müller committed
#include "Config.hpp"
#include "const.h"
Philip Müller's avatar
Philip Müller committed
#include "Data.hpp"
#include "Device.hpp"
#include "Enums.hpp"
#include "Printer.hpp"
#include "vita/string.hpp"
#include "Transaction.hpp"

class Mhwd
{
public:
    ~Mhwd() = default;
Philip Müller's avatar
Philip Müller committed
    void setVersionMhwd(std::string versionOfSoftware, std::string yearCopyright);
Philip Müller's avatar
Philip Müller committed
    int launch(int argc, char *argv[]);

private:
    struct Arguments
    {
        bool SHOW_PCI = false;
        bool SHOW_USB = false;
        bool INSTALL = false;
        bool REMOVE = false;
        bool DETAIL = false;
        bool FORCE = false;
        bool LIST_ALL = false;
        bool LIST_INSTALLED = false;
        bool LIST_AVAILABLE = false;
        bool LIST_HARDWARE = false;
        bool CUSTOM_INSTALL = false;
        bool AUTOCONFIGURE = false;
    } arguments_;
    std::shared_ptr<Config> config_;
    Data data_;
    Printer printer_;
    std::vector<std::string> configs_;
Philip Müller's avatar
Philip Müller committed
    std::string version_, year_;
december0123's avatar
december0123 committed
    bool performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONTYPE type);
Philip Müller's avatar
Philip Müller committed
    bool isUserRoot() const;
    std::vector<std::string> checkEnvironment() const;
Philip Müller's avatar
Philip Müller committed

    void printDeviceDetails(std::string type, FILE *f = stdout);
Philip Müller's avatar
Philip Müller committed

december0123's avatar
december0123 committed
    std::shared_ptr<Config> getInstalledConfig(const std::string& configName, const std::string& configType);
    std::shared_ptr<Config> getDatabaseConfig(const std::string& configName, const std::string& configType);
    std::shared_ptr<Config> getAvailableConfig(const std::string& configName, const std::string& configType);
Philip Müller's avatar
Philip Müller committed

    std::vector<Config*> getAllLocalRequirements(Config *config);

    MHWD::STATUS performTransaction(const Transaction& transaction);
    bool proceedWithInstallation(const std::string& input) const;
Philip Müller's avatar
Philip Müller committed

    bool copyDirectory(const std::string& source, const std::string& destination);
    bool copyFile(const std::string& source, const std::string destination, const mode_t mode =
december0123's avatar
december0123 committed
            S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH);
    bool removeDirectory(const std::string& directory);
    bool dirExists(const std::string& path) const;
    bool createDir(const std::string& path, const mode_t mode =
december0123's avatar
december0123 committed
            S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH);
Philip Müller's avatar
Philip Müller committed

december0123's avatar
december0123 committed
    MHWD::STATUS installConfig(std::shared_ptr<Config> config);
Philip Müller's avatar
Philip Müller committed
    MHWD::STATUS uninstallConfig(Config *config);
december0123's avatar
december0123 committed
    bool runScript(std::shared_ptr<Config> config, MHWD::TRANSACTIONTYPE operationType);
	void tryToParseCmdLineOptions(int argc, char* argv[], bool& autoConfigureNonFreeDriver,
			std::string& operationType, std::string& autoConfigureClassID);
	bool optionsDontInterfereWithEachOther() const;
Philip Müller's avatar
Philip Müller committed
};

#endif /* MHWD_HPP_ */