private void SetDefault(Directory directory, DirectoryInfo directoryInfo)
        {
            labelName.Text = directory.Name;
            labelType.Text = "File folder";
            icon.Image     = new Icon(Properties.Resources.Folder, new Size(64, 64)).ToBitmap();
            StringBuilder sb = new StringBuilder();

            if (UserSettings.Mode != Mode.BASIC)
            {
                sb.AppendLine($"Path: {directory.Path}");
            }
            if (directoryInfo != null)
            {
                if (directoryInfo.ItemCount > 0)
                {
                    sb.AppendLine($"Items: {directoryInfo.ItemCount}");
                }
                if (directoryInfo.TotalByteSize > 0)
                {
                    if (UserSettings.Mode == Mode.BASIC)
                    {
                        sb.AppendLine($"Size: {DirectoryContent.ToFileSize(directoryInfo.TotalByteSize)}");
                    }
                    else
                    {
                        sb.AppendLine($"Size: {DirectoryContent.ToByteFileSize(directoryInfo.TotalByteSize)}");
                    }
                }
            }
            textBoxInfo.Text = sb.ToString();
        }
 public void Set(DirectoryInfo info)
 {
     if (info.TotalByteSize == 0)
     {
         toolStripLabel.Text = $"{info.ItemCount} items";
     }
     else
     {
         toolStripLabel.Text = $"{info.ItemCount} items ({DirectoryContent.ToFileSize(info.TotalByteSize)})";
     }
 }
        public async Task Initialize()
        {
            Directory root = await BrickExplorer.GetDirectory(BrickExplorer.ROOT_PATH);

            CURRENT_DIRECTORY  = root;
            SELECTED_DIRECTORY = root;
            await folderTree.Initialize(root);

            await previewPane.Initialize(root);

            navigationBar.Initialize();
            DirectoryContent content = await DirectoryContent.Get(root);

            directoryContentPane.Set(content);
            statusBar.Set(content.Info);

            if (UserSettings.Mode == Mode.BASIC)
            {
                Directory drive = await BrickExplorer.GetDirectory(BrickExplorer.PROJECTS_PATH);

                Execute(this, drive, ActionType.OPEN);
            }
        }
        public static async Task <DirectoryContent> Get(Directory directory)
        {
            DirectoryContent content = new DirectoryContent
            {
                Path = directory.Path,
                Info = new DirectoryInfo(),
            };

            switch (UserSettings.Mode)
            {
            case Mode.BASIC:
            {
                switch (directory.Path)
                {
                case BrickExplorer.ROOT_PATH:
                {
                    List <Directory> dirs = new List <Directory>();
                    dirs.Add(await BrickExplorer.GetDirectory(BrickExplorer.PROJECTS_PATH));
                    if (Manager.Brick.SDCard != null)
                    {
                        dirs.Add(await BrickExplorer.GetDirectory(BrickExplorer.SDCARD_PATH));
                    }
                    content.Directories    = dirs.ToArray();
                    content.Info.ItemCount = content.Directories.Length;
                    break;
                }

                case BrickExplorer.PROJECTS_PATH:
                {
                    content.Directories = await Manager.Brick.Drive.GetDirectories();

                    content.Info.ItemCount = content.Directories.Length;
                    break;
                }

                case BrickExplorer.SDCARD_PATH:
                {
                    content.Directories = await Manager.Brick.SDCard.GetDirectories();

                    content.Info.ItemCount = content.Directories.Length;
                    break;
                }

                default:
                {
                    //only get files
                    content.Files = await BrickExplorer.GetFiles(directory.Path);

                    foreach (File file in content.Files)
                    {
                        content.Info.TotalByteSize += file.Size;
                    }
                    content.Info.ItemCount = content.Files.Length;
                    break;
                }
                }
                return(content);
            }

            default:
            {
                Framework.Core.DirectoryContent dc = await BrickExplorer.GetDirectoryContent(directory.Path);

                content.Directories = dc.Directories;
                content.Files       = dc.Files;
                foreach (File file in content.Files)
                {
                    content.Info.TotalByteSize += file.Size;
                }
                content.Info.ItemCount = content.Directories.Length + content.Files.Length;
                return(content);
            }
            }
        }
        public async Task Set(File file)
        {
            Clear();

            labelName.Text = file.FileName;
            labelType.Text = DirectoryContent.ToString(file.Type);
            string additionalInfo = null;

            switch (file.Type)
            {
            case FileType.TextFile:
            {
                icon.Image             = new Icon(Properties.Resources.Rtf, new Size(64, 64)).ToBitmap();
                previewContent.Text    = await((TextFile)file).DownloadAsString();
                previewContent.Visible = true;
                break;
            }

            case FileType.SoundFile:
            {
                icon.Image = new Icon(Properties.Resources.Rsf, new Size(64, 64)).ToBitmap();
                break;
            }

            case FileType.GraphicFile:
            {
                icon.Image = new Icon(Properties.Resources.Rgf, new Size(64, 64)).ToBitmap();
                byte[] data = await file.Download();

                Bitmap bitmap = FileConverter.RGFtoBitmap(data, Color.FromArgb(73, 74, 75));
                int    width  = data[0];
                int    height = data[1];
                previewImage.Image   = bitmap;
                additionalInfo       = $"Dimension: {width} x {height} px";
                previewImage.Visible = true;
                break;
            }

            default:
            {
                icon.Image = new Icon(Properties.Resources.File, new Size(64, 64)).ToBitmap();
                break;
            }
            }

            StringBuilder sb = new StringBuilder();

            if (UserSettings.Mode == Mode.BASIC)
            {
                sb.AppendLine($"Size: {DirectoryContent.ToFileSize(file.Size)}");
            }
            else
            {
                sb.AppendLine($"Path: {file.Path}");
                sb.AppendLine($"Size: {DirectoryContent.ToByteFileSize(file.Size)}");
                sb.AppendLine($"Md5sum: {file.MD5SUM}");
            }
            if (additionalInfo != null)
            {
                sb.Append(additionalInfo);
            }
            textBoxInfo.Text = sb.ToString();
        }
        private async void Execute(object sender, Directory directory, ActionType type)
        {
            switch (type)
            {
            case ActionType.OPEN:
            {
                if (CURRENT_DIRECTORY.Path == directory.Path)
                {
                    return;                                                   // do not open again is already open
                }
                CURRENT_DIRECTORY  = directory;
                SELECTED_DIRECTORY = directory;
                statusBar.SetLoading();
                ((Manager)Parent).UseWaitCursor = true;
                DirectoryContent content = await DirectoryContent.Get(directory);

                previewPane.Set(directory, content.Info);
                directoryContentPane.Set(content);
                statusBar.Set(content.Info);
                navigationBar.Set(directory);
                ((Manager)Parent).UseWaitCursor = false;
                break;
            }

            case ActionType.SELECT:
            {
                SELECTED_DIRECTORY = directory;
                previewPane.Set(directory, null);
                break;
            }

            case ActionType.DOWNLOAD:
            {
                ((Manager)Parent).UseWaitCursor = true;
                await Download(SELECTED_DIRECTORY);

                ((Manager)Parent).UseWaitCursor = false;
                break;
            }

            case ActionType.CREATE_DIRECTORY:
            {
                using (CreateEntryDialog dialog = new CreateEntryDialog(CURRENT_DIRECTORY, EntryType.DIRECTORY, null))
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        string path = System.IO.Path.Combine(CURRENT_DIRECTORY.Path, dialog.EntryName);
                        await BrickExplorer.CreateDirectory(path);

                        await folderTree.Refresh(CURRENT_DIRECTORY);

                        Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                    }
                }
                break;
            }

            case ActionType.DELETE:
            {
                if (MessageBox.Show("Are you sure you want to permanently delete this directory and all it's content?", "Delete directory", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    ((Manager)Parent).UseWaitCursor = true;
                    await BrickExplorer.DeleteDirectory(directory.Path, true);

                    await folderTree.Refresh(CURRENT_DIRECTORY);

                    Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                    ((Manager)Parent).UseWaitCursor = false;
                }
                break;
            }

            case ActionType.REFRESH_DIRECTORY:
            {
                statusBar.SetLoading();
                ((Manager)Parent).UseWaitCursor = true;
                DirectoryContent content = await DirectoryContent.Get(CURRENT_DIRECTORY);

                directoryContentPane.Set(content);
                previewPane.Set(directory, content.Info);
                statusBar.Set(content.Info);
                ((Manager)Parent).UseWaitCursor = false;
                break;
            }

            case ActionType.UPLOAD_DIRECTORY:
            {
                await UploadDirectory();

                await folderTree.Refresh(CURRENT_DIRECTORY);

                Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                break;
            }
            }
        }
        public void Set(DirectoryContent content)
        {
            listView.BeginUpdate();
            listView.Items.Clear();

            if (UserSettings.Mode == Mode.BASIC && content.Path == BrickExplorer.ROOT_PATH)
            {
                foreach (Directory directory in content.Directories)
                {
                    switch (directory.Path)
                    {
                    case BrickExplorer.PROJECTS_PATH:
                    {
                        ListViewItem item = new ListViewItem("Drive")
                        {
                            Tag        = directory,
                            ImageIndex = 1
                        };
                        item.SubItems.Add("Drive");
                        item.SubItems.Add("");
                        listView.Items.Add(item);
                        break;
                    }

                    case BrickExplorer.SDCARD_PATH:
                    {
                        ListViewItem item = new ListViewItem("SD Card")
                        {
                            Tag        = directory,
                            ImageIndex = 2
                        };
                        item.SubItems.Add("SD Card");
                        item.SubItems.Add("");
                        listView.Items.Add(item);
                        break;
                    }
                    }
                }
            }
            else
            {
                if (content.Directories != null)
                {
                    foreach (Directory directory in content.Directories)
                    {
                        ListViewItem item = new ListViewItem(directory.Name)
                        {
                            Tag        = directory,
                            ImageIndex = 0
                        };
                        item.SubItems.Add("File folder");
                        item.SubItems.Add("");
                        listView.Items.Add(item);
                    }
                }
                if (content.Files != null)
                {
                    foreach (File file in content.Files)
                    {
                        //if (UseFilter && !file.Name.EndsWith(FilterValue)) continue;

                        ListViewItem item = new ListViewItem(file.FileName);
                        item.Tag = file;
                        switch (file.Type)
                        {
                        case FileType.TextFile:
                        {
                            item.ImageIndex = 6;
                            break;
                        }

                        case FileType.GraphicFile:
                        {
                            item.ImageIndex = 5;
                            break;
                        }

                        case FileType.SoundFile:
                        {
                            item.ImageIndex = 4;
                            break;
                        }

                        default:
                        {
                            item.ImageIndex = 3;
                            break;
                        }
                        }

                        item.SubItems.Add(DirectoryContent.ToString(file.Type));
                        item.SubItems.Add(DirectoryContent.ToFileSize(file.Size));
                        listView.Items.Add(item);
                    }
                }
            }

            listView.EndUpdate();
        }