private bool Filter(DirInfo dirInfo, string filterQuery) { string name = dirInfo.DisplayName; if (dirInfo.IsDirectory) { return(true); } string ext = Path.GetExtension(name); switch (filterQuery) { case "All": return(true); case "Crypt": return(ext == ".enc"); case "Sign": return(ext == ".sig"); case "NotCryptSign": return(ext != ".sig" && ext != ".enc");; default: return(true); } }
JsonResult IDriver.Open(string target, bool tree) { WebDavRoot lroot = this.GetRoot(target); target = this.GetCorectTarget(target); target = this.DecodeTarget(target, lroot.Directory.RelPath); List <DirInfo> filesFormWebFav = client.GetDirectories(target, true); List <DirInfo> directories = filesFormWebFav.FindAll(d => d.IsDirectory); DirInfo targetDirInfo = directories[0]; DirInfo parentDirInfo = this.GetParent(targetDirInfo); targetDirInfo.HasSubDirectories = filesFormWebFav != null && directories != null && directories.Count > 1; OpenResponseBase answer = new OpenResponseBase(DTOBase.Create(targetDirInfo, parentDirInfo, lroot)); if (filesFormWebFav != null) { filesFormWebFav.Remove(targetDirInfo); foreach (DirInfo dirInfo in filesFormWebFav) { dirInfo.HasSubDirectories = IsConstainsChild(dirInfo); answer.Files.Add(DTOBase.Create(dirInfo, targetDirInfo, lroot)); } } //HttpContext.Current.Session[RetTarget] = answer.CurrentWorkingDirectory.Hash; return(Json(answer)); }
public AddResponse(DirInfo newDir, DirInfo parent, WebDavRoot root) { _added = new List <DTOBase>() { DTOBase.Create(newDir, parent, root) }; }
private DirInfo GetParent(DirInfo directory) { if (directory == null) { return(null); } string parentPath; if (directory.RelPath.EndsWith("/")) { parentPath = directory.RelPath.Substring(0, directory.RelPath.Length - 1); } else { parentPath = directory.RelPath; } int lastIndex = parentPath.LastIndexOf("/", StringComparison.Ordinal); if (lastIndex == -1) { return(null); } parentPath = parentPath.Substring(0, lastIndex); if (string.IsNullOrEmpty(parentPath)) { return(null); } List <DirInfo> parentInfo = client.GetDirectories(parentPath, true); return(parentInfo != null && parentInfo.Count > 0 ? parentInfo[0] : null); }
static void Main(string[] args) { foreach (string s in args) { Console.WriteLine(s); } //Console.Write("pause"); //Console.ReadLine(); String strCurDir = System.IO.Directory.GetCurrentDirectory(); //Console.WriteLine(strCurDir); DirInfo infoRoot = new DirInfo(); GetDirectoriesSize(strCurDir, infoRoot.listChild); //Console.WriteLine("{0,0:N0}",aSize); infoRoot.DoPrint(); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); }
private void btnFromFile_Click(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "All Supported Picture Files(*.jpg,*.png,*.ico,*.bmp)|*.jpg;*.png;*.ico;*.bmp"; dlg.Multiselect = true; if (dlg.ShowDialog() == DialogResult.OK) { string[] filenames = dlg.FileNames; if (filenames == null || filenames.Length == 0) { return; } DirInfo info = txtCategories.SelectedItem as DirInfo; if (info == null) { Directory.CreateDirectory(Constants.GetMapResourceDir() + "\\Default"); txtCategories.Items.Add(info); txtCategories.SelectedIndex = 0; } foreach (string f in filenames) { try { File.Copy(f, Path.Combine(info.Dir, Path.GetFileName(f)), false); } catch { } } txtCategories_SelectedIndexChanged(null, null); } } }
public AdvancedSearch(String path) { InitializeComponent(); workdir = path; TBPattern.Text = ""; TBReplace.Text = ""; DirInfo CurrentDirectory = new DirInfo(new DirectoryInfo(workdir)); childFileList = (from fobj in FileSystemExplorerService.GetChildFiles(CurrentDirectory.Path) select new DirInfo(fobj)).ToList(); int length = 0; if (!int.TryParse(TBLength.Text, out length)) { length = 3; } Dictionary <String, int> detection = DetectOccurences(childFileList, length); LVWord.ItemsSource = detection; }
JsonResult IDriver.Rename(string target, string name) { string oldTarget = target; WebDavRoot lroot = this.GetRoot(target); target = this.GetCorectTarget(target); target = this.DecodeTarget(target); DirInfo oldDirInfo = client.GetInfo(target); if (oldDirInfo == null) { throw new ElFinderFileNotExists(); } DirInfo parent = this.GetParent(oldDirInfo); client.Rename(target, parent.RelPath + name); DirInfo newDirInfo = client.GetInfo(parent.RelPath + name); if (newDirInfo == null) { return(Error.Message("Невозможно переименовать файл. Задано некорректное имя.")); } ReplaceResponse answer = new ReplaceResponse(); answer.Removed.Add(oldTarget); answer.Added.Add(DTOBase.Create(newDirInfo, parent, lroot)); return(Json(answer)); }
public WebDavDownloadFileResult(DirInfo file, Stream stream, bool isDownload) { file.DisplayName = file.DisplayName; File = file; IsDownload = isDownload; this.stream = stream; }
private static string readdir(DirInfo dirinfo, ref byte[] buffer) { if (dirinfo == null) { return(null); } //if (dir == IntPtr(INVALID_HANDLE_VALUE)) if (!dirinfo.lastResult) { return(null); } string res = dirinfo.directory + (dirinfo.directory.EndsWith(@"\") ? "" : @"\") + dirinfo.findData.cFileName; /* * int r = 0; * * // We can reuse the same buffer since sys_readdir * // will fill up the rest of the space by null characters * r = sys_readdir (dir, buffer, buffer.Length); * if (r == -1) * return null; * * int n_chars = 0; * while (n_chars < buffer.Length && buffer [n_chars] != 0) ++n_chars; * * return FileNameMarshaler.LocalToUTF8 (buffer, 0, n_chars); * * while (Kernel32.FindNextFile(findHandle, out findData)) ; * */ dirinfo.lastResult = FindNextFile(dirinfo.findHandle, out dirinfo.findData); return(res); }
private void TreeView_Expanded(object sender, RoutedEventArgs e) { TreeViewItem currentTreeNode = sender as TreeViewItem; if (currentTreeNode == null) { return; } if (currentTreeNode.ItemsSource == null) { return; } DirInfo parentDirectory = currentTreeNode.Header as DirInfo; if (parentDirectory == null) { return; } foreach (DirInfo d in currentTreeNode.ItemsSource) { if (myViewModel.CurrentDirectory.Path.Equals(d.Path)) { d.IsSelected = true; d.IsExpanded = true; break; } } e.Handled = true; }
public void Move(string path, string dest) { DirInfo d1 = FindInfo(path), d2 = FindInfo(dest); if (d1 == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } if (d2 == null) { StringCollection sa = new StringCollection(ResolvePath(dest)); string s = sa[sa.Count - 1]; sa.RemoveAt(sa.Count - 1); d2 = FindInfo("\\" + string.Join("\\", sa.ToArray())); if (d2 == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", dest)); } d1.Name = s; } else if (d2 is FileInfo) { throw new IOException("A file or folder with this name already exists."); } d1.Parent = d2.Index; if (d1 == current) { StringCollection sa = new StringCollection(ResolvePath(d1.ToString())); sa.RemoveAt(sa.Count - 1); current = FindInfo("\\" + string.Join("\\", sa.ToArray())); } }
private DirInfo FindInfo(string path) { string[] sa = ResolvePath(path); DirInfo d1 = ROOT_DIR, d2 = d1; for (int i = 0; i < sa.Length; ++i) { string s = sa[i].ToLower(); d1 = null; foreach (DirInfo di in entries) { if (di.Parent != d2.Index || di.Name.ToLower() != s) { continue; } if ((d1 = di) is FileInfo && i != sa.Length - 1) { throw new DirectoryNotFoundException(path); } else { d2 = d1; } break; } if (d1 == null) { break; } } return(d1); }
JsonResult IDriver.Filter(string target, string query) { WebDavRoot lroot = this.GetRoot(target); target = this.GetCorectTarget(target); target = this.DecodeTarget(target, lroot.Directory.RelPath); List <DirInfo> filesFormWebFav = client.GetDirectories(target, true); List <DirInfo> directories = filesFormWebFav.FindAll(d => d.IsDirectory); DirInfo targetDirInfo = directories[0]; DirInfo parentDirInfo = this.GetParent(targetDirInfo); targetDirInfo.HasSubDirectories = filesFormWebFav != null && directories != null && directories.Count > 1; OpenResponseBase answer = new OpenResponseBase(DTOBase.Create(targetDirInfo, parentDirInfo, lroot)); if (filesFormWebFav != null) { filesFormWebFav.Remove(targetDirInfo); foreach (DirInfo dirInfo in filesFormWebFav) { if (!Filter(dirInfo, query)) { continue; } answer.Files.Add(DTOBase.Create(dirInfo, targetDirInfo, lroot)); } } var r = Json(answer); return(r); }
static long GetDirectoriesSize( String strCurDir, System.Collections.Generic.LinkedList <DirInfo> parentList) { String[] strFiles = Directory.GetFiles(strCurDir, "*.*"); long aSize = 0; foreach (String s in strFiles) { FileInfo info = new FileInfo(s); aSize += info.Length; } DirInfo infoCur = new DirInfo(); infoCur.dirName = strCurDir; infoCur.curSize = aSize; System.Collections.Generic.LinkedListNode <DirInfo> infoMine = parentList.AddLast(infoCur); String[] strDirectories = Directory.GetDirectories(strCurDir); foreach (String sDirs in strDirectories) { aSize += GetDirectoriesSize(sDirs, infoMine.Value.listChild); } //Console.WriteLine("{0} size({1,0:N0}) Bytes", strCurDir, aSize); //infoMine.Value.aSize = aSize; infoMine.Value.aSize = aSize; return(aSize); }
public void Delete(string path, bool recursive) { DirInfo di = FindInfo(path); if (di == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } if (di.ToString() == "\\") { if (!recursive) { throw new IOException("The archive root cannot be deleted."); } StringCollection sa = new StringCollection(GetDirectories("\\")); sa.AddRange(GetFiles("\\")); foreach (string s in sa) { Delete("\\" + s, true); } } else if (di is FileInfo) { entries.Remove(di); FileInfo fi = (FileInfo)di; lock (stream) { foreach (int i in fi.seq) { stream.Position = GetOffset(i); bw.Write((short)-1); bw.Write(new byte[BLOCK_SIZE - 2]); } } } else { StringCollection sa = new StringCollection(GetDirectories(di.ToString())); sa.AddRange(GetFiles(di.ToString())); if (recursive) { foreach (string s in sa) { Delete(di.ToString() + '\\' + s, true); } } else if (sa.Count > 0) { throw new IOException("Directory is not empty."); } entries.Remove(di); if (di == current) { sa = new StringCollection(ResolvePath(di.ToString())); sa.RemoveAt(sa.Count - 1); current = FindInfo("\\" + string.Join("\\", sa.ToArray())); } } UpdateDirs(); }
ActionResult IDriver.Download(IEnumerable <string> targets) { string[] enumerable = targets as string[] ?? targets.ToArray(); if (enumerable.Count() == 1) { string target = enumerable[0]; target = this.GetCorectTarget(target); target = this.DecodeTarget(target); DirInfo dirInfo = client.GetInfo(target); if (dirInfo == null) { throw new ElFinderDownloadException("Файл не существует или удален."); } Stream stream = client.DownloadStream(target); WebDavDownloadFileResult retVal = new WebDavDownloadFileResult(dirInfo, stream, true); return(retVal); } List <DirInfo> dirInfoList = new List <DirInfo>(); foreach (string item in enumerable) { string target = this.DecodeTarget(this.GetCorectTarget(item)); DirInfo dirInfo = client.GetInfo(target); if (dirInfo != null) { dirInfoList.Add(dirInfo); } } byte[] content = Helper.GetZip(dirInfoList, client); return(new WebDavDownloadZip(content)); }
private static Int32 GetDirInfoByName( IntPtr FileSystemPtr, ref FullContext FullContext, String FileName, out DirInfo DirInfo) { FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr); try { Object FileNode, FileDesc; String NormalizedName; Api.GetFullContext(ref FullContext, out FileNode, out FileDesc); DirInfo = default(DirInfo); Int32 Result = FileSystem.GetDirInfoByName( FileNode, FileDesc, FileName, out NormalizedName, out DirInfo.FileInfo); DirInfo.SetFileNameBuf(NormalizedName); return(Result); } catch (Exception ex) { DirInfo = default(DirInfo); return(ExceptionHandler(FileSystem, ex)); } }
public void CreateDirectory(string path) { string[] sa = ResolvePath(path); bool created = false; DirInfo d1 = ROOT_DIR; foreach (string s in sa) { DirInfo d2 = null; foreach (DirInfo di in entries) { if (di.Parent != d1.Index || di.Name.ToLower() != s.ToLower()) { continue; } if (di is FileInfo) { throw new IOException(""); } d2 = di; break; } if (d2 == null) { entries.Add(d2 = new DirInfo(this, s, next_dir--, d1.Index)); created = true; } d1 = d2; } if (created) { UpdateDirs(); } }
public Int32 SeekableReadDirectory( Object FileNode, Object FileDesc, String Pattern, String Marker, IntPtr Buffer, UInt32 Length, out UInt32 BytesTransferred) { Object Context = null; String FileName; DirInfo DirInfo = default(DirInfo); BytesTransferred = default(UInt32); while (ReadDirectoryEntry(FileNode, FileDesc, Pattern, Marker, ref Context, out FileName, out DirInfo.FileInfo)) { DirInfo.SetFileNameBuf(FileName); if (!Api.FspFileSystemAddDirInfo(ref DirInfo, Buffer, Length, out BytesTransferred)) { return(STATUS_SUCCESS); } } Api.FspFileSystemEndDirInfo(Buffer, Length, out BytesTransferred); return(STATUS_SUCCESS); }
private DirInfo CreateDirInfo(string physicalDirFile, string base64Ciphertext, DirInfo parent) { var filename = DecryptFileName(physicalDirFile, parent.ParentDirId); string[] lines = File.ReadAllLines(PathJoin(physicalDirFile, "dir.c9r")); string dirID = lines[0]; Debug.Assert(lines[0].Length == 36 && lines.Length == 1); var dirIdHash = Base32Encoding.ToString(sha1.ComputeHash(siv.Seal(Encoding.UTF8.GetBytes(dirID)))); Debug.Assert(dirIdHash.Length == 32); var actualDirPath = PathJoin(dirIdHash.Substring(0, 2), dirIdHash.Substring(2)); return(new DirInfo { Name = filename, VirtualPath = PathJoin(parent.VirtualPath, filename), PhysicalPath = PathJoin(vaultPath, "d", actualDirPath), ParentDirId = dirID, Level = parent.Level + 1 }); }
private static void InitializeInfo(DirInfo info, Options options) { info.totalDirs = 0; // Because we count the base directory info.totalFiles = 0; info.totalBytes = 0; info.dirOpts = options; }
public static RayCastResult rayCast(Vector3 startPos, Vector3 dir, RayCastManager rtm, float length, RayCastBlockType mask) { DirInfo dirInfo = new DirInfo(dir); Vector3 startPosInner = startPos; float hitTime = 0; float startOffset = 0; bool bHitBounds = true;//能击中总区域,或者在内部 if (startPos.x >= 0 && startPos.x < rtm.getSizeX() && startPos.y >= 0 && startPos.y < rtm.getSizeY() && startPos.z >= 0 && startPos.z < rtm.getSizeZ()) { bHitBounds = true; } else { bHitBounds = Misc.rayHitAABB(startPos, dir, new Vector3(0, 0, 0), rtm.getSize(), ref hitTime); if (hitTime > 0) { startOffset = hitTime; } startPosInner = startPos + dir * startOffset - dir * 0.01f; } if (bHitBounds) { RayCastResult rlt = rayTraceSmall(startPosInner, dirInfo, rtm, Face.FNI_Unknown, length - startOffset, mask); rlt.hitLength += startOffset; return(rlt); } else { return(new RayCastResult(false, 0, 0, 0, Face.FNI_Unknown, 0)); } }
public static DTOBase Create(DirInfo directory, WebDavRoot root) { if (directory == null) { throw new ArgumentNullException("directory"); } if (root == null) { throw new ArgumentNullException("root"); } RootDTO response = new RootDTO() { Mime = "directory", Dirs = directory.HasSubDirectories ? (byte)1 : (byte)0, Hash = root.VolumeId + Helper.EncodePath(directory.RelPath), Read = 1, Write = 1, Locked = 0, Name = root.Alias, Size = 0, VolumeId = root.VolumeId }; DateTime lastModified; if (DateTime.TryParse(directory.LastModified, out lastModified)) { response.UnixTimeStamp = (long)(lastModified - _unixOrigin).TotalSeconds; } return(response); }
private void viewServer_BeforeExpand(object sender, TreeViewCancelEventArgs e) { string path; TreeNode node; try { e.Node.Nodes.Clear(); path = e.Node.FullPath; DirInfo dirInfo = new DirInfo(path); dirInfo.Type = (int)PacketType.ReqDirList; Packet.Serialize(dirInfo).CopyTo(this.sendBuf, 0); this.Send(); Recv(); DirList dirList = (DirList)Packet.Deserialize(this.recvBuf); foreach (string dir in dirList.dirList) { node = e.Node.Nodes.Add(dir); node.Nodes.Add(""); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// async test1 public void test1() { //IEnumerable<int> GenerateWithYield() //{ // var i = 0; // while (i < 5) // { // yield return ++i; // yield return i + 2; // } //} //foreach (var number in GenerateWithYield()) // Console.WriteLine(number); var subdirs = DirInfo.GetDirectories(); IEnumerable <int> GenerateWithYield() { yield return(1); } foreach (var dir in subdirs) { FolderSelector child = new FolderSelector(dir.FullName); myParents[child.DirInfo.FullName] = this; Children.Add(child); } }
public static DirInfo GetDirInfo(string path, Options options = Options.None) { DirInfo info = new DirInfo(); InitializeInfo(info, options); info = GetAllDirInfo(path, info); return(info); }
public static DirInfo CountDirs(string path) { DirInfo info = new DirInfo(); info.totalDirs = System.IO.Directory.GetDirectories(path, "*", SearchOption.AllDirectories).Length; info.totalFiles = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Length; return(info); }
private void HandleReqFileList() { DirInfo dirInfo = (DirInfo)Packet.Deserialize(this.recvBuf); SendSubFileList(pathDir + dirInfo.dirName); pathCur = pathDir + dirInfo.dirName + "\\"; Directory.SetCurrentDirectory(pathCur); }
private Stack <DirInfo> getSubDirs(string source, int level) { Stack <DirInfo> dirNodes = new Stack <DirInfo>(1000); IEnumerable <string> rootSubDirs; string message; if (!Directory.Exists(source)) { message = "Directory [" + source + "] does not exist"; MyLog.Add(message); MessageBox.Show(message); return(dirNodes);; } // add the folders (should be movies) under source as root try { // subDirs = Directory.getDirectories(currentDir)); rootSubDirs = Directory.EnumerateDirectories(source); } catch (UnauthorizedAccessException e) { MyLog.Add(e.ToString()); MessageBox.Show(e.Message); return(dirNodes);; } catch (PathTooLongException e) { MyLog.Add(e.ToString()); MessageBox.Show(e.Message); return(dirNodes);; } catch (DirectoryNotFoundException e) { MyLog.Add(e.ToString()); MessageBox.Show(e.Message); return(dirNodes);; } DirectoryInfo directoryInfo; DirInfo dirInfo = new DirInfo(); foreach (string subDir in rootSubDirs) { directoryInfo = new DirectoryInfo(subDir); dirInfo.directoryInfo = directoryInfo; dirInfo.level = level; dirNodes.Push(dirInfo); } return(dirNodes); }
public static void Init() { s_dirInfo = new DirInfo[9]; s_dirInfo[0] = new DirInfo(-1, 0, 0, 0 , "\u2751"); s_dirInfo[1] = new DirInfo( 0, 1, 0, RIGHT , "\u2192"); // right s_dirInfo[2] = new DirInfo( 1, 1, 1, UP | RIGHT , "\u2197"); // up-right s_dirInfo[3] = new DirInfo( 2, 0, 1, UP , "\u2191"); // up s_dirInfo[4] = new DirInfo( 3, -1, 1, UP | LEFT , "\u2196"); // up-left s_dirInfo[5] = new DirInfo( 4, -1, 0, LEFT , "\u2190"); // left s_dirInfo[6] = new DirInfo( 5, -1, -1, DOWN | LEFT , "\u2199"); // down-left s_dirInfo[7] = new DirInfo( 6, 0, -1, DOWN , "\u2193"); // down s_dirInfo[8] = new DirInfo( 7, 1, -1, DOWN | RIGHT, "\u2198"); // down-right }
public static Protocol Create(int iType) { Protocol prtc = null; // Protocol stub = GetStub(iType); // if(stub != null) // { // prtc = (Protocol)stub.Clone(); // } // else // { if (iType == DirInfo.PROTOCOL_TYPE) prtc = new DirInfo(); else prtc = new CommonData(iType); // } return prtc ; }