コード例 #1
0
        //**********************************************************************************************
        public void QueueDownloadItem(bool IsDir, string source, string destination, string name, int ImageIndex, long size)
        {
            form.currentItem.Text = $"Queueing {source}";

            Cursor.Current = Cursors.WaitCursor;
            QueueItem queue = new QueueItem();

            queue.Download        = true;
            queue.SourceIsdir     = IsDir;
            queue.SourcePath      = source;
            queue.ImageIndex      = ImageIndex;
            queue.Name            = name;
            queue.DestinationPath = Path.Combine(destination, name);
            queue.Status          = QueueStatus.Queue;
            queue.Size            = size;
            InsertOnQueue(queue);

            if (IsDir)
            {
                var task   = Task.Run(async() => await remoteIO.ListDirectory(source));
                var result = task.Result;
                if (result.Success)
                {
                    foreach (XwRemoteIOItem item in result.Items)
                    {
                        int image = ShellImageList.GetFileImageIndex(item.Name, (item.IsDirectory) ? FileAttributes.Directory : FileAttributes.Archive);
                        QueueDownloadItem(item.IsDirectory, item.FullName, queue.DestinationPath, item.Name, image, item.Size);
                    }
                }
                else
                {
                    form.Log(result.Message, Color.Red);
                }
            }
        }
コード例 #2
0
ファイル: XwShellTree.cs プロジェクト: maxsnts/XwMaxLib
        //***********************************************************************************************
        public void Load()
        {
            BeginUpdate();
            Nodes.Clear();
            desktop            = new TreeNode(System.Environment.SpecialFolder.Desktop.ToString());
            desktop.Tag        = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            desktop.ImageIndex = desktop.SelectedImageIndex = ShellImageList.GetSpecialFolderImageIndex(ShellAPI.CSIDL.DESKTOP);
            Nodes.Add(desktop);
            SelectedNode = desktop;

            TreeNode documents = new TreeNode(System.Environment.SpecialFolder.MyDocuments.ToString());

            documents.Tag        = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            documents.ImageIndex = documents.SelectedImageIndex = ShellImageList.GetFileImageIndex(documents.Tag.ToString(), FileAttributes.Directory | FileAttributes.System);
            desktop.Nodes.Add(documents);
            LoadNode(documents, true);

            computer            = new TreeNode(System.Environment.SpecialFolder.MyComputer.ToString());
            computer.Tag        = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
            computer.ImageIndex = computer.SelectedImageIndex = ShellImageList.GetSpecialFolderImageIndex(ShellAPI.CSIDL.DRIVES);
            desktop.Nodes.Add(computer);

            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                if (string.Compare(drive.Name, "A:\\", true) == 0 && drive.DriveType == DriveType.Removable)
                {
                    continue;
                }

                if (string.Compare(drive.Name, "B:\\", true) == 0 && drive.DriveType == DriveType.Removable)
                {
                    continue;
                }

                string   name    = String.Format("{0} ({1})", (drive.IsReady)?drive.VolumeLabel:drive.DriveType.ToString(), drive.Name.Replace("\\", ""));
                TreeNode drvNode = new TreeNode(name);
                drvNode.Tag        = drive.RootDirectory.FullName;
                drvNode.ImageIndex = drvNode.SelectedImageIndex = ShellImageList.GetFileImageIndex(drive.Name, FileAttributes.Device);
                computer.Nodes.Add(drvNode);

                if (drive.IsReady)
                {
                    DirectoryInfo   checkD = new DirectoryInfo(drive.RootDirectory.FullName);
                    DirectoryInfo[] check  = checkD.GetDirectories();
                    if (check.Length > 0)
                    {
                        TreeNode dummy = new TreeNode(string.Empty);
                        drvNode.Nodes.Add(dummy);
                    }
                }
            }

            LoadNode(desktop, true);
            desktop.Expand();
            computer.Expand();
            EndUpdate();

            RegisterForDeviceChange(true);
        }
