Explorar o código

Expose FileSystem.ScanDisk to script

Matt Benic %!s(int64=8) %!d(string=hai) anos
pai
achega
50611551b6

+ 29 - 0
Script/AtomicNET/AtomicNET/IO/FileNameIterator.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+namespace AtomicEngine
+{
+
+    public partial class FileNameIterator : IEnumerable<string>
+    {
+        public IEnumerator<string> GetEnumerator()
+        {
+            Reset();
+            while (MoveNext())
+            {
+                yield return GetCurrent();
+            }
+        }
+
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            Reset();
+            while (MoveNext())
+            {
+                yield return GetCurrent();
+            }
+        }
+    }
+
+
+}

+ 1 - 1
Script/Packages/Atomic/IO.json

@@ -1,7 +1,7 @@
 {
 {
 	"name" : "IO",
 	"name" : "IO",
 	"sources" : ["Source/Atomic/IO"],
 	"sources" : ["Source/Atomic/IO"],
-	"classes" : ["Log", "File", "FileSystem", "FileWatcher", "BufferQueue", "PackageFile"],
+	"classes" : ["Log", "File", "FileSystem", "FileWatcher", "BufferQueue", "PackageFile", "FileNameIterator"],
 	"interfaces" : ["Serializer", "Deserializer", "AbstractFile"],
 	"interfaces" : ["Serializer", "Deserializer", "AbstractFile"],
 	"overloads" : {
 	"overloads" : {
 		"File" : {
 		"File" : {

+ 32 - 0
Source/Atomic/IO/FileSystem.cpp

@@ -1081,6 +1081,8 @@ bool IsAbsolutePath(const String& pathName)
 }
 }
 
 
 // ATOMIC BEGIN
 // ATOMIC BEGIN
+
+
 bool FileSystem::CreateDirs(const String& root, const String& subdirectory)
 bool FileSystem::CreateDirs(const String& root, const String& subdirectory)
 {
 {
     String folder = AddTrailingSlash(GetInternalPath(root));
     String folder = AddTrailingSlash(GetInternalPath(root));
@@ -1335,6 +1337,36 @@ bool GetRelativePath(const String& fromPath, const String& toPath, String& outpu
 
 
 }
 }
 
 
+FileNameIterator::FileNameIterator()
+{
+    Reset();
+}
+
+const String& FileNameIterator::GetCurrent()
+{
+    return (index_ < filenames_.Size()) ?
+        filenames_[index_] :
+        String::EMPTY;
+}
+
+bool FileNameIterator::MoveNext()
+{
+    return ++index_ < filenames_.Size();
+}
+
+void FileNameIterator::Reset()
+{
+    index_ = -1;
+}
+
+SharedPtr<FileNameIterator> FileSystem::ScanDir(const String& pathName, const String& filter, unsigned flags, bool recursive) const
+{
+    SharedPtr<FileNameIterator> enumerator(new FileNameIterator());
+    ScanDir(enumerator->filenames_, pathName, filter, flags, recursive);
+
+    return enumerator;
+}
+
 // ATOMIC END
 // ATOMIC END
 
 
 }
 }

+ 22 - 0
Source/Atomic/IO/FileSystem.h

@@ -38,6 +38,26 @@ static const unsigned SCAN_DIRS = 0x2;
 /// Return also hidden files.
 /// Return also hidden files.
 static const unsigned SCAN_HIDDEN = 0x4;
 static const unsigned SCAN_HIDDEN = 0x4;
 
 
+// ATOMIC BEGIN
+
+/// Helper class to expose resource iteration to script
+class FileNameIterator : public RefCounted
+{
+    ATOMIC_REFCOUNTED(FileNameIterator);
+public:
+    FileNameIterator();
+
+    const String& GetCurrent();
+    bool MoveNext();
+    void Reset();
+
+    Vector<String> filenames_;
+private:
+    unsigned index_;
+};
+
+// ATOMIC END
+
 /// Subsystem for file and directory operations and access control.
 /// Subsystem for file and directory operations and access control.
 class ATOMIC_API FileSystem : public Object
 class ATOMIC_API FileSystem : public Object
 {
 {
@@ -103,6 +123,8 @@ public:
     String GetAppPreferencesDir(const String& org, const String& app) const;
     String GetAppPreferencesDir(const String& org, const String& app) const;
 
 
 // ATOMIC BEGIN
 // ATOMIC BEGIN
+    /// Scan specified files, returning them as an iterator
+    SharedPtr<FileNameIterator> ScanDir(const String& pathName, const String& filter, unsigned flags, bool recursive) const;
 
 
     /// Check if a file or directory exists at the specified path
     /// Check if a file or directory exists at the specified path
     bool Exists(const String& pathName) const { return FileExists(pathName) || DirExists(pathName); }
     bool Exists(const String& pathName) const { return FileExists(pathName) || DirExists(pathName); }