Browse Source

Implemented file_setCurrentPath.

David Piuva 3 years ago
parent
commit
f45bd1d20a
3 changed files with 14 additions and 3 deletions
  1. 10 0
      Source/DFPSR/api/fileAPI.cpp
  2. 3 2
      Source/DFPSR/api/fileAPI.h
  3. 1 1
      Source/SDK/guiExample/main.cpp

+ 10 - 0
Source/DFPSR/api/fileAPI.cpp

@@ -179,6 +179,16 @@ bool file_hasRoot(const ReadableString &path) {
 	#endif
 }
 
+bool file_setCurrentPath(const ReadableString &path) {
+	Buffer buffer;
+	const NativeChar *nativePath = toNativeString(file_optimizePath(path), buffer);
+	#ifdef USE_MICROSOFT_WINDOWS
+		return SetCurrentDirectoryW(nativePath);
+	#else
+		return chdir(nativePath) == 0;
+	#endif
+}
+
 String file_getCurrentPath() {
 	#ifdef USE_MICROSOFT_WINDOWS
 		NativeChar resultBuffer[maxLength + 1] = {0};

+ 3 - 2
Source/DFPSR/api/fileAPI.h

@@ -130,14 +130,15 @@ namespace dsr {
 
 	// Get the current path, from where the application was called and relative paths start.
 	String file_getCurrentPath();
+	// Sets the current path to file_optimizePath(path).
+	// Returns true on success and false on failure.
+	bool file_setCurrentPath(const ReadableString &path);
 	// Get the application's folder path, from where the application is stored.
 	// If not implemented and allowFallback is true,
 	//   the current path is returned instead as a qualified guess instead of raising an exception.
 	String file_getApplicationFolder(bool allowFallback = true);
 	// Gets an absolute version of the path, quickly without removing redundancy.
 	String file_getAbsolutePath(const ReadableString &path);
-	// Returns true iff path refers to a valid file or folder.
-	bool file_exists(const ReadableString& path);
 }
 
 #endif

+ 1 - 1
Source/SDK/guiExample/main.cpp

@@ -15,7 +15,7 @@ DSR_MAIN_CALLER(dsrMain)
 int dsrMain(List<String> args) {
 	// Set current path to the application folder, so that it's safe to use relative paths for loading GUI resources.
 	// Loading and saving files will automatically convert / and \ to the local format using file_optimizePath, so that you can use them directly in relative paths.
-	//file_setCurrentPath(file_getApplicationFolder());
+	file_setCurrentPath(file_getApplicationFolder());
 
 	// Create a window
 	window = window_create(U"GUI example", 1000, 700);