aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/vcpkg_System.h
blob: 14f39ca40d9e6f5a88160aa6fb202298e89f935f (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once

#include "vcpkg_Strings.h"
#include "filesystem_fs.h"
#include "vcpkg_optional.h"

namespace vcpkg::System
{
    fs::path get_exe_path_of_current_process();

    struct exit_code_and_output
    {
        int exit_code;
        std::string output;
    };

    int cmd_execute(const wchar_t* cmd_line);

    inline int cmd_execute(const std::wstring& cmd_line)
    {
        return cmd_execute(cmd_line.c_str());
    }

    exit_code_and_output cmd_execute_and_capture_output(const wchar_t* cmd_line);

    inline exit_code_and_output cmd_execute_and_capture_output(const std::wstring& cmd_line)
    {
        return cmd_execute_and_capture_output(cmd_line.c_str());
    }

    std::wstring create_powershell_script_cmd(const fs::path& script_path);

    std::wstring create_powershell_script_cmd(const fs::path& script_path, const std::wstring& args);

    enum class color
    {
        success = 10,
        error = 12,
        warning = 14,
    };

    void print(const char* message);
    void println(const char* message);
    void print(const color c, const char* message);
    void println(const color c, const char* message);

    inline void print(const std::string& message)
    {
        return print(message.c_str());
    }

    inline void println(const std::string& message)
    {
        return println(message.c_str());
    }

    inline void print(const color c, const std::string& message)
    {
        return print(c, message.c_str());
    }

    inline void println(const color c, const std::string& message)
    {
        return println(c, message.c_str());
    }

    template <class...Args>
    void print(const char* messageTemplate, const Args&... messageArgs)
    {
        return print(Strings::format(messageTemplate, messageArgs...).c_str());
    }

    template <class...Args>
    void print(const color c, const char* messageTemplate, const Args&... messageArgs)
    {
        return print(c, Strings::format(messageTemplate, messageArgs...).c_str());
    }

    template <class...Args>
    void println(const char* messageTemplate, const Args&... messageArgs)
    {
        return println(Strings::format(messageTemplate, messageArgs...).c_str());
    }

    template <class...Args>
    void println(const color c, const char* messageTemplate, const Args&... messageArgs)
    {
        return println(c, Strings::format(messageTemplate, messageArgs...).c_str());
    }

    optional<std::wstring> get_environmental_variable(const wchar_t* varname) noexcept;

    void set_environmental_variable(const wchar_t* varname, const wchar_t* varvalue) noexcept;
}