mirror of
https://github.com/hyprwm/hyprwayland-scanner.git
synced 2024-11-22 23:45:58 +01:00
core: don't overwrite files if they are the same
This commit is contained in:
parent
43d27dae69
commit
9ab8ea2d62
1 changed files with 40 additions and 6 deletions
38
src/main.cpp
38
src/main.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
struct SRequestArgument {
|
struct SRequestArgument {
|
||||||
std::string CType;
|
std::string CType;
|
||||||
|
@ -731,12 +732,45 @@ int main(int argc, char** argv, char** envp) {
|
||||||
parseHeader();
|
parseHeader();
|
||||||
parseSource();
|
parseSource();
|
||||||
|
|
||||||
std::ofstream header(outpath + "/" + PROTO_DATA.fileName + ".hpp", std::ios::trunc);
|
const auto HPATH = outpath + "/" + PROTO_DATA.fileName + ".hpp";
|
||||||
|
const auto CPATH = outpath + "/" + PROTO_DATA.fileName + ".cpp";
|
||||||
|
bool needsToWriteHeader = true, needsToWriteSource = true;
|
||||||
|
|
||||||
|
if (std::filesystem::exists(HPATH)) {
|
||||||
|
// check if we need to overwrite
|
||||||
|
|
||||||
|
std::ifstream headerIn(HPATH);
|
||||||
|
std::string content((std::istreambuf_iterator<char>(headerIn)), (std::istreambuf_iterator<char>()));
|
||||||
|
|
||||||
|
if (content == COPYRIGHT + HEADER)
|
||||||
|
needsToWriteHeader = false;
|
||||||
|
|
||||||
|
headerIn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::filesystem::exists(CPATH)) {
|
||||||
|
// check if we need to overwrite
|
||||||
|
|
||||||
|
std::ifstream sourceIn(CPATH);
|
||||||
|
std::string content((std::istreambuf_iterator<char>(sourceIn)), (std::istreambuf_iterator<char>()));
|
||||||
|
|
||||||
|
if (content == COPYRIGHT + SOURCE)
|
||||||
|
needsToWriteHeader = false;
|
||||||
|
|
||||||
|
sourceIn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needsToWriteHeader) {
|
||||||
|
std::ofstream header(HPATH, std::ios::trunc);
|
||||||
header << COPYRIGHT << HEADER;
|
header << COPYRIGHT << HEADER;
|
||||||
header.close();
|
header.close();
|
||||||
std::ofstream source(outpath + "/" + PROTO_DATA.fileName + ".cpp", std::ios::trunc);
|
}
|
||||||
|
|
||||||
|
if (needsToWriteSource) {
|
||||||
|
std::ofstream source(CPATH, std::ios::trunc);
|
||||||
source << COPYRIGHT << SOURCE;
|
source << COPYRIGHT << SOURCE;
|
||||||
source.close();
|
source.close();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue