Exemple #1
0
        private void updateDownloadInfo(object downFile)
        {
            if (downFile.GetType() == typeof(AddFile))
            {
                AddFile file = (AddFile)downFile;
                if (file.getPanel() == null)
                {
                    return;
                }

                ulong downBlock = 1, size = file.getCountBlock();
                for (ulong i = 0; i < size; i++)
                {
                    if (file.flagBlock[i] != 0)
                    {
                        downBlock++;
                    }
                }

                View.updateFileMessage(file.getPanel(), (100.0 / size) * downBlock);
            }
        }
Exemple #2
0
 private void errorDonwload(object file)
 {
     if (file.GetType() == typeof(AddFile))
     {
         var File = (AddFile)file;
         if (File.getCreator() != null && File.getCreator().message != null)
         {
             foreach (var i in File.getCreator().message.Controls)
             {
                 if (i.GetType() == typeof(Panel))
                 {
                     AddFile addFile = this.getFile(View.getInfa((Panel)i));
                     if (addFile == null)
                     {
                         continue;
                     }
                     if (addFile.getCreator().Equals(File.getCreator()) && addFile.getName() == File.getName() && addFile.getNewName() == File.getNewName())
                     {
                         View.updateFileMessage(addFile.getPanel(), File.getError());
                         return;
                     }
                 }
             }
         }
         if (File.getCreator() != null)
         {
             foreach (var i in this.panel1.Controls)
             {
                 if (i.GetType() == typeof(Panel))
                 {
                     AddFile addFile = this.getFile(View.getInfa((Panel)i));
                     if (addFile == null)
                     {
                         continue;
                     }
                     if (addFile.getCreator().Equals(File.getCreator()) && addFile.getName() == File.getName() && addFile.getNewName() == File.getNewName())
                     {
                         View.updateFileMessage(addFile.getPanel(), File.getError());
                         return;
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
        private void downloadClick(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(Label))
            {
                string[] data = ((Label)sender).Text.Split(new string[] { "\n" }, StringSplitOptions.None);
                if (data.Length >= 2 && data.Length <= 3)
                {
                    string name = data[0], newName;
                    ulong  size;
                    try
                    {
                        string sizeS = "";
                        for (int i = 0; i < data[1].Length; i++)
                        {
                            if (data[1][i] >= '0' && data[1][i] <= '9')
                            {
                                sizeS += data[1][i];
                            }
                            else if (sizeS != "")
                            {
                                break;
                            }
                        }
                        size = Convert.ToUInt64(sizeS);
                    }
                    catch
                    {
                        return;
                    }
                    if (data.Length == 3)
                    {
                        newName = data[2];
                    }
                    else
                    {
                        newName = name;
                    }

                    User creator = null;
                    foreach (object i in ((Label)sender).Parent.Controls)
                    {
                        if (i.GetType() == typeof(Label))
                        {
                            creator = this.getUser(((Label)i).Text);
                            if (creator != null)
                            {
                                break;
                            }
                        }
                    }

                    if (creator != null)
                    {
                        var file = new AddFile(creator, name, size, Storage.getBlockSize(), newName);
                        file.setPanel((Panel)((Label)sender).Parent);

                        if (!creator.Equals(Server.me) && Server.isDownloadable(creator.client, file))
                        {
                            return;
                        }
                        else if (Storage.isHave(file))
                        {
                            try
                            {
                                Storage.open(file);
                            }
                            catch
                            {
                                if (!creator.Equals(Server.me))
                                {
                                    View.updateFileMessage(file.getPanel());
                                    Server.startDownload(creator.client, file);
                                }
                            }
                        }
                        else if (!creator.Equals(Server.me))
                        {
                            View.updateFileMessage(file.getPanel());
                            Server.startDownload(creator.client, file);
                        }
                        else
                        {
                            View.updateFileMessage(file.getPanel(), "Error Download! Это ваш файл и Вы удалили его");//eror on panel
                        }
                    }
                }
            }
        }