Ejemplo n.º 1
0
        private void PasteFile(string path)
        {
            var type = PasteFiles(path, out string[] destPath, out string[] sourcePath);

            if (type != 0)
            {
                foreach (var v in Enumerable.Range(0, destPath.Length))
                {
                    var      dest     = destPath[v];
                    var      src      = sourcePath[v];
                    var      sha      = GetSHA256(src);
                    var      withTags = containTagList.ContainsKey(sha);
                    string[] tagData  = null;
                    if (withTags)
                    {
                        tagData = containTagList[sha].TagItems.ToArray();
                    }
                    if (type == 2)
                    {
                        if (Path.GetDirectoryName(src) == currentDirectory)
                        {
                            var fileName = Path.GetFileName(src);
                            var index    = GetFileItemsList().IndexOf(fileItems.FirstOrDefault(n => n.Name == fileName));
                            if (index >= 0)
                            {
                                GetFileItemsList().RemoveAt(index);
                            }
                            if (metroCheckBox1.Checked)
                            {
                                index = rawFileItems.IndexOf(fileItems.FirstOrDefault(n => n.Name == fileName));
                                if (index >= 0)
                                {
                                    rawFileItems.RemoveAt(index);
                                }
                            }
                            UpdateFileList();
                        }
                        if (withTags)
                        {
                            containTagList.Remove(sha);
                        }
                    }
                    if (dest.Contains(GetSSFolderPath()))
                    {
                        var newSHA = GetSHA256(dest);
                        if (tagData != null)
                        {
                            if (containTagList.ContainsKey(newSHA))
                            {
                                containTagList.Add(newSHA, new FilePathTagList()
                                {
                                    TagItems = tagData.ToList(), FilePath = dest
                                });
                            }
                            else
                            {
                                containTagList[newSHA].TagItems = tagData.ToList();
                            }
                        }
                        if (Path.GetDirectoryName(dest) == currentDirectory)
                        {
                            if (File.GetAttributes(dest).HasFlag(FileAttributes.Directory))
                            {
                                var dirInfo  = new DirectoryInfo(dest);
                                var fileItem = new FileItem();
                                fileItem.Name = dirInfo.Name;
                                fileItem.Size = new FileSize(-1);
                                fileItem.Date = dirInfo.LastWriteTime.ToString();
                                fileItem.AddTag("Folder");
                                GetFileItemsList().Add(fileItem);
                            }
                            else
                            {
                                var info     = new FileInfo(dest);
                                var fileItem = new FileItem();
                                fileItem.Name = info.Name;
                                fileItem.Size = new FileSize(info);
                                fileItem.Date = info.LastWriteTime.ToString();
                                if (containTagList.ContainsKey(newSHA))
                                {
                                    foreach (var tag in containTagList[newSHA].TagItems)
                                    {
                                        fileItem.AddTag(tag);
                                    }
                                }
                                GetFileItemsList().Add(fileItem);
                            }
                            UpdateFileList();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void UpdateFileList()
        {
            if (!fileListRefresher.IsBusy)
            {
                var flag = false;
                if (fileItems == null)
                {
                    flag      = true;
                    fileItems = new SortableFileItems();
                }
                var selectedFile = "";
                if (lastSelectedFileIndex >= 0)
                {
                    selectedFile = fileItems[lastSelectedFileIndex].Name;
                }
                lastSelectedFileIndex = -1;
                fileItems.Clear();
                if (tempFileItems != null)
                {
                    rawFileItems  = tempFileItems;
                    tempFileItems = null;
                }
                if (metroCheckBox1.Checked && metroComboBox2.SelectedItem != null)
                {
                    tempFileItems = rawFileItems;
                    rawFileItems  = new List <FileItem>();
                    var           tagContainFiles = new Dictionary <string, string>();
                    var           selectedTag     = (metroComboBox2.SelectedItem as TagItem).Name;
                    List <string> missingFiles    = null;

                    foreach (var v in containTagList.Where(n => n.Value.TagItems.Contains(selectedTag)))
                    {
                        var path = v.Value.FilePath;
                        if (File.Exists(path))
                        {
                            var info     = new FileInfo(path);
                            var fileItem = new FileItem();
                            fileItem.Name = path;
                            fileItem.Size = new FileSize(info);
                            fileItem.Date = info.LastWriteTime.ToString();
                            fileItem.Tags.AddRange(v.Value.TagItems);
                            rawFileItems.Add(fileItem);
                        }
                        else
                        {
                            if (missingFiles == null)
                            {
                                missingFiles = new List <string>();
                            }

                            missingFiles.Add(v.Key);
                        }
                    }
                    if (missingFiles != null)
                    {
                        foreach (var v in missingFiles)
                        {
                            containTagList.Remove(v);
                        }
                    }
                }
                foreach (var v in rawFileItems)
                {
                    fileItems.Add(v);
                }
                metroGrid1.Enabled    = true;
                metroGrid1.DataSource = fileItems;
                metroGrid1.ScrollBars = ScrollBars.Both;
                ((CurrencyManager)metroGrid1.BindingContext[fileItems]).Refresh();
                metroGrid1.Columns[0].Frozen = true;
                metroGrid1.Refresh();
                if (flag)
                {
                    metroGrid1.Sort(metroGrid1.Columns[0], ListSortDirection.Descending);
                }
                if (!string.IsNullOrEmpty(selectedFile))
                {
                    var item  = fileItems.FirstOrDefault(n => n.Name == selectedFile);
                    var index = -1;
                    if (item != null)
                    {
                        index = fileItems.IndexOf(item);
                    }
                    if (index >= 0)
                    {
                        metroGrid1.Rows[index].Cells[0].Selected = true;
                        metroGrid1_SelectionChanged(metroGrid1, null);
                    }
                }
                SortRows(metroGrid1.SortedColumn, false);
            }
        }