summaryrefslogtreecommitdiffstats
path: root/source/OSSupport
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-10-09 09:57:48 +0200
committermadmaxoft <github@xoft.cz>2013-10-09 09:57:48 +0200
commit55999ee1187579179a70328808a4c856339ca97f (patch)
tree6335123ef5b8ff43b2e38e76282c45c61270b235 /source/OSSupport
parentAdded static cFile functions to Lua API. (diff)
downloadcuberite-55999ee1187579179a70328808a4c856339ca97f.tar
cuberite-55999ee1187579179a70328808a4c856339ca97f.tar.gz
cuberite-55999ee1187579179a70328808a4c856339ca97f.tar.bz2
cuberite-55999ee1187579179a70328808a4c856339ca97f.tar.lz
cuberite-55999ee1187579179a70328808a4c856339ca97f.tar.xz
cuberite-55999ee1187579179a70328808a4c856339ca97f.tar.zst
cuberite-55999ee1187579179a70328808a4c856339ca97f.zip
Diffstat (limited to 'source/OSSupport')
-rw-r--r--source/OSSupport/File.cpp29
-rw-r--r--source/OSSupport/File.h3
-rw-r--r--source/OSSupport/MakeDir.cpp25
-rw-r--r--source/OSSupport/MakeDir.h16
4 files changed, 24 insertions, 49 deletions
diff --git a/source/OSSupport/File.cpp b/source/OSSupport/File.cpp
index 16ec00e16..a3733933e 100644
--- a/source/OSSupport/File.cpp
+++ b/source/OSSupport/File.cpp
@@ -310,11 +310,11 @@ bool cFile::Copy(const AString & a_SrcFileName, const AString & a_DstFileName)
bool cFile::IsFolder(const AString & a_Path)
{
#ifdef _WIN32
- DWORD FileAttrib = GetFileAttributes(a_Path.c_str());
- return ((FileAttrib != INVALID_FILE_ATTRIBUTES) && ((FileAttrib & FILE_ATTRIBUTE_DIRECTORY) != 0));
+ DWORD FileAttrib = GetFileAttributes(a_Path.c_str());
+ return ((FileAttrib != INVALID_FILE_ATTRIBUTES) && ((FileAttrib & FILE_ATTRIBUTE_DIRECTORY) != 0));
#else
- struct stat st;
- return ((stat(a_Path.c_str(), &st) == 0) && S_ISDIR(st.st_mode));
+ struct stat st;
+ return ((stat(a_Path.c_str(), &st) == 0) && S_ISDIR(st.st_mode));
#endif
}
@@ -325,11 +325,11 @@ bool cFile::IsFolder(const AString & a_Path)
bool cFile::IsFile(const AString & a_Path)
{
#ifdef _WIN32
- DWORD FileAttrib = GetFileAttributes(a_Path.c_str());
- return ((FileAttrib != INVALID_FILE_ATTRIBUTES) && ((FileAttrib & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)) == 0));
+ DWORD FileAttrib = GetFileAttributes(a_Path.c_str());
+ return ((FileAttrib != INVALID_FILE_ATTRIBUTES) && ((FileAttrib & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)) == 0));
#else
- struct stat st;
- return ((stat(a_Path.c_str(), &st) == 0) && S_ISREG(st.st_mode));
+ struct stat st;
+ return ((stat(a_Path.c_str(), &st) == 0) && S_ISREG(st.st_mode));
#endif
}
@@ -351,6 +351,19 @@ int cFile::GetSize(const AString & a_FileName)
+bool cFile::CreateFolder(const AString & a_FolderPath)
+{
+ #ifdef _WIN32
+ return (CreateDirectory(a_FolderPath.c_str(), NULL) != 0);
+ #else
+ return (mkdir(a_FolderPath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) == 0);
+ #endif
+}
+
+
+
+
+
int cFile::Printf(const char * a_Fmt, ...)
{
AString buf;
diff --git a/source/OSSupport/File.h b/source/OSSupport/File.h
index f47bd4041..9fef25ace 100644
--- a/source/OSSupport/File.h
+++ b/source/OSSupport/File.h
@@ -118,6 +118,9 @@ public:
/// Returns the size of the file, or a negative number on error
static int GetSize(const AString & a_FileName);
+ /// Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute
+ static bool CreateFolder(const AString & a_FolderPath);
+
// tolua_end
int Printf(const char * a_Fmt, ...);
diff --git a/source/OSSupport/MakeDir.cpp b/source/OSSupport/MakeDir.cpp
deleted file mode 100644
index 10ccfe9ec..000000000
--- a/source/OSSupport/MakeDir.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "MakeDir.h"
-
-
-
-
-
-void cMakeDir::MakeDir(const AString & a_Directory)
-{
-#ifdef _WIN32
- SECURITY_ATTRIBUTES Attrib;
- Attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
- Attrib.lpSecurityDescriptor = NULL;
- Attrib.bInheritHandle = false;
- ::CreateDirectory( (FILE_IO_PREFIX + a_Directory).c_str(), &Attrib);
-#else
- mkdir( (FILE_IO_PREFIX + a_Directory).c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
-#endif
-}
-
-
-
-
diff --git a/source/OSSupport/MakeDir.h b/source/OSSupport/MakeDir.h
deleted file mode 100644
index e66cf1071..000000000
--- a/source/OSSupport/MakeDir.h
+++ /dev/null
@@ -1,16 +0,0 @@
-
-#pragma once
-
-
-
-
-
-class cMakeDir
-{
-public:
- static void MakeDir(const AString & a_Directory);
-};
-
-
-
-