示例#1
0
        private void SetAttributes()
        {
            var            prefixFullname = PREFIX + filename;
            SafeFileHandle fileHandle     = ExternalCalls.CreateFile(prefixFullname,
                                                                     ExternalCalls.ExtFileAccess.GenericRead, ExternalCalls.ExtFileShare.Read, IntPtr.Zero,
                                                                     ExternalCalls.ECreationDisposition.OpenExisting, 0, IntPtr.Zero);

            if (fileHandle != null && !fileHandle.IsInvalid)
            {
                using (var fileStream = new FileStream(fileHandle, FileAccess.Read))
                {
                    if (fileStream.Length > 0)
                    {
                        exists = true;
                    }
                    length = fileStream.Length;
                }
                name      = filename.Split('\\').Last();
                extention = filename.Split('.').Last();
                IntPtr ptr              = fileHandle.DangerousGetHandle();
                var    ftCreationTime   = new FILETIME();
                var    ftLastAccessTime = new FILETIME();
                var    ftLastWriteTime  = new FILETIME();
                ExternalCalls.GetFileTime(ptr, ref ftCreationTime, ref ftLastAccessTime, ref ftLastWriteTime);
                var creationTime   = DateTime.FromFileTimeUtc((((long)ftCreationTime.dwHighDateTime) << 32) | ((uint)ftCreationTime.dwLowDateTime));
                var lastAccessTime = DateTime.FromFileTimeUtc((((long)ftLastAccessTime.dwHighDateTime) << 32) | ((uint)ftLastAccessTime.dwLowDateTime));
                var lastWriteTime  = DateTime.FromFileTimeUtc((((long)ftLastWriteTime.dwHighDateTime) << 32) | ((uint)ftLastWriteTime.dwLowDateTime));
                this.creationTime = creationTime;
                if (!fileHandle.IsClosed)
                {
                    fileHandle.Close();
                }
                if ((ExternalCalls.GetFileAttributes(prefixFullname) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    this.readOnly = true;
                }
            }
        }
示例#2
0
        public FileAttributes GetAttributes()
        {
            var prefixFullname = PREFIX + filename;

            return(ExternalCalls.GetFileAttributes(prefixFullname));
        }