-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
71 lines (59 loc) · 2.23 KB
/
main.cpp
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
#include <filesystem>
#ifdef WIN32
#include <windows.h>
#endif
#include <nowide/args.hpp>
#include <nowide/cstdlib.hpp>
#include <nowide/iostream.hpp>
#include <nowide/convert.hpp>
#include "read.h"
#include "write.h"
enum class ExitCode : uint8_t {
Okay,
MissingArg,
InvalidDirectory,
UnhandledError
};
int main(int argc, char* argv[]) {
nowide::args args ( argc, argv );
#ifdef WIN32
SetConsoleCP(65001); // UTF-8 on Windows
#endif
std::filesystem::path pluginDbPath;
if (argc >= 2) {
pluginDbPath = nowide::widen(argv[1]);
} else {
std::string homeDir { nowide::getenv("UserProfile") };
if (homeDir.empty()) {
nowide::cerr << "Please pass the path to your plugin database as the first arg.";
return static_cast<int>(ExitCode::MissingArg);
}
// Assumes we're on Windows
pluginDbPath = homeDir + R"(\Documents\Image-Line\FL Studio\Presets\Plugin database)";
}
if (!std::filesystem::exists(pluginDbPath)) {
nowide::cerr << "Directory does not exist: " << pluginDbPath.string() << std::endl;
return static_cast<int>(ExitCode::InvalidDirectory);
}
if (!std::filesystem::is_directory(pluginDbPath)) {
nowide::cerr << "Given path is not a directory: " << pluginDbPath.string() << std::endl;
return static_cast<int>(ExitCode::InvalidDirectory);
}
std::filesystem::path installedPluginDbPath = pluginDbPath / "Installed";
if (!std::filesystem::exists(installedPluginDbPath)) {
nowide::cerr << "Directory does not exist: " << installedPluginDbPath.string() << std::endl;
return static_cast<int>(ExitCode::InvalidDirectory);
}
if (!std::filesystem::is_directory(installedPluginDbPath)) {
nowide::cerr << "Given path is not a directory: " << installedPluginDbPath.string() << std::endl;
return static_cast<int>(ExitCode::InvalidDirectory);
}
try {
PluginByVendorMap pluginMap = walkDirectories(installedPluginDbPath);
writeToPluginDatabase(pluginDbPath, pluginMap);
} catch (std::exception &err) {
nowide::cerr << err.what();
return static_cast<int>(ExitCode::UnhandledError);
}
return static_cast<int>(ExitCode::Okay);
}