forked from royqh1979/RedPanda-CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
231 lines (188 loc) · 6.14 KB
/
utils.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* Copyright (C) 2020-2022 Roy Qu ([email protected])
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef UTILS_H
#define UTILS_H
#include <type_traits>
#include <utility>
#include <functional>
#include <QString>
#include <QRect>
#include <QStringList>
#include <memory>
#include <QThread>
#include <QProcessEnvironment>
#include <QTemporaryFile>
#define SI_NO_CONVERSION
#include "SimpleIni.h"
#include "qt_utils/utils.h"
#ifdef Q_OS_WIN
#include <windows.h>
#endif
using SimpleIni = CSimpleIniA;
using PSimpleIni = std::shared_ptr<SimpleIni>;
enum class FileType{
GAS, // GNU assembler source file (.s)
LUA, // lua file (.lua)
CSource, // c source file (.c)
CppSource, // c++ source file (.cpp)
CHeader, // c header (.h)
CppHeader, // c++ header (.hpp)
WindowsResourceSource, // resource source (.res)
Project, //Red Panda C++ Project (.dev)
Text, // text file
FragmentShader,
VerticeShader,
ModuleDef, // Windows Module Definition
Other // any others
};
enum class SearchFileScope {
currentFile,
wholeProject,
openedFiles,
Folder
};
enum AutoSaveTarget {
astCurrentFile,
astAllOpennedFiles,
astAllProjectFiles
};
enum AutoSaveStrategy {
assOverwrite,
assAppendUnixTimestamp,
assAppendFormatedTimeStamp
};
enum FormatterBraceStyle {
fbsDefault,
fbsAllman,
fbsJava,
fbsKR,
fbsStroustrup,
fbsWitesmith,
fbsVtk,
fbsRatliff,
fbsGNU,
fbsLinux,
fbsHorstmann,
fbs1TBS,
fbsGoogle,
fbsMozilla,
fbsWebkit,
fbsPico,
fbsLisp
};
enum FormatterOperatorAlign {
foaNone,
foaType,
foaMiddle,
foaName
};
enum FormatterIndentType {
fitSpace,
fitTab
};
enum class SplitProcessCommandQuoteType {
None,
Single,
Double
};
enum class ProblemCaseValidateType {
Exact,
IgnoreLeadingTrailingSpaces,
IgnoreSpaces
};
struct NonExclusiveTemporaryFileOwner {
const QString filename;
// take ownership
explicit NonExclusiveTemporaryFileOwner(std::unique_ptr<QTemporaryFile> &tempFile);
NonExclusiveTemporaryFileOwner(const NonExclusiveTemporaryFileOwner &) = delete;
NonExclusiveTemporaryFileOwner(NonExclusiveTemporaryFileOwner &&) = delete;
NonExclusiveTemporaryFileOwner& operator=(const NonExclusiveTemporaryFileOwner &) = delete;
NonExclusiveTemporaryFileOwner& operator=(NonExclusiveTemporaryFileOwner &&) = delete;
~NonExclusiveTemporaryFileOwner();
};
using PNonExclusiveTemporaryFileOwner = std::unique_ptr<NonExclusiveTemporaryFileOwner>;
FileType getFileType(const QString& filename);
bool programHasConsole(const QString& filename);
QString parseMacros(const QString& s);
QString parseMacros(const QString& s, const QMap<QString, QString>& variables);
QMap<QString, QString> devCppMacroVariables();
class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1);
int getNewFileNumber();
struct ProcessOutput
{
QByteArray standardOutput;
QByteArray standardError;
QString errorMessage;
};
ProcessOutput runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,
const QByteArray& inputContent = QByteArray(),
bool separateStderr = false,
bool inheritEnvironment = false,
const QProcessEnvironment& env = QProcessEnvironment() );
void openFileFolderInExplorer(const QString& path);
void executeFile(const QString& fileName,
const QStringList& params,
const QString& workingDir,
const QString& tempFile);
#ifdef Q_OS_WIN
bool isGreenEdition();
#else
constexpr bool isGreenEdition() { return false; }
#endif
#ifdef Q_OS_WIN
bool readRegistry(HKEY key, const QString& subKey, const QString& name, QString& value);
#endif
qulonglong stringToHex(const QString& str, bool &isOk);
bool findComplement(const QString& s,
const QChar& fromToken,
const QChar& toToken,
int& curPos,
int increment);
bool haveGoodContrast(const QColor& c1, const QColor &c2);
QByteArray getHTTPBody(const QByteArray& content);
QString getSizeString(int size);
class QComboBox;
void setComboTextAndHistory(QComboBox *cb, const QString& newText, QStringList &historyList);
void updateComboHistory(QStringList &historyList, const QString &newKey);
QColor alphaBlend(const QColor &lower, const QColor &upper);
QStringList getExecutableSearchPaths();
QStringList platformCommandForTerminalArgsPreview();
QString appArch();
QString osArch();
QString byteArrayToString(const QByteArray &content, bool isUTF8);
QByteArray stringToByteArray(const QString& content, bool isUTF8);
#ifdef _MSC_VER
#define __builtin_unreachable() (__assume(0))
#endif
std::tuple<QString, QStringList, PNonExclusiveTemporaryFileOwner> wrapCommandForTerminalEmulator(const QString &terminal, const QStringList &argsPattern, const QStringList &payloadArgsWithArgv0);
std::tuple<QString, QStringList, PNonExclusiveTemporaryFileOwner> wrapCommandForTerminalEmulator(const QString &terminal, const QString &argsPattern, const QStringList &payloadArgsWithArgv0);
struct ExternalResource {
ExternalResource();
~ExternalResource();
};
template <typename T, typename D>
std::unique_ptr<T, D> resourcePointer(T *pointer, D deleter)
{
return {pointer, deleter};
}
#ifdef Q_OS_WINDOWS
bool applicationHasUtf8Manifest(const wchar_t *path);
bool osSupportsUtf8Manifest();
bool applicationIsUtf8(const QString &path);
#endif
#endif // UTILS_H