public void ProcessRespondDirListingMessage(Network network, Node messageFrom, SharedDirectoryInfo info) { string fullPath = PathUtil.Join(messageFrom.Directory.FullPath, info.FullPath); var node = PathUtil.GetNode(fullPath); if (node != messageFrom) { throw new Exception("Directory was for a different node"); } RemoteDirectory remoteDirectory = GetOrCreateRemoteDirectory(fullPath); remoteDirectory.UpdateFromInfo(info); lock (remoteDirectoryCallbacks) { if (remoteDirectoryCallbacks.ContainsKey(fullPath)) { foreach (var callback in remoteDirectoryCallbacks[fullPath]) { callback(remoteDirectory); } remoteDirectoryCallbacks.Remove(fullPath); } } network.RaiseReceivedDirListing(messageFrom, remoteDirectory); }
static LocalFile CreateFile(LocalDirectory parentDirectory, string name, string localpath, long length) { int last_id = -1; string fullPath = PathUtil.Join(parentDirectory.FullPath, name); if (fullPath.Length > 1 && fullPath.EndsWith("/")) { fullPath = fullPath.Substring(0, fullPath.Length - 1); } Core.FileSystem.UseConnection(delegate(IDbConnection connection) { IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = @"INSERT INTO directoryitems (type, name, local_path, parent_id, length, full_path) VALUES ('F', @name, @local_path, @parent_id, @length, @full_path);" ; Core.FileSystem.AddParameter(cmd, "@name", name); Core.FileSystem.AddParameter(cmd, "@local_path", localpath); Core.FileSystem.AddParameter(cmd, "@parent_id", parentDirectory.Id); Core.FileSystem.AddParameter(cmd, "@length", length); Core.FileSystem.AddParameter(cmd, "@full_path", fullPath); Core.FileSystem.ExecuteNonQuery(cmd); cmd = connection.CreateCommand(); cmd.CommandText = "SELECT last_insert_rowid()"; last_id = Convert.ToInt32(Core.FileSystem.ExecuteScalar(cmd)); }, true); return(new LocalFile(last_id, parentDirectory.Id, name, localpath, length, fullPath)); }
internal void UpdateFromInfo(SharedDirectoryInfo info) { var newDirectories = new RemoteDirectory[info.Directories.Length]; for (int x = 0; x < info.Directories.Length; x++) { RemoteDirectory dir = (RemoteDirectory)GetSubdirectory(info.Directories[x]); if (dir == null) { dir = new RemoteDirectory(PathUtil.Join(m_FullPath, info.Directories[x])); } newDirectories[x] = dir; } var newFiles = new RemoteFile[info.Files.Length]; for (int x = 0; x < info.Files.Length; x++) { RemoteFile file = (RemoteFile)GetFile(info.Files[x].Name); if (file == null) { file = new RemoteFile(this, info.Files[x]); } else { file.UpdateFromInfo(info.Files[x]); } newFiles[x] = file; } m_SubDirectories = newDirectories; m_Files = newFiles; m_State = RemoteDirectoryState.ContentsReceived; }
internal RemoteDirectory CreateSubdirectory(string name) { var dir = new RemoteDirectory(PathUtil.Join(m_FullPath, name)); var newDirectories = new RemoteDirectory[m_SubDirectories.Length + 1]; Array.Copy(m_SubDirectories, newDirectories, m_SubDirectories.Length); newDirectories[newDirectories.Length - 1] = dir; m_SubDirectories = newDirectories; return(dir); }
public void ProcessFileDetailsMessage(Network network, Node messageFrom, SharedFileListing info) { string fullPath = PathUtil.Join(messageFrom.Directory.FullPath, info.FullPath); var node = PathUtil.GetNode(fullPath); if (node != messageFrom) { throw new Exception("Directory was for a different node"); } bool created = false; RemoteFile remoteFile = GetOrCreateRemoteFile(fullPath, info, out created); if (!created) { remoteFile.UpdateFromInfo(info); } lock (remoteFileCallbacks) { if (remoteFileCallbacks.ContainsKey(fullPath)) { foreach (var callback in remoteFileCallbacks[fullPath]) { callback(remoteFile); } } remoteFileCallbacks.Remove(fullPath); } network.RaiseReceivedFileDetails(remoteFile); // FIXME: Get rid of all this, just listen for above network.ReceivedFileDetails event! var transfer = this.fileTransferManager.Transfers.SingleOrDefault(t => t.File == remoteFile); if (transfer != null && transfer.Status == FileTransferStatus.WaitingForInfo) { ((IFileTransferInternal)transfer).DetailsReceived(); } }
internal NodeDirectory(Node node) : base(PathUtil.Join(node.Network.Directory.FullPath, node.NodeID)) { m_Node = node; }
private static LocalDirectory CreateDirectory(LocalDirectory parent, string name, string local_path) { string fullPath; int last_id = -1; if (String.IsNullOrEmpty(local_path)) { throw new ArgumentNullException("local_path"); } if (!System.IO.Directory.Exists(local_path)) { throw new ArgumentException("local_path", String.Format("Directory does not exist: '{0}'", local_path)); } if (parent != null) { fullPath = PathUtil.Join(parent.FullPath, name); } else { fullPath = PathUtil.Join("/", name); } if (fullPath.Length > 1 && fullPath.EndsWith("/")) { fullPath = fullPath.Substring(0, fullPath.Length - 1); } Core.FileSystem.UseConnection(delegate(IDbConnection connection) { IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = @"INSERT INTO directoryitems (type, parent_id, name, local_path, full_path) VALUES ('D', @parent_id, @name, @local_path, @full_path);" ; Core.FileSystem.AddParameter(cmd, "@name", name); Core.FileSystem.AddParameter(cmd, "@local_path", local_path); Core.FileSystem.AddParameter(cmd, "@full_path", fullPath); if (parent == null) { Core.FileSystem.AddParameter(cmd, "@parent_id", null); } else { Core.FileSystem.AddParameter(cmd, "@parent_id", (int)parent.Id); } Core.FileSystem.ExecuteNonQuery(cmd); cmd = connection.CreateCommand(); cmd.CommandText = "SELECT last_insert_rowid()"; last_id = Convert.ToInt32(Core.FileSystem.ExecuteScalar(cmd)); }, true); if (parent != null) { parent.InvalidateCache(); } int parentId = (parent == null) ? -1 : parent.Id; return(new LocalDirectory(last_id, parentId, name, local_path, fullPath)); }