mirror of
https://github.com/hyprwm/hyprwayland-scanner.git
synced 2024-11-22 18:05: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
46
src/main.cpp
46
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";
|
||||||
header << COPYRIGHT << HEADER;
|
const auto CPATH = outpath + "/" + PROTO_DATA.fileName + ".cpp";
|
||||||
header.close();
|
bool needsToWriteHeader = true, needsToWriteSource = true;
|
||||||
std::ofstream source(outpath + "/" + PROTO_DATA.fileName + ".cpp", std::ios::trunc);
|
|
||||||
source << COPYRIGHT << SOURCE;
|
if (std::filesystem::exists(HPATH)) {
|
||||||
source.close();
|
// 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.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needsToWriteSource) {
|
||||||
|
std::ofstream source(CPATH, std::ios::trunc);
|
||||||
|
source << COPYRIGHT << SOURCE;
|
||||||
|
source.close();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue