Explorar o código

String FileSystem::GetTemporaryDir() const API

Rokas Kupstys %!s(int64=8) %!d(string=hai) anos
pai
achega
eacf671d12
Modificáronse 2 ficheiros con 20 adicións e 0 borrados
  1. 18 0
      Source/Urho3D/IO/FileSystem.cpp
  2. 2 0
      Source/Urho3D/IO/FileSystem.h

+ 18 - 0
Source/Urho3D/IO/FileSystem.cpp

@@ -1067,4 +1067,22 @@ bool IsAbsolutePath(const String& pathName)
     return false;
 }
 
+String FileSystem::GetTemporaryDir() const
+{
+#if defined(_WIN32)
+    wchar_t pathName[MAX_PATH];
+    pathName[0] = 0;
+    GetTempPathW(SDL_arraysize(pathName), pathName);
+    return AddTrailingSlash(pathName);
+#else
+    if (char* pathName = getenv("TMPDIR"))
+        return AddTrailingSlash(pathName);
+#ifdef P_tmpdir
+    return AddTrailingSlash(P_tmpdir);
+#else
+    return "/tmp/";
+#endif
+#endif
+}
+
 }

+ 2 - 0
Source/Urho3D/IO/FileSystem.h

@@ -101,6 +101,8 @@ public:
     String GetUserDocumentsDir() const;
     /// Return the application preferences directory.
     String GetAppPreferencesDir(const String& org, const String& app) const;
+    /// Return path of temporary directory. Path always ends with a forward slash.
+    String GetTemporaryDir() const;
 
 private:
     /// Scan directory, called internally.