Example #1
0
 public static void HandleDownloadFile(Packets.ServerPackets.DownloadFile command, Client client)
 {
     try
     {
         byte[] bytes = File.ReadAllBytes(command.RemotePath);
         new Packets.ClientPackets.DownloadFileResponse(Path.GetFileName(command.RemotePath), bytes, command.ID).Execute(client);
     }
     catch
     { }
 }
Example #2
0
        public static void HandleDownloadFile(Packets.ServerPackets.DownloadFile command, Client client)
        {
            new Thread(() =>
            {
                try
                {
                    FileSplit srcFile = new FileSplit(command.RemotePath);
                    if (srcFile.MaxBlocks < 0)
                    {
                        new Packets.ClientPackets.DownloadFileResponse(command.ID, "", new byte[0], -1, -1,
                                                                       srcFile.LastError).Execute(client);
                    }

                    for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                    {
                        if (!client.Connected)
                        {
                            return;
                        }
                        if (_canceledDownloads.ContainsKey(command.ID))
                        {
                            return;
                        }

                        byte[] block;
                        if (srcFile.ReadBlock(currentBlock, out block))
                        {
                            new Packets.ClientPackets.DownloadFileResponse(command.ID,
                                                                           Path.GetFileName(command.RemotePath), block, srcFile.MaxBlocks, currentBlock,
                                                                           srcFile.LastError).Execute(client);
                            //Thread.Sleep(200);
                        }
                        else
                        {
                            new Packets.ClientPackets.DownloadFileResponse(command.ID, "", new byte[0], -1, -1,
                                                                           srcFile.LastError).Execute(client);
                        }
                    }
                }
                catch (Exception ex)
                {
                    new Packets.ClientPackets.DownloadFileResponse(command.ID, "", new byte[0], -1, -1, ex.Message)
                    .Execute(client);
                }
            }).Start();
        }