From fb79c54f1e6547985e8180d9fd5e2cc27ef6f919 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 30 May 2016 16:12:13 +0100 Subject: [PATCH] Added code to generate UUIDs using built-in operating system tools. --- source/common/uuid.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ source/common/uuid.h | 28 ++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 source/common/uuid.cpp create mode 100644 source/common/uuid.h diff --git a/source/common/uuid.cpp b/source/common/uuid.cpp new file mode 100644 index 0000000..2831e88 --- /dev/null +++ b/source/common/uuid.cpp @@ -0,0 +1,59 @@ +// uuid.cpp - UUID subroutines. +// +// (c) 2012-2015 Xestia Software Development. +// +// This file is part of Xestia Calendar. +// +// Xestia Calendar 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, version 3 of the license. +// +// Xestia Calendar 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 Xestia Calendar. If not, see + +#include "uuid.h" + +string GenerateUUID() +{ + +#if defined(__WIN32__) + +#include + + UUID UUIDData; + UuidCreate(&UUIDData); + wchar_t* UUIDStr = 0; + UuidToString(&UUIDData, (RPC_WSTR*)&UUIDStr); + wxString Result(UUIDStr); + +#elif defined(__HAIKU__) + +#else + +#include + + FILE *uuid_hdl = popen("uuidgen", "r"); + + if (uuid_hdl == NULL) { + return ""; + } + + char strdata[64]; + std::string uuidout; + + while (fgets(strdata, sizeof(strdata), uuid_hdl) != NULL){ + uuidout.append(strdata); + } + + pclose(uuid_hdl); + +#endif + + return uuidout; + +} \ No newline at end of file diff --git a/source/common/uuid.h b/source/common/uuid.h new file mode 100644 index 0000000..f406a79 --- /dev/null +++ b/source/common/uuid.h @@ -0,0 +1,28 @@ +// uuid.cpp - UUID subroutines header. +// +// (c) 2012-2015 Xestia Software Development. +// +// This file is part of Xestia Calendar. +// +// Xestia Calendar 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, version 3 of the license. +// +// Xestia Calendar 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 Calendar. If not, see + +#include + +using namespace std; + +#ifndef COMMON_UUID_H +#define COMMON_UUID_H + +string GenerateUUID(); + +#endif \ No newline at end of file -- 2.39.2