diff options
author | Johannes Schickel | 2013-11-07 12:58:35 +0100 |
---|---|---|
committer | D G Turner | 2013-11-24 00:48:01 +0000 |
commit | c00ab00f250205dc76890965562f5b661055826a (patch) | |
tree | eb25346daf3e8ef2e043c1429e373fa984515905 | |
parent | 19a20ad71fb8b57504f54786b39ba481dd1400b0 (diff) | |
download | scummvm-rg350-c00ab00f250205dc76890965562f5b661055826a.tar.gz scummvm-rg350-c00ab00f250205dc76890965562f5b661055826a.tar.bz2 scummvm-rg350-c00ab00f250205dc76890965562f5b661055826a.zip |
DEVTOOLS: Factor out function to create directories in create_project.
-rw-r--r-- | devtools/create_project/create_project.cpp | 27 | ||||
-rw-r--r-- | devtools/create_project/create_project.h | 7 | ||||
-rw-r--r-- | devtools/create_project/xcode.cpp | 31 |
3 files changed, 35 insertions, 30 deletions
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 <sys/param.h> #include <sys/stat.h> #include <dirent.h> +#include <errno.h> #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 @@ -341,6 +341,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 * the node. "children" does contain all the node's children. 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 <fstream> #include <algorithm> -#if defined(_WIN32) || defined(WIN32) -#include <windows.h> -#else -#include <sys/param.h> -#include <sys/stat.h> -#include <dirent.h> -#include <errno.h> -#endif - namespace CreateProjectTool { #define DEBUG_XCODE_HASH 0 @@ -88,27 +79,7 @@ XCodeProvider::XCodeProvider(StringList &global_warnings, std::map<std::string, void XCodeProvider::createWorkspace(const BuildSetup &setup) { // Create project folder std::string workspace = setup.outputDir + '/' + PROJECT_NAME ".xcodeproj"; - -#if defined(_WIN32) || defined(WIN32) - if (!CreateDirectory(workspace.c_str(), NULL)) - if (GetLastError() != ERROR_ALREADY_EXISTS) - error("Could not create folder \"" + setup.outputDir + '/' + PROJECT_NAME ".xcodeproj\""); -#else - if (mkdir(workspace.c_str(), 0777) == -1) { - if (errno == EEXIST) { - // Try to open as a folder (might be a file / symbolic link) - DIR *dirp = opendir(workspace.c_str()); - if (dirp == NULL) { - error("Could not create folder \"" + setup.outputDir + '/' + PROJECT_NAME ".xcodeproj\""); - } else { - // The folder exists, just close the stream and return - closedir(dirp); - } - } else { - error("Could not create folder \"" + setup.outputDir + '/' + PROJECT_NAME ".xcodeproj\""); - } - } -#endif + createDirectory(workspace); // Setup global objects setupDefines(setup); |