-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (55 loc) · 2.06 KB
/
main.cpp
File metadata and controls
60 lines (55 loc) · 2.06 KB
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
#include "utils.hpp"
#include "dir_item.hpp"
#include <iostream>
void TraverseDirectoryNR(const utils::fs::path &directory) {
std::queue<utils::fs::path> queue;
queue.push(directory);
while (not queue.empty()) {
utils::fs::path current{queue.front()};
queue.pop();
if (utils::fs::is_regular_file(current)) continue;
dir_item folder(current);
for (const auto &entry: utils::fs::directory_iterator(current)) {
auto wstr_filename{entry.path().filename().wstring()};
if (utils::EndsWith(wstr_filename, L".mnu")) {
utils::fs::remove(entry);
continue;
}
auto should_rename{entry.is_directory() and not utils::StartsWith(wstr_filename, L"A-")};
auto renamed_path{entry.path().parent_path() / (L"A-" + wstr_filename)};
if (should_rename) {
utils::fs::rename(entry, renamed_path);
}
queue.emplace(should_rename ? renamed_path : entry);
folder.add_child(should_rename ? renamed_path : entry);
}
folder.dump_to_file();
}
}
int main(int argc, char *argv[]) {
system("chcp 65001 > nul");
utils::fs::path gb_lib_home;
auto proLibraryDir{std::getenv("PRO_LIBRARY_DIR")};
if (not proLibraryDir) {
std::cout << "环境变量 PRO_LIBRARY_DIR 未设置" << std::endl;
if (argc == 1) {
std::cout << ", 程序并且缺少必要路径参数, 正在退出程序.." << std::endl;
exit(EXIT_FAILURE);
} else {
gb_lib_home = utils::fs::path(argv[1]);
if (not utils::fs::exists(gb_lib_home)) {
std::wcout << "路径 [" << gb_lib_home.wstring() << "] 不存在, 正在退出程序.." << std::endl;
exit(EXIT_FAILURE);
}
}
} else {
gb_lib_home = utils::fs::path(proLibraryDir);
}
std::cout << "- 正在生成 .mnu 文件" << std::endl;
TraverseDirectoryNR(gb_lib_home);
std::cout << "- OK\n- 运行 pro_build_library_ctg.exe" << std::endl;
system("%PRO_LIBRARY_DIR%\\pro_build_library_ctg.exe > nul");
std::cout << "- 完成" << std::endl;
system("pause");
return 0;
}