コード例 #3
0
ファイル: QueueList.cs プロジェクト: maxsnts/XwRemote
        //*************************************************************************************************************
        public void QueueUploadItem(bool IsDir, string source, string destination, string name, int ImageIndex, long size)
        {
            if (source.IsIn(".", ".."))
            {
                return;
            }

            form.statusMainLabel.Text = $"Queueing {source}";

            QueueItem queue = new QueueItem();

            queue.Download          = false;
            queue.SourceIsdir       = IsDir;
            queue.SourcePath        = source;
            queue.ImageIndex        = ImageIndex;
            queue.Name              = name;
            queue.DestinationPath   = Path.Combine(destination, name);
            queue.Status            = QueueStatus.Queue;
            queue.Size              = size;
            queue.CancelTokenSource = new CancellationTokenSource();
            InsertOnQueue(queue);

            if (IsDir)
            {
                DirectoryInfo DirInfo = new DirectoryInfo(source);
                foreach (DirectoryInfo dir in DirInfo.GetDirectories())
                {
                    if ((dir.Attributes & FileAttributes.Hidden) != 0)
                    {
                        continue;
                    }

                    QueueUploadItem(true, dir.FullName, queue.DestinationPath, dir.Name,
                                    ShellImageList.GetFileImageIndex("Folder", FileAttributes.Directory), 0);
                }

                foreach (FileInfo file in DirInfo.GetFiles())
                {
                    if ((file.Attributes & FileAttributes.Hidden) != 0)
                    {
                        continue;
                    }

                    QueueUploadItem(false, file.FullName, queue.DestinationPath, file.Name,
                                    ShellImageList.GetFileImageIndex(file.Name, FileAttributes.Archive), file.Length);
                }
            }
        }
コード例 #4
0
        //*************************************************************************************************************
        private void this_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop)) //from explorer
            {
                string[] filePaths = (string[])e.Data.GetData("FileDrop");
                Cursor.Current = Cursors.WaitCursor;
                foreach (string path in filePaths)
                {
                    DiskItem disk;
                    int      imageIndex = 0;

                    if (Directory.Exists(path))
                    {
                        disk       = new DiskItem(true, false, path, Path.GetFileName(path));
                        imageIndex = ShellImageList.GetFileImageIndex(disk.path, FileAttributes.Directory);
                    }
                    else
                    {
                        FileInfo f = new FileInfo(path);
                        disk       = new DiskItem(false, false, path, Path.GetFileName(path), f.Length);
                        imageIndex = ShellImageList.GetFileImageIndex(disk.path, File.GetAttributes(path));
                    }
                    form.QueueList.QueueUploadItem(disk.IsDirectory, disk.path,
                                                   CurrentDirectory, disk.name, imageIndex, disk.size);
                }
            }
            else //from listview
            {
                System.Windows.Forms.ListView.SelectedListViewItemCollection items =
                    (System.Windows.Forms.ListView.SelectedListViewItemCollection)e.Data.GetData(
                        typeof(System.Windows.Forms.ListView.SelectedListViewItemCollection));
                Cursor.Current = Cursors.WaitCursor;
                foreach (ListViewItem item in items)
                {
                    DiskItem disk = (DiskItem)item.Tag;
                    form.QueueList.QueueUploadItem(disk.IsDirectory, disk.path,
                                                   CurrentDirectory, disk.name, item.ImageIndex, disk.size);
                }
            }

            form.QueueList.StartQueue();

            form.LocalList.AllowDrop = true;
            AllowDrop = true;
        }
コード例 #5
0
ファイル: XwShellTree.cs プロジェクト: maxsnts/XwMaxLib
        //***********************************************************************************************
        public void LoadNode(TreeNode node, bool init)
        {
            if ((node == desktop || node == computer) && init == false)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            if (init == false)
            {
                node.Nodes.Clear();
            }

            DirectoryInfo nodeDirInfo = new DirectoryInfo(node.Tag.ToString());

            foreach (DirectoryInfo dir in nodeDirInfo.GetDirectories())
            {
                if ((dir.Attributes & FileAttributes.Hidden) != 0)
                {
                    continue;
                }

                TreeNode child = new TreeNode(dir.Name);
                child.ImageIndex = child.SelectedImageIndex = ShellImageList.GetFileImageIndex(dir.FullName, dir.Attributes);
                child.Tag        = dir.FullName;
                node.Nodes.Add(child);

                try
                {
                    DirectoryInfo[] check = dir.GetDirectories();
                    if (check.Length > 0)
                    {
                        TreeNode dummy = new TreeNode(string.Empty);
                        child.Nodes.Add(dummy);
                    }
                }
                catch { }
            }

            Cursor.Current = Cursors.Default;
        }
