Пример #1
0
        private void Test()
        {
            for (int i = 0; i < 7; i++)
            {
                string file = "C:/back/test.jpeg";

                LocalFileStructure fStruct = new LocalFileStructure();

                FileInfo fInfo = new FileInfo(file);
                fStruct.FilePath      = file;
                fStruct.FileExtension = Path.GetExtension(file);
                fStruct.FileName      = Path.GetFileNameWithoutExtension(file);
                fStruct.FileSize      = fInfo.Length;
                fStruct.FullName      = fInfo.Name;

                AddFileVisual(fStruct, 50);

                string file2 = "C:/back/carlo_and_tanja.jpg";

                LocalFileStructure fStruct2 = new LocalFileStructure();

                FileInfo fInfo2 = new FileInfo(file2);
                fStruct2.FilePath      = file2;
                fStruct2.FileExtension = Path.GetExtension(file2);
                fStruct2.FileName      = Path.GetFileNameWithoutExtension(file2);
                fStruct2.FileSize      = fInfo2.Length;
                fStruct2.FullName      = fInfo2.Name;

                AddFileVisual(fStruct2, 50 + 70 + 20);
            }
        }
Пример #2
0
        private void DragDrop_Drop(object sender, DragEventArgs de)
        {
            string[] files = (string[])de.Data.GetData(DataFormats.FileDrop);

            if (files == null || files.Length < 1)
            {
                return;
            }

            CreateFileQueueVisual();

            int id = 0;

            foreach (string file in files)
            {
                LocalFileStructure fStruct = new LocalFileStructure();
                try
                {
                    FileInfo fInfo = new FileInfo(file);
                    fStruct.FilePath      = file;
                    fStruct.FileExtension = Path.GetExtension(file);
                    fStruct.FileName      = Path.GetFileNameWithoutExtension(file);
                    fStruct.FileSize      = fInfo.Length;
                    AddNewQueuedFile(fStruct, id);
                    id++;
                }
                catch (Exception e)
                {
                    Debugger.AddErrorMessage(e.Message);
                    throw;
                }
            }
        }
Пример #3
0
        private void CreateFileQueueVisual(string[] files)
        {
            DeleteDragDropVisual();

            int id = 0;

            foreach (string file in files)
            {
                LocalFileStructure fStruct = new LocalFileStructure();
                try
                {
                    FileInfo fInfo = new FileInfo(file);
                    fStruct.FilePath      = file;
                    fStruct.FileExtension = Path.GetExtension(file);
                    fStruct.FileName      = Path.GetFileNameWithoutExtension(file);
                    fStruct.FileSize      = fInfo.Length;
                    fStruct.FullName      = fInfo.Name;
                    AddFileVisual(fStruct, 50);
                    id++;
                }
                catch (Exception e)
                {
                    Debugger.AddErrorMessage(e.Message);
                    throw;
                }
            }
        }
