private bool DoInputNewDir(string fileName) { if (fileName == "" || fileName == ".") { fileName = Directory.GetCurrentDirectory(); } fileName = Path.GetFullPath(fileName); if (!Directory.Exists(fileName)) { mainForm.Log.WriteError("Move error", "No directory: " + fileName); mainForm.Log.Open(); return(true); } mainForm.Dialogs.CloseInput(); List <Node> filesAndDirs = GetFilesAndDirs(buffer.Controller); PathSet newFullPaths = new PathSet(); PathSet oldPostfixed = new PathSet(); foreach (Node nodeI in filesAndDirs) { if (!string.IsNullOrEmpty(renamePostfixed)) { oldPostfixed.Add(nodeI.fullPath + renamePostfixed); } } foreach (Node nodeI in filesAndDirs) { if (!string.IsNullOrEmpty(renamePostfixed)) { oldPostfixed.Remove(nodeI.fullPath); } } foreach (Node nodeI in filesAndDirs) { try { if (nodeI.type == NodeType.Directory) { DirectoryMove(nodeI.fullPath, newFullPaths.Add(Path.Combine(fileName, Path.GetFileName(nodeI.fullPath)))); } else if (nodeI.type == NodeType.File) { FileMove(nodeI.fullPath, newFullPaths.Add(Path.Combine(fileName, Path.GetFileName(nodeI.fullPath)))); } if (!string.IsNullOrEmpty(renamePostfixed) && oldPostfixed.Contains(nodeI.fullPath + renamePostfixed) && File.Exists(nodeI.fullPath + renamePostfixed)) { FileMove(nodeI.fullPath + renamePostfixed, Path.Combine(fileName, Path.GetFileName(nodeI.fullPath) + renamePostfixed)); } } catch (IOException e) { mainForm.Log.WriteError("Move error", e.Message); mainForm.Log.Open(); } } Reload(); PutCursors(newFullPaths); return(true); }
/// <summary> /// Get Node that PathSet specified. /// </summary> /// <param name="pathSet"></param> /// <param name="paramSet"></param> /// <returns></returns> public Node GetNode(PathSet pathSet, FixedParamSet paramSet) { if (!this.ValidatePathSet(pathSet)) { return(null); } if (pathSet.Elements.Length <= 0) { // Requested Share Folder. return(NodeFactory.Get( pathSet.FullPath, NodeType.Folder, paramSet )); } else { // Requested Sub Node on Share. var result = this.GetFolderNode(pathSet, paramSet) ?? this.GetFileNode(pathSet, paramSet); if (result == null) { this.AddError("GetNode", $"Path Not Found: {pathSet.FullPath}"); return(null); } return(result); } }
private static string TestPaths(PathSet computed, params MovementPath[] expected) { var exp = new HashSet <MovementPath>(expected); var actual = new List <MovementPath>(computed); for (var i = actual.Count - 1; i >= 0; i--) { if (exp.Contains(actual[i])) { exp.Remove(actual[i]); actual.RemoveAt(i); } } var sb = new StringBuilder(); foreach (var missingExpected in exp) { sb.AppendLine($"Missing expected movement path {missingExpected}"); } foreach (var unexpectedActual in actual) { sb.AppendLine($"Unexpected movement path {unexpectedActual} found in calculated result"); } return(sb.ToString().Trim()); }
public FileStructure(PathSet pathSet, FilePropertiesSet properties) { this.Properties = properties; this.Name = pathSet.Name; this.FullPath = pathSet.FullPath; this.RelativePath = pathSet.RelativePath; }
private void PutCursors(PathSet newFullPaths) { foreach (string pathI in newFullPaths.NormalizedPaths) { ExpandTo(node, pathI); } Rebuild(); buffer.Controller.ClearMinorSelections(); bool first = true; for (int i = 0, count = nodes.Count; i < count; i++) { Node nodeI = nodes[i]; if (newFullPaths.Contains(nodeI.fullPath)) { if (first) { buffer.Controller.PutCursor(new Place(0, i), false); } else { buffer.Controller.PutNewCursor(new Place(0, i)); } first = false; } } buffer.Controller.NeedScrollToCaret(); }
private static string TestEndSquares(PathSet computed, params Vector[] expected) { var exp = new HashSet <Vector>(expected); var found = new HashSet <Vector>(); var actual = new List <MovementPath>(computed); for (var i = actual.Count - 1; i >= 0; i--) { if (exp.Contains(actual[i].Sum)) { found.Add(actual[i].Sum); actual.RemoveAt(i); } } var sb = new StringBuilder(); foreach (var missingExpected in exp.Except(found)) { sb.AppendLine($"Missing moves for expected vector {missingExpected}"); } foreach (var unexpectedActual in actual) { sb.AppendLine($"Got move {unexpectedActual} which didn't match an expected vector"); } return(sb.ToString().Trim()); }
public Connection(PathSet pathSet, ParamSet paramSet) : base() { this.IsConnected = false; if (pathSet == null) { this.AddError("Constructor", "Required pathSet."); return; } this._pathSet = pathSet; var argParamSet = (paramSet == null) ? new ParamSet() : paramSet.Clone(); if (argParamSet.SmbType == null) { this._client = this.GetConnection(SmbType.Smb2) ?? this.GetConnection(SmbType.Smb1); } else if (argParamSet.SmbType == SmbType.Smb2) { this._client = this.GetConnection(SmbType.Smb2); } else if (argParamSet.SmbType == SmbType.Smb1) { this._client = this.GetConnection(SmbType.Smb1); } else { this.AddError("Constructor", $"Unexpected ParamSet.SmbType: {argParamSet.SmbType}"); return; } if (this._client == null) { this.AddError("Constructor", "Connection Failed."); return; } if (!this.Login(argParamSet)) { this.AddError("Constructor", "Authentication Failed."); return; } this._paramSet = FixedParamSet.Parse( argParamSet, (this._client is SMB2Client) ? SmbType.Smb2 : SmbType.Smb1 ); this.IsConnected = true; }
protected bool ValidatePathSet(PathSet pathSet) { if (!this.IsConnected) { this.AddError("ValidatePathSet", "Not Connected."); return(false); } if (pathSet == null) { this.AddError("ValidatePathSet", "Required pathSet."); return(false); } if (string.IsNullOrEmpty(pathSet.Share)) { this.AddError("ValidatePathSet", "Share Not Specified."); return(false); } if (pathSet.Share.ToLower() != this._name.ToLower()) { this.AddError("ValidatePathSet", $"Share Missmatch. this: {this._name}, args: {pathSet.Share}"); return(false); } return(true); }
/// <summary> /// Create Sub Folder on Folder Node. /// </summary> /// <param name="node"></param> /// <param name="folderName"></param> /// <returns></returns> public Node CreateFolder(Node node, string folderName) { if (!this.ValidateNode(node)) { return(null); } if (string.IsNullOrEmpty(folderName)) { this.AddError("CreateFolder", "Required folderName"); return(null); } if (node.Type != NodeType.Folder) { this.AddError("CreateFolder", $"Invalid Operation: NodeType.{node.Type}"); return(null); } var newFullPath = $@"{node.FullPath}\{folderName}"; PathSet newPathSet; try { newPathSet = PathSet.Parse(newFullPath); } catch (Exception ex) { this.AddError("CreateFolder", $"Invalid Path: {newFullPath}", ex); return(null); } if (!this.ValidatePathSet(newPathSet)) { return(null); } var path = this.FormatPath(newPathSet.ElementsPath); using (var hdr = this.GetHandler(path, HandleType.Write, NodeType.Folder)) { if (!hdr.Succeeded) { this.AddError("CreateFolder", $"Create Handle Failed: {node.FullPath}"); return(null); } // The creation handle cannot be used to get node information. //return this.CreateNode(hdr, NodeType.Folder, newPathSet, node.ParamSet); } using (var hdr = this.GetHandler(path, HandleType.Read, NodeType.Folder)) { return(this.CreateNode(hdr, NodeType.Folder, newPathSet, node.ParamSet)); } }
public DirectoryStructure(PathSet pathSet, IEnumerable <FileStructure> files, IEnumerable <DirectoryStructure> directories, PropertiesSet properties) { this.Name = pathSet.Name; this.FullPath = pathSet.FullPath; this.RelativePath = pathSet.RelativePath; this.Files = files?.ToDictionary(o => o.Name); this.Directories = directories?.ToDictionary(o => o.Name); this.Properties = properties; }
/// <summary> /// Get Node from only Path. /// </summary> /// <param name="fullPath"></param> /// <param name="nodeType"></param> /// <param name="paramSet"></param> /// <returns></returns> public static Node Get( string fullPath, NodeType nodeType, FixedParamSet paramSet ) { var pathSet = PathSet.Parse(fullPath); return(NodeFactory.InnerGet(nodeType, pathSet, paramSet)); }
public Connection(Node node) : base() { this.IsConnected = false; if (node == null) { this.AddError("Constructor", "Required node."); return; } if (node.ParamSet == null || node.PathSet == null) { this.AddError("Constructor", "Invalid Node."); return; } this._pathSet = node.PathSet; if (node.ParamSet.SmbType == SmbType.Smb2) { this._client = this.GetConnection(SmbType.Smb2); } else if (node.ParamSet.SmbType == SmbType.Smb1) { this._client = this.GetConnection(SmbType.Smb1); } else { this.AddError("Constructor", $"Unexpected ParamSet.SmbType: {node.ParamSet.SmbType}"); return; } if (this._client == null) { this.AddError("Constructor", "Connection Failed."); return; } if (!this.Login(node.ParamSet)) { this.AddError("Constructor", "Authentication Failed."); return; } this._paramSet = node.ParamSet; this.IsConnected = true; }
public Connection(PathSet pathSet, FixedParamSet paramSet) : base() { this.IsConnected = false; if (pathSet == null) { this.AddError("Constructor", "Required pathSet."); return; } if (paramSet == null) { this.AddError("Constructor", "Required paramSet."); return; } this._pathSet = pathSet; if (paramSet.SmbType == SmbType.Smb2) { this._client = this.GetConnection(SmbType.Smb2); } else if (paramSet.SmbType == SmbType.Smb1) { this._client = this.GetConnection(SmbType.Smb1); } else { this.AddError("Constructor", $"Unexpected ParamSet.SmbType: {paramSet.SmbType}"); return; } if (this._client == null) { this.AddError("Constructor", "Connection Failed."); return; } if (!this.Login(paramSet)) { this.AddError("Constructor", "Authentication Failed."); return; } this._paramSet = paramSet; this.IsConnected = true; }
private Node GetFileNode(PathSet pathSet, FixedParamSet paramSet) { var path = this.FormatPath(pathSet.ElementsPath); using (var hdr = this.GetHandler(path, HandleType.Read, NodeType.File)) { if (!hdr.Succeeded) { // DO NOT AddError on failed. Do only GetNode method. return(null); } return(this.CreateNode(hdr, NodeType.File, pathSet, paramSet)); } }
/// <summary> /// Get Node from Path and SMB-FileInfomation /// </summary> /// <param name="fullPath"></param> /// <param name="paramSet"></param> /// <param name="basicInfo"></param> /// <param name="stdInfo"></param> /// <returns></returns> public static Node Get( string fullPath, FixedParamSet paramSet, FileBasicInformation basicInfo, FileStandardInformation stdInfo = null ) { if (paramSet == null) { throw new ArgumentException("Required paramSet."); } if (basicInfo == null) { throw new ArgumentException("Required info."); } var pathSet = PathSet.Parse(fullPath); if (basicInfo.FileAttributes.HasFlag(SMBLibrary.FileAttributes.Directory)) { // Folder var result = NodeFactory.InnerGet( NodeType.Folder, pathSet, paramSet ); result.Created = basicInfo.CreationTime; result.Updated = basicInfo.LastWriteTime; result.LastAccessed = basicInfo.LastAccessTime; return(result); } else { // File var result = NodeFactory.InnerGet( NodeType.File, pathSet, paramSet ); result.Size = stdInfo?.EndOfFile; result.Created = basicInfo.CreationTime; result.Updated = basicInfo.LastWriteTime; result.LastAccessed = basicInfo.LastAccessTime; return(result); } }
/// <summary> /// Get Child Node from Path and Smb1-Result. /// </summary> /// <param name="parentNode"></param> /// <param name="info"></param> /// <returns></returns> public static Node GetChild( Node parentNode, FindFileDirectoryInfo info ) { if (parentNode == null) { throw new ArgumentException("Required parentNode."); } if (info == null) { throw new ArgumentException("Required info."); } var pathSet = PathSet.Parse($@"{parentNode.FullPath}\{info.FileName}"); if (info.ExtFileAttributes.HasFlag(ExtendedFileAttributes.Directory)) { // Folder var result = NodeFactory.InnerGet( NodeType.Folder, pathSet, parentNode.ParamSet ); result.Created = info.CreationTime; result.Updated = info.LastWriteTime; result.LastAccessed = info.LastAccessTime; return(result); } else { // File var result = NodeFactory.InnerGet( NodeType.File, pathSet, parentNode.ParamSet ); result.Size = info.EndOfFile; result.Created = info.CreationTime; result.Updated = info.LastWriteTime; result.LastAccessed = info.LastAccessTime; return(result); } }
public void Serialize(BinaryLogger.EventWriter writer) { writer.Write(PathSetHash); PathSet.Serialize( writer.PathTable, writer, pathWriter: (w, v) => w.Write(v), stringWriter: (w, v) => ((BinaryLogger.EventWriter)w).WriteDynamicStringId(v)); writer.WriteReadOnlyList(PriorStrongFingerprints, (w, v) => w.Write(v)); writer.Write(Succeeded); if (Succeeded) { writer.Write(IsStrongFingerprintHit); writer.Write(ObservedInputs, (w, v) => v.Serialize(w)); writer.Write(ComputedStrongFingerprint); } }
public ActionResult DeletePhoto(int photoId, FormCollection formValues) { // retrieve the photo object to be deleted. Photo photoToDelete = _photoRepository.GetPhoto(photoId); // capture files name and file paths. string filename = Path.GetFileName(photoToDelete.PathToOriginalFile); PathSet pathset = new PathSet(); PopulatePaths(pathset, filename); // Delete from database. _photoRepository.Delete(photoToDelete); _photoRepository.Save(); // Todo Delete from file system. System.IO.File.Delete(pathset.originalFileLocal); System.IO.File.Delete(pathset.mediumThumbLocal); System.IO.File.Delete(pathset.smallThumbLocal); return RedirectToAction("Index"); }
private string GetFormattedSetG(PathSet set, string id, int resolution) { var result = $"<use xlink:href=\"#{id}\" fill-rule=\"evenodd\""; if (set.FillEffectExists == Reflection.Enum.eBoolean.True) { result += $" fill=\"{set.FillEffect.GetHTMLColor()}\""; } if (set.StrokeEffectExists == Reflection.Enum.eBoolean.True) { var thick = set.StrokeEffect.Thickness * resolution; if (thick == 0) { thick = (float)resolution / 2048.0f; // this should crash the game btw } result += $" stroke=\"{set.StrokeEffect.GetHTMLColor()}\" stroke-width=\"{thick:0.00}\""; } return(result + " />" + Environment.NewLine); }
/// <summary> /// Get Parent Node from Node. /// </summary> /// <param name="node"></param> /// <returns></returns> public static Node GetParent(Node node) { if (node == null) { throw new ArgumentException("Required node."); } if (node.Type == NodeType.Server) { return(null); } if (string.IsNullOrEmpty(node.PathSet.Share)) { throw new IOException($"Invalid FullPath String. : {node.FullPath}"); } var paths = new List <string>() { node.PathSet.IpAddressString }; if (1 <= node.PathSet.Elements.Length) { paths.Add(node.PathSet.Share); } if (2 <= node.PathSet.Elements.Length) { paths.AddRange(node.PathSet.Elements.Take(node.PathSet.Elements.Length - 1)); } var pathSet = PathSet.Parse(string.Join(@"\", paths)); var nodeType = (string.IsNullOrEmpty(pathSet.Share)) ? NodeType.Server : NodeType.Folder; return(NodeFactory.InnerGet(nodeType, pathSet, node.ParamSet)); }
protected override void Dispose(bool disposing) { if (!this.disposedValue) { if (disposing) { try { this._client?.Disconnect(); } catch (Exception) { } this._pathSet = null; this._paramSet = null; this._client = null; } this.disposedValue = true; } base.Dispose(disposing); }
public static MerkleProofTree GenerateProof(object value, PathSet pathSet, MerkleHashCalculator calculator) { var binaryTree = treeFactory.BuildWithPath(value, pathSet); return(proofFactory.BuildFromBinaryTree(binaryTree, calculator)); }
/// <summary> /// Query Infos, Create Node Instance. /// </summary> /// <param name="handler"></param> /// <param name="nodeType"></param> /// <param name="pathSet"></param> /// <param name="paramSet"></param> /// <returns></returns> protected Node CreateNode( IHandler handler, NodeType nodeType, PathSet pathSet, FixedParamSet paramSet ) { if (handler == null) { this.AddError("CreateNode", "Required handler."); return(null); } if (!handler.Succeeded) { this.AddError("CreateNode", "Invalid Handle."); return(null); } if (nodeType != NodeType.File && nodeType != NodeType.Folder) { this.AddError("CreateNode", $"Invalid Operation: {nodeType}"); return(null); } var status = this.Store.GetFileInformation( out var basicInfo, handler.Handle, FileInformationClass.FileBasicInformation ); if (status != NTStatus.STATUS_SUCCESS) { this.AddError("CreateNode", $"Basic Infomation Query Failed: {pathSet.FullPath}"); return(null); } FileInformation standardInfo = null; if (nodeType == NodeType.File) { status = this.Store.GetFileInformation( out standardInfo, handler.Handle, FileInformationClass.FileStandardInformation ); if (status != NTStatus.STATUS_SUCCESS) { this.AddError("CreateNode", $"StandardInfomation Query Failed: {pathSet.FullPath}"); return(null); } } return(NodeFactory.Get( pathSet.FullPath, paramSet, (FileBasicInformation)basicInfo, (FileStandardInformation)standardInfo )); }
public void Set(XmlNode attributeNode, Element parent, PropertyInfo property, string value) { try { PathSet propertyValue = new PathSet(parent.Project, value); property.SetValue(parent, propertyValue, BindingFlags.Public | BindingFlags.Instance, null, null, CultureInfo.InvariantCulture); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1022"), value, attributeNode.Name, parent.Name), parent.Location, ex); } }
/// <summary> /// Get Node Instance. /// </summary> /// <param name="path"></param> /// <param name="paramSet"></param> /// <param name="throwException"></param> /// <returns></returns> /// <remarks> /// /// ** Warning ** /// SMB1 with Windows Domain (= Active Directory) is NOT Supoorted. /// /// </remarks> public static async Task <Node> GetNode( string path, ParamSet paramSet = null, bool throwException = false ) { PathSet pathSet; try { pathSet = PathSet.Parse(path); } catch (Exception ex) { var message = Node.GetErrorMessage( "GetNode", $"Invalid Format fullPath: {path}" ); if (throwException) { throw new ArgumentException(message, ex); } Debug.WriteLine(message); return(null); } return(await Task.Run(() => { using (var conn = new Connection(pathSet, paramSet)) { if (conn.HasError) { if (throwException) { throw new IOException(Node.GetErrorMessage(conn)); } Node.DebugWrite(conn); return null; } var result = conn.GetNode(); if (result == null) { if (throwException) { throw new IOException(Node.GetErrorMessage(conn)); } Node.DebugWrite(conn); return null; } return result; } }).ConfigureAwait(false)); }
public void WritePathSet(StPathSetFieldCode fieldCode, PathSet value) { WriteFieldId(StTypeCode.PathSet, (uint)fieldCode); var first = true; Span <byte> span; foreach (var path in value) { if (first) { first = false; } else { span = bufferWriter.GetSpan(1); span[0] = 0xFF; bufferWriter.Advance(1); } foreach (var element in path) { var flags = (element.Account.HasValue ? 0x01 : 0x00) | (element.Currency.HasValue ? 0x10 : 0x00) | (element.Issuer.HasValue ? 0x20 : 0x00); var size = (element.Account.HasValue ? 20 : 0) + (element.Currency.HasValue ? 20 : 0) + (element.Issuer.HasValue ? 20 : 0) + 1; span = bufferWriter.GetSpan(size); span[0] = (byte)flags; var offset = 1; if (element.Account.HasValue) { element.Account.Value.CopyTo(span.Slice(offset)); offset += 20; } if (element.Currency.HasValue) { element.Currency.Value.CopyTo(span.Slice(offset)); offset += 20; } if (element.Issuer.HasValue) { element.Issuer.Value.CopyTo(span.Slice(offset)); offset += 20; } bufferWriter.Advance(size); } } span = bufferWriter.GetSpan(1); span[0] = 0x0; bufferWriter.Advance(1); }
public ActionResult UploadPhoto(HttpPostedFileBase file) { // If no content was recieved then just return the same view again. if (file.ContentLength == 0) { return View("UploadPhoto"); } PathSet pathSet = new PathSet(); PopulatePaths(pathSet, file.FileName); file.SaveAs(pathSet.originalFileLocal); // Create thumbnails. CreateThumbnailForImage(pathSet.mediumThumbLocal, pathSet.originalFileLocal, Settings.Default.MediumEdge, CompositingQuality.HighSpeed); CreateThumbnailForImage(pathSet.smallThumbLocal, pathSet.originalFileLocal, Settings.Default.SmallEdge, CompositingQuality.HighQuality); // Create a photo object, prepopulate it with some default values and save to DB. This will prevent us from creating orphan // image files in case something goes wrong with the edit photo data page later. Photo photo = new Photo(); // prepopulate photo with public paths, which are what we need to use later. photo.PathToOriginalFile = pathSet.originalFilePublic; photo.PathToMediumThumb = pathSet.mediumThumbPublic; photo.PathToSmallThumb = pathSet.smallThumbPublic; // Find out size and store the details. Image original = Image.FromFile(pathSet.originalFileLocal); photo.Width = original.Width; photo.Height = original.Height; photo.Aspect = (float)photo.Width / (float)photo.Height; // Dates and preference. TimeSpan typicalProcessingTime = TimeSpan.FromDays(Properties.Settings.Default.TypicalProcessingTimeInDays); photo.DateTaken = DateTime.Today.Subtract(typicalProcessingTime); photo.DateUploaded = DateTime.Today; photo.Preference = Settings.Default.DefaultPreference; // TODO: run a validation. ValidateModel(photo); // save _photoRepository.Add(photo); _photoRepository.Save(); // Now to user-supplied metadata. return RedirectToAction("EditPhotoData", new { photoId = photo.PhotoId }); }
private static Node InnerGet( NodeType nodeType, PathSet pathSet, FixedParamSet paramSet ) { if (pathSet == null) { throw new ArgumentException("Required pathSet."); } if (paramSet == null) { throw new ArgumentException("Required paramSet."); } var result = new Node(); switch (nodeType) { case NodeType.File: { if (pathSet.Elements.Length <= 0) { throw new ArgumentException($"Invalid File Path. : {pathSet.FullPath}"); } result.Type = NodeType.File; result.Name = pathSet.Elements.Last(); break; } case NodeType.Folder: { if (string.IsNullOrEmpty(pathSet.Share)) { throw new ArgumentException($"Invalid Folder Path. : {pathSet.FullPath}"); } result.Type = NodeType.Folder; result.Name = (0 < pathSet.Elements.Length) ? pathSet.Elements.Last() : pathSet.Share; break; } case NodeType.Server: { if (!string.IsNullOrEmpty(pathSet.Share)) { throw new ArgumentException($"Invalid Server Path. : {pathSet.FullPath}"); } result.Type = NodeType.Server; result.Name = pathSet.IpAddressString; break; } default: throw new Exception($"Unexpected NodeType: {nodeType}"); } result.PathSet = pathSet; result.ParamSet = paramSet; return(result); }
/// <summary> /// Populates the passed in object with the correct set of paths. /// </summary> private void PopulatePaths(PathSet pathset, string fileName) { pathset.originalFilePublic = Path.Combine("~/" + Settings.Default.PhotoCatalogFolder, Settings.Default.OriginalFileFolder, fileName); pathset.originalFileLocal = Server.MapPath(pathset.originalFilePublic); pathset.mediumThumbPublic = Path.Combine("~/" + Settings.Default.PhotoCatalogFolder, Settings.Default.MediumThumbsFolder, fileName); pathset.mediumThumbLocal = Server.MapPath(pathset.mediumThumbPublic); pathset.smallThumbPublic = Path.Combine("~/" + Settings.Default.PhotoCatalogFolder, Settings.Default.SmallThumbsFolder, fileName); pathset.smallThumbLocal = Server.MapPath(pathset.smallThumbPublic); }
private bool DoInputNewFileName(string newText) { if (string.IsNullOrEmpty(newText)) { return(true); } string[] newFileNames = newText.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'); List <Node> filesAndDirs = GetFilesAndDirsHard(buffer.Controller); if (newFileNames.Length != filesAndDirs.Count) { return(true); } for (int i = 0; i < newFileNames.Length; i++) { if (filesAndDirs[i].fullPath == ".." || newFileNames[i] == "..") { return(true); } newFileNames[i] = newFileNames[i].TrimStart(); if (string.IsNullOrEmpty(newFileNames[i])) { return(true); } } mainForm.Dialogs.CloseRename(); PathSet oldPostfixed = new PathSet(); PathSet newFullPaths = new PathSet(); List <KeyValuePair <Node, string> > pairs = new List <KeyValuePair <Node, string> >(); for (int i = 0; i < filesAndDirs.Count; i++) { Node nodeI = filesAndDirs[i]; string fileName = newFileNames[i]; pairs.Add(new KeyValuePair <Node, string>(nodeI, fileName)); if (!string.IsNullOrEmpty(renamePostfixed)) { oldPostfixed.Add(filesAndDirs[i].fullPath + renamePostfixed); } } foreach (KeyValuePair <Node, string> pair in pairs) { Node nodeI = pair.Key; string fileName = pair.Value; if (!string.IsNullOrEmpty(renamePostfixed)) { oldPostfixed.Remove(nodeI.fullPath); } } List <List <KeyValuePair <Node, string> > > levels = new List <List <KeyValuePair <Node, string> > >(); foreach (KeyValuePair <Node, string> pair in pairs) { int level = GetPartsLevel(pair); if (level >= levels.Count) { while (levels.Count < level + 1) { levels.Add(null); } } if (levels[level] == null) { levels[level] = new List <KeyValuePair <Node, string> >(); } levels[level].Add(pair); } for (int i = levels.Count; i-- > 0;) { List <KeyValuePair <Node, string> > pairsI = levels[i]; if (pairsI == null) { continue; } foreach (KeyValuePair <Node, string> pair in pairsI) { Node nodeI = pair.Key; string fileName = pair.Value; if (nodeI.type == NodeType.File || nodeI.type == NodeType.Directory) { try { if (nodeI.type == NodeType.File) { FileMove(nodeI.fullPath, newFullPaths.Add(Path.Combine(Path.GetDirectoryName(nodeI.fullPath), fileName))); } else if (nodeI.type == NodeType.Directory) { DirectoryMove(nodeI.fullPath, newFullPaths.AddDirectory(Path.Combine(Path.GetDirectoryName(nodeI.fullPath), fileName), nodeI.fullPath)); } if (!string.IsNullOrEmpty(renamePostfixed) && oldPostfixed.Contains(nodeI.fullPath + renamePostfixed) && File.Exists(nodeI.fullPath + renamePostfixed)) { FileMove(nodeI.fullPath + renamePostfixed, Path.Combine(Path.GetDirectoryName(nodeI.fullPath), fileName + renamePostfixed)); } } catch (IOException e) { mainForm.Log.WriteError("Rename error", e.Message); mainForm.Log.Open(); break; } } } } mainForm.UpdateAfterFileRenamed(); Reload(); PutCursors(newFullPaths); return(true); }