private AddFile getFile(Label infa) { string[] data = infa.Text.Split(new string[] { "\n" }, StringSplitOptions.None); if (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(null); } if (data[2].IndexOf(name) != -1) { newName = data[2]; } else { return(null); } User creator = null; foreach (object i in infa.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)infa.Parent); return(file); } } return(null); }
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 } } } } }