Пример #1
0
        private static void GetFilesOrDirectories(IntPtr info, bool fileMode)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);

            string[]  buffer    = null;
            Exception exception = null;

            try
            {
                if (arguments.Length > 0)
                {
                    string path = (arguments[0] as NSJSString)?.Value;
                    if (DIRECTORY.Exists(path))
                    {
                        if (arguments.Length > 1)
                        {
                            string searchPattern = (arguments[1] as NSJSString)?.Value;
                            if (string.IsNullOrEmpty(searchPattern))
                            {
                                searchPattern = "*";
                            }
                            if (arguments.Length > 2)
                            {
                                int?searchOption = (arguments[2] as NSJSInt32)?.Value;
                                buffer = fileMode ?
                                         DIRECTORY.GetFiles(path, searchPattern, (SearchOption)searchOption.GetValueOrDefault()) :
                                         DIRECTORY.GetDirectories(path, searchPattern, (SearchOption)searchOption.GetValueOrDefault());
                            }
                            else
                            {
                                buffer = fileMode ?
                                         DIRECTORY.GetFiles(path, searchPattern) :
                                         DIRECTORY.GetDirectories(path, searchPattern);
                            }
                        }
                        else
                        {
                            buffer = fileMode ?
                                     DIRECTORY.GetFiles(path) :
                                     DIRECTORY.GetDirectories(path);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            if (exception != null)
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
            else if (buffer == null)
            {
                Throwable.DirectoryNotFoundException(arguments.VirtualMachine);
            }
            else
            {
                NSJSArray s = NSJSArray.New(arguments.VirtualMachine, buffer.Length);
                for (int i = 0; i < buffer.Length; i++)
                {
                    s[i] = NSJSString.New(arguments.VirtualMachine, buffer[i]);
                }
                arguments.SetReturnValue(s);
            }
        }