Пример #4
0
        private void btn_ChooseFromDevice_Click(object sender, EventArgs e)
        {
            dialog_OpenFiles.Multiselect = true;
            DialogResult dr = dialog_OpenFiles.ShowDialog();

            if (dr == DialogResult.OK)
            {
                CreateFileQueueVisual();

                int id = 0;

                foreach (String file in dialog_OpenFiles.FileNames)
                {
                    LocalFileStructure fStruct = new LocalFileStructure();
                    try
                    {
                        FileInfo fInfo = new FileInfo(file);
                        fStruct.FilePath      = file;
                        fStruct.FileExtension = Path.GetExtension(file);
                        fStruct.FileName      = Path.GetFileNameWithoutExtension(file);
                        fStruct.FileSize      = fInfo.Length;
                        AddNewQueuedFile(fStruct, id);
                        id++;
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }
Пример #5
0
        private void AddFileVisual(LocalFileStructure fileStruct, int y)
        {
            FileUploadInstance instance = new FileUploadInstance()
            {
            };

            FileUploadVisual visual = new FileUploadVisual(20, y, panel_FlowLayout.Width - 25, 70, fileStruct);

            //visual.AddToControl(MainPanel);
            visual.AddToControl(panel_FlowLayout);
        }
Пример #6
0
        /// <summary>
        /// Saves the file to the local storage
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="fStruct"></param>
        public void SaveFileToLocalStorage(byte[] buffer, LocalFileStructure fStruct)
        {
            string fullName = fStruct.FileName + fStruct.FileExtension;
            string filePath = Path.Combine(ProgramSettings.StorageFolderPath, fullName);

            filePath = GetValidPath(filePath);

            using (Stream file = File.OpenWrite(filePath))
            {
                file.Write(buffer, 0, buffer.Length);
            }
        }
Пример #7
0
        private void AddNewQueuedFile(LocalFileStructure file_struct)
        {
            int width  = (int)((decimal)FileAreaPanel.Width / 4.30M);
            int height = (int)((decimal)FileAreaPanel.Width / 4M);

            Bitmap icon;

            if (imageExtensions.Contains(file_struct.FileExtension.ToLower()))
            {
                // Create the thumbnail
                icon = new Bitmap(file_struct.FilePath);
            }
            else
            {
                icon = Icon.ExtractAssociatedIcon(file_struct.FilePath).ToBitmap();
            }

            DarkFileDisplay dfd = new DarkFileDisplay(width, height, icon, false, file_struct.FullName, panel_FlowLayoutFiles);

            dfd.FileStructure = file_struct;

            dfd.ActionOnClick(() =>
            {
                FileIconClick(dfd);
            });

            if (mainForm.InvokeRequired)
            {
                mainForm.Invoke((MethodInvoker) delegate { dfd.AddToControl(panel_FlowLayoutFiles); });
            }

            //dfd.AddToControl(panel_FlowLayoutFiles);

            FileDisplayList.Add(dfd);

            icon.Dispose();
        }
Пример #8
0
        private void AddNewQueuedFile(LocalFileStructure file_struct, int id)
        {
            FileVisualDisplay fileVis = new FileVisualDisplay();

            fileVis.ID = id;
            fileVis.FileStructLocal = file_struct;

            if (PanelFlowLayout == null)
            {
                return;
            }

            fileVis.panel_Parent = new Panel()
            {
                Name      = "Parent Panel",
                Size      = new Size(90, 100),
                BackColor = Color.Transparent
            };


            fileVis.pBox_Icon = new PictureBox()
            {
                Size     = new Size(50, 50),
                Location = new Point(18, 20),
                SizeMode = PictureBoxSizeMode.StretchImage,
                //Image = Icon.ExtractAssociatedIcon(fileStruct.FilePath).ToBitmap(),
            };

            fileVis.pBox_Checkmark = new PictureBox()
            {
                Size        = new Size(50, 50),
                Location    = new Point(0, 0),
                SizeMode    = PictureBoxSizeMode.StretchImage,
                BackColor   = Color.Transparent,
                BorderStyle = BorderStyle.None,
            };

            fileVis.pBox_Icon.Click += (sender, args) =>
            {
                ThumbnailClicked(fileVis.ID);
            };

            if (imageExtensions.Contains(file_struct.FileExtension.ToLower()))
            {
                // Create the thumbnail
                Bitmap img = new Bitmap(file_struct.FilePath);
                fileVis.pBox_Icon.Image = DrawImageScaled(fileVis.pBox_Icon.Width, fileVis.pBox_Icon.Height, ref img);

                img.Dispose();
            }
            else
            {
                fileVis.pBox_Icon.Image = Icon.ExtractAssociatedIcon(file_struct.FilePath).ToBitmap();
            }

            // The Checkmark picture box needs to be added to the controls of the Icon pb. That's so that
            // the transparency works
            fileVis.panel_Parent.Controls.Add(fileVis.pBox_Icon);
            fileVis.pBox_Icon.Controls.Add(fileVis.pBox_Checkmark);


            fileVis.btn_Delete = new Button()
            {
                Size      = new Size(15, 20),
                Text      = "X",
                TextAlign = ContentAlignment.TopCenter,
                //Font = new Font("Serif", 12, FontStyle.Bold, GraphicsUnit.Pixel),
                Location = new Point(fileVis.pBox_Icon.Location.X + 15, fileVis.pBox_Icon.Location.Y - 22)
            };


            fileVis.label_FileName = new Label()
            {
                Name        = "label_FileName",
                AutoSize    = false,
                Size        = new Size(60, 15),
                MinimumSize = new Size(40, 10),
                MaximumSize = new Size(60, 200),
                TextAlign   = ContentAlignment.MiddleCenter,
                Text        = file_struct.FileName + file_struct.FileExtension,
                Location    = new Point(fileVis.pBox_Icon.Location.X, fileVis.pBox_Icon.Location.Y + 50)
            };

            string name = file_struct.FileName + file_struct.FileExtension;

            fileVis.label_FileName.Text = GUITools.ShortenFileName(name, 6);


            fileVis.panel_Parent.Controls.Add(fileVis.label_FileName);

            fileVis.panel_Parent.Controls.Add(fileVis.btn_Delete);
            fileVis.CurrentState = FileStatus.Inactive;

            PanelFlowLayout.Controls.Add(fileVis.panel_Parent);

            CurrentSelectedFiles.Add(fileVis);
        }
Пример #9
0
        //private void ProcessFileArrayThread(string[] paths)
        //{
        //    var t = new Thread(() => ProcessFileArray(paths));
        //    t.Start();

        //}

        private void ProcessFileArray(string[] paths)
        {
            if (mainForm.InvokeRequired)
            {
                mainForm.Invoke((MethodInvoker) delegate { ChangeGuiState(GUIState.FilesSelected); });
            }

            //mainForm.Invoke((MethodInvoker)delegate { panel_SendFiles.Visible = false; });


            //ChangeGuiState(GUIState.FilesSelected);

            CustomProgressBar progressBar = new CustomProgressBar()
            {
                Size     = new Size(FileAreaPanel.Width, 20),
                Location = new Point(0, 0),
            };

            progressBar.BackgroundBarColor = GUITools.COLOR_DarkMode_Light;
            progressBar.ProgressBarColor   = Color.Green;
            progressBar.Percentage         = 0;

            mainForm.Invoke((MethodInvoker) delegate { panel_ButtonsMain.Controls.Add(progressBar); panel_SendFiles.Visible = false; });


            for (int i = 0; i < paths.Length; i++)
            {
                decimal pp = (decimal)i / (decimal)paths.Length;

                progressBar.Percentage = (int)Math.Round(pp * 100);

                LocalFileStructure fStruct = new LocalFileStructure();
                fStruct.FileStatus = FileStatus.Inactive;
                FileInfo fInfo = new FileInfo(paths[i]);
                fStruct.FilePath      = paths[i];
                fStruct.FileExtension = Path.GetExtension(paths[i]);
                fStruct.FileName      = Path.GetFileNameWithoutExtension(paths[i]);
                fStruct.FileSize      = fInfo.Length;
                fStruct.FullName      = fInfo.Name;
                fStruct.FileID        = i;
                fStruct.FileSize      = fInfo.Length;
                AddNewQueuedFile(fStruct);
            }


            mainForm.Invoke((MethodInvoker) delegate { panel_SendFiles.Visible = true; progressBar.Visible = false; });

            //mainForm.Invoke((MethodInvoker)delegate { progressBar.Visible = false; });


            //foreach (string file in paths)
            //{
            //    LocalFileStructure fStruct = new LocalFileStructure();
            //    fStruct.FileStatus = FileStatus.Inactive;
            //    FileInfo fInfo = new FileInfo(file);
            //    fStruct.FilePath = file;
            //    fStruct.FileExtension = Path.GetExtension(file);
            //    fStruct.FileName = Path.GetFileNameWithoutExtension(file);
            //    fStruct.FileSize = fInfo.Length;
            //    fStruct.FullName = fInfo.Name;
            //    fStruct.FileID = id;
            //    fStruct.FileSize = fInfo.Length;
            //    AddNewQueuedFile(fStruct);
            //    id++;
            //}
        }
Пример #10
0
        public FileUploadVisual(int x, int y, int width, int height, LocalFileStructure fStruct)
        {
            // TEMP
            Size thumbSize = new Size(50, height - 15);

            panel_Background = new Panel()
            {
                BackColor = Color.Transparent,
                Size      = new Size(width, height),
                Location  = new Point(x, y)
            };

            //
            // bar_Progress
            //

            bar_Progress = new RoundedProgressBar()
            {
                Location = new Point(thumbSize.Width + 20, (int)((decimal)thumbSize.Height / 1.3M)),
                //Size = new Size((int)((decimal)width / 1.5M), 10),
                BorderStyle = BorderStyle.None,
                //BackColor = Color.White,
                BackgroundBarColor = Color.FromArgb(255, 220, 220, 220),
                ProgressBarColor   = Color.Green,
                Percentage         = 0
            };

            bar_Progress.Size       = new Size(width - bar_Progress.Location.X - 20, 10);
            bar_Progress.Percentage = 70;


            //bar_Progress = new ProgressBar()
            //{
            //    Location = new Point(thumbSize.Width + 20, (int)((decimal)thumbSize.Height / 1.3M)),
            //    //Size = new Size((int)((decimal)width / 1.5M), 10),
            //    BackColor = Color.White,

            //};
            //bar_Progress.Maximum = 100;
            //bar_Progress.Value = 50;
            //bar_Progress.Size = new Size(width - bar_Progress.Location.X - 20, 10);

            //
            // Thumbnail
            //

            if (imageExtensions.Contains(fStruct.FileExtension.ToLower()))
            {
                // Create the thumbnail
                Bitmap img = new Bitmap(fStruct.FilePath);
                FileThumbnail = ImageEditing.DrawImageScaled(thumbSize.Width, thumbSize.Height, img);

                img.Dispose();
            }
            else
            {
                FileThumbnail = Icon.ExtractAssociatedIcon(fStruct.FilePath).ToBitmap();
            }

            pBox_Thumbnail = new PictureBox()
            {
                Size     = thumbSize,
                Location = new Point(5, 7),
                Image    = ImageEditing.AddThumbnailShadow((Bitmap)FileThumbnail, Properties.Resources.shadow_base_full),
                SizeMode = PictureBoxSizeMode.Zoom
            };

            //
            // btn_CheckCross
            //

            btn_CheckCross = new Button()
            {
                BackgroundImage       = Properties.Resources.TransferResult_CrossThick,
                BackgroundImageLayout = ImageLayout.Zoom,
                Size      = new Size(25, 25),
                BackColor = Color.Transparent,
                FlatStyle = FlatStyle.Flat,
            };



            //
            // label_FileName
            //

            label_FileName = new Label()
            {
                Font      = new Font("Bahnschrift", 12),
                Location  = new Point(bar_Progress.Location.X - 3, bar_Progress.Location.Y - 25),
                ForeColor = Color.FromArgb(200, 80, 80, 80),
                Size      = new Size(bar_Progress.Width - btn_CheckCross.Width - 10, 50)
            };

            // Automatically adjust the text lenght in relation to the label width. Dynamic
            label_FileName.Text = GUITools.FitTextLenghtToLabelSize(fStruct.FullName, label_FileName);

            //Console.WriteLine($"Width of: {label_FileName.Text}: {size.Width}");


            btn_CheckCross.Location = new Point(bar_Progress.Location.X + bar_Progress.Size.Width - btn_CheckCross.Size.Width,
                                                label_FileName.Location.Y - 5);

            btn_CheckCross.FlatAppearance.BorderSize = 0;
        }