file_io.hpp 3.72 KB
Newer Older
Phobos D'thorga's avatar
Phobos D'thorga committed
1
/**
2
3
4
5
6
7
8
9
10
11
12
 **     __                 _ _   __    __           _     _ 
 **    / _\_ __ ___   __ _| | | / / /\ \ \___  _ __| | __| |
 **    \ \| '_ ` _ \ / _` | | | \ \/  \/ / _ \| '__| |/ _` |
 **    _\ \ | | | | | (_| | | |  \  /\  / (_) | |  | | (_| |
 **    \__/_| |_| |_|\__,_|_|_|   \/  \/ \___/|_|  |_|\__,_|
 **                                                         
 **                  ___     _                              
 **                 /   \___| |_   ___  _____               
 **                / /\ / _ \ | | | \ \/ / _ \              
 **               / /_//  __/ | |_| |>  <  __/              
 **              /___,' \___|_|\__,_/_/\_\___|              
Phobos D'thorga's avatar
Phobos D'thorga committed
13
14
15
16
17
18
 **                                                                 
 **
 **   If you have downloaded the source code for "Small World Deluxe" and are reading this,
 **   then thank you from the bottom of our hearts for making use of our hard work, sweat
 **   and tears in whatever you are implementing this into!
 **
Phobos D'thorga's avatar
Phobos D'thorga committed
19
 **   Copyright (C) 2020 - 2021. GekkoFyre.
Phobos D'thorga's avatar
Phobos D'thorga committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 **
 **   Small World Deluxe 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.
 **
 **   Small World 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 Small World Deluxe.  If not, see <http://www.gnu.org/licenses/>.
 **
 **
 **   The latest source code updates can be obtained from [ 1 ] below at your
 **   discretion. A web-browser or the 'git' application may be required.
 **
38
 **   [ 1 ] - https://code.gekkofyre.io/amateur-radio/small-world-deluxe
Phobos D'thorga's avatar
Phobos D'thorga committed
39
40
41
42
43
 **
 ****************************************************************************************************/
 
#pragma once

Phobos D'thorga's avatar
   
Phobos D'thorga committed
44
#include "src/defines.hpp"
Phobos D'thorga's avatar
Phobos D'thorga committed
45
46
#include <boost/filesystem.hpp>
#include <boost/exception/all.hpp>
47
48
#include <boost/random.hpp>
#include <boost/random/random_device.hpp>
Phobos D'thorga's avatar
Phobos D'thorga committed
49
#include <functional>
50
51
#include <algorithm>
#include <iterator>
Phobos D'thorga's avatar
Phobos D'thorga committed
52
#include <vector>
53
#include <random>
Phobos D'thorga's avatar
Phobos D'thorga committed
54
#include <string>
Phobos D'thorga's avatar
   
Phobos D'thorga committed
55
#include <memory>
56
57
#include <limits>
#include <array>
Phobos D'thorga's avatar
   
Phobos D'thorga committed
58
59
#include <QObject>
#include <QString>
Phobos D'thorga's avatar
Phobos D'thorga committed
60
61
62
63
64
65
66

namespace GekkoFyre {

class FileIo : public QObject {
    Q_OBJECT

public:
67
    explicit FileIo(QObject *parent = nullptr);
68
    ~FileIo() override;
Phobos D'thorga's avatar
Phobos D'thorga committed
69
70
71
72
73

    static std::vector<boost::filesystem::path> boost_dir_iterator(const boost::filesystem::path &dirPath, boost::system::error_code ec,
            const std::vector<std::string> &dirsToSkip = { });
    static bool checkSettingsExist(const bool &is_file, const boost::filesystem::path &fileName = GekkoFyre::Filesystem::fileName);

Phobos D'thorga's avatar
   
Phobos D'thorga committed
74
75
76
    void write_initial_settings(const QString &value, const GekkoFyre::Database::Settings::init_cfg &key);
    QString read_initial_settings(const GekkoFyre::Database::Settings::init_cfg &key);

77
    [[nodiscard]] size_t generateRandInteger(const size_t &min_integer_size, const size_t &max_integer_size,
Phobos D'thorga's avatar
   
Phobos D'thorga committed
78
                               const size_t &desired_result_less_than) const;
Phobos D'thorga's avatar
Phobos D'thorga committed
79

Phobos D'thorga's avatar
   
Phobos D'thorga committed
80
    std::string get_file_contents(const boost::filesystem::path &filePath);
Phobos D'thorga's avatar
   
Phobos D'thorga committed
81
    QString defaultDirectory(const QString &base_path, const bool &use_native_slashes = false,
82
                             const QString &append_dir = QString(General::companyName + QString("/") + Filesystem::defaultDirAppend));
Phobos D'thorga's avatar
   
Phobos D'thorga committed
83

Phobos D'thorga's avatar
Phobos D'thorga committed
84
85
86
87
88
protected:
    static std::vector<boost::filesystem::path> analyze_dir(const boost::filesystem::path &dirPath, const std::vector<std::string> &dirsToSkip = { });

};
};