void commandReceived(Model.Commands.Command c) { if (c is Model.Commands.PrivateChatCommand) { Model.Commands.PrivateChatCommand chat = (Model.Commands.PrivateChatCommand)c; foreach (string s in chat.content.Split('\n')) { string w = DateTime.Now.ToShortTimeString() + " " + p.username + ": " + s; try { if (this.InvokeRequired) { this.Invoke(new Action(delegate() { addLine(w); })); } else { addLine(w); } } catch (InvalidOperationException) { } } } if (c is Model.Commands.FileListing) { Model.Commands.FileListing f = (Model.Commands.FileListing)c; lastFileListing = f; if (f.path == currentPath) { try { if (this.InvokeRequired) { this.Invoke(new Action(delegate() { doUpdate(f); })); } else { doUpdate(f); } } catch (InvalidOperationException) { } } } }
void doUpdate(Model.Commands.FileListing list) { connected = true; ignoreReselect = true; foldersView.BeginUpdate(); //foldersView.Nodes.Clear(); TreeNode root = traverse(list.path); root.Nodes.Clear(); foreach (Model.Commands.FSListing i in list.folders) { TreeNode t = new TreeNode(i.name); t.Name = i.name; root.Nodes.Add(t); } foldersView.EndUpdate(); filesView.BeginUpdate(); filesView.Items.Clear(); if (list.path != "/") { filesView.Items.Add(new ListViewItem("..")); } foreach (Model.Commands.FSListing i in list.folders) { ListViewItem l = new ListViewItem(); l.Text = i.name; l.Name = i.name; l.SubItems.Add(ByteFormatter.formatBytes(i.size)); l.SubItems.Add(DateFormatter.formatDate(i.updated)); l.Tag = i; filesView.Items.Add(l); try { if (!iconCache.Images.ContainsKey("Folder")) { iconCache.Images.Add("Folder", IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed)); } l.ImageKey = "Folder"; } catch { //don't care } } foreach (Model.Commands.FSListing i in list.files) { ListViewItem l = new ListViewItem(); l.Text = i.name; l.Name = i.name; l.SubItems.Add(ByteFormatter.formatBytes(i.size)); l.SubItems.Add(DateFormatter.formatDate(i.updated)); l.Tag = i; filesView.Items.Add(l); string s = i.name; if (i.name.Contains(".")) { s = s.Substring(s.LastIndexOf(".") + 1); } try { if (!iconCache.Images.ContainsKey(s)) { iconCache.Images.Add(s, IconReader.GetFileIcon("filename." + s, IconReader.IconSize.Small, false)); } l.ImageKey = s; } catch { //don't care } } filesView.EndUpdate(); ignoreReselect = false; updateFilterList(); }