public File(FileInfo file, DriveMapping mapping, User user) { Extension = file.Extension; Type = "File"; Name = file.Name + (file.Name.Contains(file.Extension) ? "" : file.Extension); CreationTime = file.CreationTime.ToShortDateString() + " " + file.CreationTime.ToString("hh:mm"); UnderlyingCreation = file.CreationTime; ModifiedTime = file.LastWriteTime.ToShortDateString() + " " + file.LastWriteTime.ToString("hh:mm"); UnderlyingModified = file.LastWriteTime; Size = parseLength(file.Length); UnderlyingSize = file.Length; FileIcon fi; if (FileIcon.TryGet(Extension, out fi)) { Type = fi.Type; Name = Name.Remove(Name.LastIndexOf(file.Extension)); } if (Type == "File") { try { RegistryKey rkRoot = Registry.ClassesRoot; string keyref = rkRoot.OpenSubKey(file.Extension).GetValue("").ToString(); Type = rkRoot.OpenSubKey(keyref).GetValue("").ToString(); Name = Name.Remove(Name.LastIndexOf(file.Extension)); } catch { Type = "File"; } } if (Type != "File") { Icon = "../images/icons/" + ParseForImage(file); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + ParseForImage(file); } } else { Icon = "../images/icons/file.png"; } string m = Converter.UNCtoDrive2(file.FullName, mapping, user); Path = "../Download/" + HttpUtility.UrlEncode(m.Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|2f", "/"); if (file.Extension.ToLower().Equals(".png") || file.Extension.ToLower().Equals(".jpg") || file.Extension.ToLower().Equals(".jpeg") || file.Extension.ToLower().Equals(".gif") || file.Extension.ToLower().Equals(".bmp") || file.Extension.ToLower().Equals(".wmf")) { Icon = "../api/mycomputer/thumb/" + HttpUtility.UrlEncode(m.Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|2f", "/"); } Permissions = UserFileAccessRights.Get(file.FullName).ToPerms(); }
public Properties(DirectoryInfo dir, DriveMapping mapping, User user, bool RunSize) { Name = dir.Name; DateCreated = dir.CreationTime.ToString(); DriveMapping m; Actions = isWriteAuth(mapping) ? HAP.MyFiles.AccessControlActions.Change : HAP.MyFiles.AccessControlActions.View; try { Permissions = UserFileAccessRights.Get(dir.FullName).ToPerms(); } catch { } if (dir.FullName == Converter.DriveToUNC("", mapping.Drive.ToString(), out m, user) + "\\") { Location = null; } else { Location = HttpUtility.UrlEncode(Converter.UNCtoDrive(dir.Parent.FullName, mapping, user).Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|5c", "\\"); Contents = dir.GetFiles().Length + " Files, "; Contents += dir.GetDirectories().Length + " Folders"; long s = 0; if (RunSize) { foreach (FileInfo f in dir.GetFiles("*.*", SearchOption.AllDirectories)) { s += f.Length; } } Size = File.parseLength(s); } Type = "File Folder"; if (Type != "File") { Icon = "../images/icons/" + File.ParseForImage(dir); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + File.ParseForImage(dir); } } else { Icon = "../images/icons/file.png"; } }
/// <summary> /// Create Properties for quick use /// </summary> /// <param name="dir">Directory</param> /// <param name="user">User</param> /// <param name="mapping">Drive Mapping</param> public Properties(DirectoryInfo dir, User user, DriveMapping mapping) { DriveMapping m; Actions = isWriteAuth(mapping) ? HAP.MyFiles.AccessControlActions.Change : HAP.MyFiles.AccessControlActions.View; try { Permissions = UserFileAccessRights.Get(dir.FullName).ToPerms(); } catch { } if (dir.FullName.Contains(".zip")) { Actions = AccessControlActions.ZIP; } else { try { dir.GetDirectories(); } catch { Actions = HAP.MyFiles.AccessControlActions.None; } } Name = (dir.FullName == Converter.DriveToUNC("", mapping.Drive.ToString(), out m, user) + '\\') ? mapping.Name : dir.Name; Location = HttpUtility.UrlEncode(Converter.UNCtoDrive(dir.FullName, mapping, user).Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|5c", "\\"); try { Permissions = UserFileAccessRights.Get(dir.FullName).ToPerms(); } catch { } Type = "File Folder"; if (Type != "File") { Icon = "../images/icons/" + File.ParseForImage(dir); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + File.ParseForImage(dir); } } else { Icon = "../images/icons/file.png"; } }
public NTFSPerms ToPerms() { NTFSPerms perms = new NTFSPerms(); perms.AppendData = canAppendData(); perms.CreateDirs = canCreateDirectories(); perms.CreateFiles = canCreateFiles(); perms.Delete = canDelete(); perms.DeleteSubDirsOrFiles = canDeleteSubdirectoriesAndFiles(); perms.Execute = canExecuteFile(); perms.FullControl = canFullControl(); perms.ListDirs = canListDirectory(); perms.Modify = canModify(); perms.ReadAttr = canReadAttributes(); perms.ReadData = canReadData(); perms.ReadExAttr = canReadExtendedAttributes(); perms.ReadExecute = canReadAndExecute(); perms.Traverse = canTraverse(); perms.Write = canWrite(); perms.WriteAttr = canWriteAttributes(); perms.WriteData = canWriteData(); perms.WriteExAttr = canWriteExtendedAttributes(); return(perms); }