Пример #1
0
        public static bool IsDirectoryEmpty(string file_name)
        {
            if (!IsDirectory(file_name))
            {
                return(false);
            }

            var search_path = file_name;

            search_path = search_path.TrimEnd(new char[] { Path.DirectorySeparatorChar });
            search_path = search_path + Path.DirectorySeparatorChar + "*";
            var fs_enum = new WinAPiFSwrapper.WIN32_FIND_DATA_enumerable(search_path);
            var count   = 0;

            foreach (var data in fs_enum)
            {
                if (data.cFileName == ".")
                {
                    continue;
                }
                if (data.cFileName == "..")
                {
                    continue;
                }
                count++;
                if (count > 0)
                {
                    break;
                }
            }
            return(count == 0);
        }
Пример #2
0
        private void search_in_directory_with_subdirs(string dir_path)
        {
            //first find matches in current dir
            search_in_directory(dir_path);

            //check abort
            if (Abort)
            {
                return;
            }

            //see directories
            var search_path = IOhelper.GetUnicodePath(dir_path);

            search_path = search_path.TrimEnd(new char[] { Path.DirectorySeparatorChar });
            search_path = search_path + Path.DirectorySeparatorChar + "*";
            var fs_enum = new WinAPiFSwrapper.WIN32_FIND_DATA_enumerable(search_path, true);

            foreach (var data in fs_enum)
            {
                //check abort
                if (Abort)
                {
                    break;
                }

                //skip some entries
                if (data.cFileName == "..")
                {
                    continue;
                }
                if (data.cFileName == ".")
                {
                    continue;
                }
                if ((data.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    //recursive call
                    search_in_directory_with_subdirs(Path.Combine(dir_path, data.cFileName));
                }
            }
        }
Пример #3
0
        private void search_in_directory(string dir_path)
        {
            OnDirectoryChange(dir_path);
            string search_mask = string.Empty;

            for (int i = 0; i < filter.Masks.Length; i++)
            {
                if (Abort)
                {
                    break;
                }
                search_mask = Path.Combine(dir_path, filter.Masks[i]);
                WinAPiFSwrapper.WIN32_FIND_DATA_enumerable file_enum =
                    new WinAPiFSwrapper.WIN32_FIND_DATA_enumerable(search_mask, true);
                foreach (WIN32_FIND_DATA data in file_enum)
                {
                    if (Abort)
                    {
                        break;
                    }

                    //skip some entries
                    if (data.cFileName == "..")
                    {
                        continue;
                    }

                    if (data.cFileName == ".")
                    {
                        continue;
                    }

                    if (filter_match(data))
                    {
                        OnFind(dir_path, data);
                    }
                }
            }
        }
Пример #4
0
        protected override void internal_refill()
        {
            //stop change file system notyfications
            internal_watcher.EnableRaisingEvents = false;

            //we will fill new_list first
            //if errors will not occurs, fill work list
            List <WIN32_FIND_DATA> new_list = new List <WIN32_FIND_DATA>();

            try
            {
                string search_path = IOhelper.GetUnicodePath(directory_path);
                search_path = search_path.TrimEnd(new char[] { Path.DirectorySeparatorChar });
                search_path = search_path + Path.DirectorySeparatorChar + "*";
                WinAPiFSwrapper.WIN32_FIND_DATA_enumerable fs_enum = new WinAPiFSwrapper.WIN32_FIND_DATA_enumerable(search_path);
                foreach (WIN32_FIND_DATA data in fs_enum)
                {
                    if (data.cFileName == ".") //skip entry "." - that is current directory
                    {
                        continue;
                    }

                    new_list.Add(data);
                }

                //workaround for directory path like \\server_name\share$
                //for that path there is no '..' entry returned from fs_enum
                if ((directory_path.EndsWith("$")) && (directory_path.StartsWith(@"\\")))
                {
                    bool need_add = true;
                    for (int i = 0; i < new_list.Count; i++)
                    {
                        if (new_list[i].cFileName == "..")
                        {
                            need_add = false;
                            break;
                        }
                    }
                    if (need_add)
                    {
                        WIN32_FIND_DATA fake_net_data = new WIN32_FIND_DATA();
                        fake_net_data.cFileName        = "..";
                        fake_net_data.dwFileAttributes = FileAttributes.Directory;
                        new_list.Add(fake_net_data);
                    }
                }

                //if no errors...
                internal_list.Clear();
                cache_directory_count          = 0;
                cache_directory_selected_count = 0;
                cache_files_count          = 0;
                cache_files_selected_count = 0;
                cache_selected_indices     = new int[] { };
                cache_size          = 0UL;
                cache_size_selected = 0UL;
                //update internal_list, counts, skip parent dir entry
                foreach (WIN32_FIND_DATA data in new_list)
                {
                    internal_list.Add(data, null);
                    if (data.cFileName == "..")
                    {
                        continue;
                    }
                    if ((data.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        cache_directory_count++;
                    }
                    else
                    {
                        cache_files_count++;
                        cache_size += data.FileSize;
                    }
                }

                //set notificator
                internal_watcher.Filter = string.Empty;
                internal_watcher.Path   = directory_path;
                try
                {
                    internal_watcher.EnableRaisingEvents = true;
                }
                catch (Exception ex)
                {
                    //Messages.ShowException(ex);
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
        }//end proc

        private void upload_directory_recurse(string source_dir, string destination_dir)
        {
            if (AbortSafe)
            {
                return;
            }

            //get fs entries
            //need try
            WinAPiFSwrapper.WIN32_FIND_DATA_enumerable fs_enum = null;
            try
            {
                fs_enum = new WinAPiFSwrapper.WIN32_FIND_DATA_enumerable
                              (Path.Combine(source_dir, "*"), false);
            }
            catch (Exception ex)
            {
                AbortSafe = !process_error
                                (string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_READ_DIRECTORY_CONTENTS_0),
                                    source_dir),
                                ex);
            }

            if (fs_enum == null)
            {
                return;
            }

            var source      = string.Empty;
            var destination = string.Empty;

            foreach (var data in fs_enum)
            {
                if (AbortSafe)
                {
                    return;
                }

                if (data.cFileName == ".")
                {
                    continue;
                }

                if (data.cFileName == "..")
                {
                    continue;
                }

                source      = Path.Combine(source_dir, data.cFileName);
                destination = FtpPath.Combine(destination_dir, data.cFileName);
                if ((data.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    upload_directory_recurse(source, destination);
                }
                else
                {
                    //source is file
                    upload_one_file(source, destination);
                }
            }
        }