From c00ab00f250205dc76890965562f5b661055826a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 7 Nov 2013 12:58:35 +0100 Subject: DEVTOOLS: Factor out function to create directories in create_project. --- devtools/create_project/create_project.cpp | 27 ++++++++++++++++++++++++++ devtools/create_project/create_project.h | 7 +++++++ devtools/create_project/xcode.cpp | 31 +----------------------------- 3 files changed, 35 insertions(+), 30 deletions(-) (limited to 'devtools/create_project') diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index ad3160d778..026cbe07a4 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #endif namespace { @@ -1121,6 +1122,32 @@ FileList listDirectory(const std::string &dir) { return result; } +void createDirectory(const std::string &dir) { +#if defined(_WIN32) || defined(WIN32) + if (!CreateDirectory(dir.c_str(), NULL)) { + if (GetLastError() != ERROR_ALREADY_EXISTS) { + error("Could not create folder \"" + dir + "\""); + } + } +#else + if (mkdir(dir.c_str(), 0777) == -1) { + if (errno == EEXIST) { + // Try to open as a folder (might be a file / symbolic link) + DIR *dirp = opendir(dir.c_str()); + if (dirp == NULL) { + error("Could not create folder \"" + dir + "\""); + } else { + // The folder exists, just close the stream and return + closedir(dirp); + } + } else { + error("Could not create folder \"" + dir + "\""); + } + } +#endif + +} + /** * Scans the specified directory against files, which should be included * in the project files. It will not include files present in the exclude list. diff --git a/devtools/create_project/create_project.h b/devtools/create_project/create_project.h index 69ed551151..459342a67d 100644 --- a/devtools/create_project/create_project.h +++ b/devtools/create_project/create_project.h @@ -340,6 +340,13 @@ std::string toString(int num); */ FileList listDirectory(const std::string &dir); +/** + * Create a directory at the given path. + * + * @param dir The path to create. + */ +void createDirectory(const std::string &dir); + /** * Structure representing a file tree. This contains two * members: name and children. "name" holds the name of diff --git a/devtools/create_project/xcode.cpp b/devtools/create_project/xcode.cpp index a9b8e7a752..d95bf3e9ee 100644 --- a/devtools/create_project/xcode.cpp +++ b/devtools/create_project/xcode.cpp @@ -26,15 +26,6 @@ #include #include -#if defined(_WIN32) || defined(WIN32) -#include -#else -#include -#include -#include -#include -#endif - namespace CreateProjectTool { #define DEBUG_XCODE_HASH 0 @@ -88,27 +79,7 @@ XCodeProvider::XCodeProvider(StringList &global_warnings, std::map