コード例 #6
0
        //********************************************************************************************
        public void RealLoadList(string path, bool skipCheckLink)
        {
            BeginUpdate();
            Items.Clear();

            if (skipCheckLink)
            {
                form.SkipCheckLink = true;
            }

            if (path == string.Empty && form.LocalTree.SelectedNode != null) //my computer
            {
                foreach (TreeNode n in form.LocalTree.SelectedNode.Nodes)
                {
                    ListViewItem i = Items.Add(n.Text, n.ImageIndex);
                    i.Tag = new DiskItem(true, false, n.Tag.ToString(), "");
                }
            }
            else
            {
                try
                {
                    if (path.Contains("\\\\") && !path.Replace("\\\\", "").Contains("\\"))
                    {
                        try
                        {
                            //New instance of the management path so we can use its properties
                            ManagementPath mpath = new ManagementPath();
                            //Set the Servername
                            mpath.Server = path.Replace("\\\\", "");
                            //Set the WMI namespace
                            mpath.NamespacePath = @"root\cimv2";
                            //Here we are using the default connections but we can also use different.
                            //Username and password if we need to.
                            ConnectionOptions oConn = new ConnectionOptions();
                            //Set the Scope ...Computername and WMI namespace
                            ManagementScope scope = new ManagementScope(path, oConn);
                            //Set the WMI Class
                            mpath.RelativePath = "Win32_Share";

                            //Set shares to null
                            ManagementClass Shares = null;
                            //Here we are connecting using the Servername and WMI Namespace/Class
                            using (Shares = new ManagementClass(scope, mpath, null))
                            {
                                //Return a collection of Shares here
                                ManagementObjectCollection moc = Shares.GetInstances();

                                //Go thru each share and display its name property in the list box.
                                foreach (ManagementObject mo in moc)
                                {
                                    string       share = mo["Name"].ToString();
                                    ListViewItem item  = new ListViewItem(share, 0);
                                    item.Tag        = new DiskItem(true, false, Path.Combine(path, share), share);
                                    item.ImageIndex = ShellImageList.GetSpecialFolderImageIndex((ShellAPI.CSIDL) 49);
                                    Items.Add(item);
                                }
                            }
                        }
                        catch (Exception) //catch any exceptions we might have .
                        {
                            MessageBox.Show("Unable to return sharenames . Please make share Servername is correct.");
                        }
                    }
                    else
                    {
                        DirectoryInfo nodeDirInfo = new DirectoryInfo(path);
                        ListViewItem.ListViewSubItem[] subItems;
                        ListViewItem item = null;

                        DirectoryInfo[] dirs = nodeDirInfo.GetDirectories();

                        ListViewItem item1 = Items.Add(".", ShellImageList.GetFileImageIndex(".", FileAttributes.Directory));
                        item1.Tag       = new DiskItem(true, false, ".", ".");
                        item1.BackColor = Color.FromArgb(240, 240, 240);
                        ListViewItem item2 = Items.Add("..", ShellImageList.GetFileImageIndex("Folder", FileAttributes.Directory));
                        item2.Tag       = new DiskItem(true, false, "..", "..");
                        item2.BackColor = Color.FromArgb(230, 230, 230);

                        foreach (DirectoryInfo dir in dirs)
                        {
                            if ((dir.Attributes & FileAttributes.Hidden) != 0)
                            {
                                continue;
                            }

                            item     = new ListViewItem(dir.Name, 0);
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, " - - - "),
                                new ListViewItem.ListViewSubItem(item,
                                                                 dir.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"))
                            };

                            item.SubItems.AddRange(subItems);
                            item.Tag        = new DiskItem(true, false, dir.FullName, dir.Name);
                            item.ImageIndex = ShellImageList.GetFileImageIndex(dir.FullName, dir.Attributes);
                            Items.Add(item);
                        }

                        foreach (FileInfo file in nodeDirInfo.GetFiles())
                        {
                            if ((file.Attributes & FileAttributes.Hidden) != 0)
                            {
                                continue;
                            }

                            item     = new ListViewItem(file.Name, 1);
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, String.Format("{0:0,0}", file.Length)),
                                new ListViewItem.ListViewSubItem(item,
                                                                 file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"))
                            };

                            item.SubItems.AddRange(subItems);
                            item.Tag = new DiskItem(false, false, file.FullName, file.Name, file.Length);
                            //item.ImageIndex = ShellImageList.GetFileImageIndex(file.FullName, file.Attributes);
                            item.ImageIndex = ShellImageList.GetFileImageIndex(file.FullName, file.Attributes);
                            Items.Add(item);
                        }

                        if (!string.IsNullOrEmpty(path))
                        {
                            fileSystemWatcher.Path = path;
                            fileSystemWatcher.EnableRaisingEvents = true;
                        }
                        else
                        {
                            fileSystemWatcher.EnableRaisingEvents = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Path", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            EndUpdate();
            form.statusLocalCount.Text = String.Format("{0} Items", (Items.Count > 2)?Items.Count - 2:0);

            CurrentDirectory    = path;
            form.LocalPath.Text = path;
            CheckPin();
        }
コード例 #7
0
        //*************************************************************************************************************
        public async Task LoadList(string path)
        {
            Cursor.Current = Cursors.WaitCursor;
            BackColor      = Color.FromArgb(240, 240, 240);

            try
            {
                if (!remoteIO.IsConnected)
                {
                    await remoteIO.Reconnect();
                }

                if (path == ".")
                {
                    path = "/";
                }
                if (path == "..")
                {
                    path = CurrentDirectory.GetUnixParentPath();
                }

                var result = await remoteIO.ListDirectory(path);

                if (result.Success)
                {
                    form.Log(result.Message);

                    BeginUpdate();
                    Items.Clear();

                    ListViewItem item1 = Items.Add(".", ShellImageList.GetFileImageIndex("c:", FileAttributes.Device));
                    item1.Tag       = new DiskItem(true, false, ".", "");
                    item1.BackColor = Color.FromArgb(240, 240, 240);
                    ListViewItem item2 = Items.Add("..", ShellImageList.GetFileImageIndex("Folder", FileAttributes.Directory));
                    item2.Tag       = new DiskItem(true, false, "..", "");
                    item2.BackColor = Color.FromArgb(230, 230, 230);

                    ListViewItem.ListViewSubItem[] subItems;
                    ListViewItem item = null;

                    foreach (XwRemoteIOItem remoteItem in result.Items)
                    {
                        if (!remoteItem.IsDirectory)
                        {
                            continue;
                        }

                        item     = new ListViewItem(remoteItem.Name, 0);
                        subItems = new ListViewItem.ListViewSubItem[]
                        {
                            new ListViewItem.ListViewSubItem(item, " - - - "),
                            new ListViewItem.ListViewSubItem(item,
                                                             (remoteItem.Modified == DateTime.MinValue)
                        ? "- - -"
                        : remoteItem.Modified.ToString("yyyy-MM-dd HH:mm:ss"))
                        };

                        item.SubItems.AddRange(subItems);
                        item.Tag = new DiskItem(remoteItem.IsDirectory,
                                                remoteItem.IsSymlink, remoteItem.FullName, remoteItem.Name);
                        item.ImageIndex = ShellImageList.GetFileImageIndex(remoteItem.Name,
                                                                           FileAttributes.Directory | ((remoteItem.IsSymlink) ? FileAttributes.Compressed : 0));

                        Items.Add(item);
                    }

                    foreach (XwRemoteIOItem remoteItem in result.Items)
                    {
                        if (remoteItem.IsDirectory)
                        {
                            continue;
                        }

                        item     = new ListViewItem(remoteItem.Name, 0);
                        subItems = new ListViewItem.ListViewSubItem[]
                        {
                            new ListViewItem.ListViewSubItem(item, string.Format("{0:0,0}", remoteItem.Size)),
                            new ListViewItem.ListViewSubItem(item,
                                                             (remoteItem.Modified == DateTime.MinValue)
                        ? "- - -"
                        : remoteItem.Modified.ToString("yyyy-MM-dd HH:mm:ss"))
                        };

                        item.SubItems.AddRange(subItems);
                        item.Tag = new DiskItem(remoteItem.IsDirectory, remoteItem.IsSymlink,
                                                remoteItem.FullName, remoteItem.Name, remoteItem.Size);
                        item.ImageIndex = ShellImageList.GetFileImageIndex(remoteItem.Name,
                                                                           FileAttributes.Normal | ((remoteItem.IsSymlink) ? FileAttributes.Compressed : 0));

                        Items.Add(item);
                    }

                    EndUpdate();

                    form.statusRemoteCount.Text = string.Format("{0} Items", (Items.Count > 2) ? Items.Count - 2 : 0);

                    CurrentDirectory     = path;
                    form.RemotePath.Text = CurrentDirectory;
                    CheckPin();
                }
                else
                {
                    if (form.splitContainerStatus.Visible) //connecting
                    {
                        form.Log($"An error occurred while retrieving the directory list.\nReason: {result.Message}",
                                 Color.Red);
                    }
                    else
                    {
                        form.loadingCircle1.Active  = true;
                        form.loadingCircle1.Visible = false;
                        form.SetStatusText(result.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                form.Log(ex.Message, Color.Red);
                Enabled = true;
            }

            Cursor.Current = Cursors.Default;
            BackColor      = SystemColors.Window;
        }