Пример #1
0
        private void calc_size_count(FileInfoEx dir_info, ref long size, ref long allocation, ref long file_count, ref long dir_count)
        {
            FileInfoExEnumerable dir_enum = new FileInfoExEnumerable
                                                (Path.Combine(dir_info.FullName, "*"),
                                                true,
                                                true,
                                                true,
                                                true);

            foreach (FileInfoEx info in dir_enum)
            {
                IntPtr h_file = IntPtr.Zero;
                try
                {
                    h_file = WinAPiFSwrapper.CreateFileHandle
                                 (info.FullName,
                                 Win32FileAccess.READ_ATTRIBUTES | Win32FileAccess.READ_EA,
                                 FileShare.ReadWrite | FileShare.Delete,
                                 FileMode.Open,
                                 info.Directory ? CreateFileOptions.BACKUP_SEMANTICS : CreateFileOptions.None);

                    NT_FILE_STANDARD_INFORMATION s_info = ntApiFSwrapper.GetFileInfo_standard(h_file);
                    size       += s_info.EndOfFile;
                    allocation += s_info.AllocationSize;
                    //if (s_info.AllocationSize < s_info.EndOfFile)
                    //{
                    //    /*DEBUG*/
                    //    long delta = s_info.EndOfFile - s_info.AllocationSize;
                    //}
                }
                catch (Exception)
                {
                    //Messages.ShowException
                    //    (ex,
                    //    string.Format
                    //    (Options.GetLiteral(Options.LANG_CANNOT_READ_ATTRIBUTES_0),
                    //    info.FullName));
                    break;
                }
                finally
                {
                    if ((h_file.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE) && (h_file != IntPtr.Zero))
                    {
                        WinApiFS.CloseHandle(h_file);
                    }
                }
                if (info.Directory)
                {
                    calc_size_count(info, ref size, ref allocation, ref file_count, ref dir_count);
                    dir_count++;
                }
                else
                {
                    file_count++;
                }
            }
        }
Пример #2
0
        private void fill_standard_info()
        {
            IntPtr h_file = IntPtr.Zero;

            try
            {
                h_file = WinAPiFSwrapper.CreateFileHandle
                             (FileName,
                             Win32FileAccess.READ_ATTRIBUTES | Win32FileAccess.READ_EA,
                             FileShare.ReadWrite | FileShare.Delete,
                             FileMode.Open,
                             is_directory ? CreateFileOptions.BACKUP_SEMANTICS : CreateFileOptions.None);

                NT_FILE_STANDARD_INFORMATION s_info = ntApiFSwrapper.GetFileInfo_standard(h_file);



                textBoxSize.Text = string.Format
                                       (Options.GetLiteral(Options.LANG_0_BYTES),
                                       s_info.EndOfFile);
                textBoxAllocationSize.Text = string.Format
                                                 (Options.GetLiteral(Options.LANG_0_BYTES),
                                                 s_info.AllocationSize);
                textBoxHardLinks.Text = s_info.NumberOfLinks.ToString();
            }
            catch (Exception ex)
            {
                textBoxSize.Text = ex.Message;
            }
            finally
            {
                if ((h_file.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE) && (h_file != IntPtr.Zero))
                {
                    WinApiFS.CloseHandle(h_file);
                }
            }
        }