private void OnStatusTimer(Object source, EventArgs e) { if (m_liReceivingFiles.Count == 1) { ReceiveFile file = m_liReceivingFiles[0]; int nComplete = (int)((file.DataReceived * 100) / file.FileSize); Log.s(TAG, "Receiving file " + file.FileName + " - " + nComplete + "% (" + file.GetTransferSpeedString() + ")"); } else if (m_liReceivingFiles.Count > 1) { ulong lDataReceived = 0; ulong lFilesizes = 0; foreach (ReceiveFile file in m_liReceivingFiles) { lDataReceived += file.DataReceived; lFilesizes += file.FileSize; } int nComplete = (int)((lDataReceived * 100) / lFilesizes); Log.s(TAG, "Receiving file " + m_liReceivingFiles.Count + " files - " + nComplete + "%"); } else { m_statusTimer.IsEnabled = false; } }
public void OpenFinished(bool bFolderOnly) { if (Selected >= 0 && FinishedFiles.Count > Selected) { ReceiveFile file = FinishedFiles[Selected]; Process process = new Process(); process.StartInfo.FileName = bFolderOnly ? file.BasePath : file.FinalFilePath; process.StartInfo.UseShellExecute = true; try { process.Start(); } catch (Exception e) { Log.w(TAG, "Failed to open file " + file.FileName + " - " + e.Message); } } }
public async void OnReceivedFileEvent(object sender, ReceiveFileEventArgs eventArgs) { if (eventArgs.FileEvent == ReceiveFileEventArgs.EFileEvent.NEWFILE) { ReceiveFile newFile = new ReceiveFile(eventArgs.FileName, eventArgs.FileType, eventArgs.FileID, eventArgs.FileSize); if (newFile.Open()) { eventArgs.CancelFile = false; m_liReceivingFiles.Add(newFile); m_statusTimer.IsEnabled = true; Log.i(TAG, "Receiving " + newFile.FileName + " (" + newFile.FileSize.ToXByteSize() + ")", true); } else { eventArgs.CancelFile = true; } } else if (eventArgs.FileEvent == ReceiveFileEventArgs.EFileEvent.CANCELFILE) { ReceiveFile file = m_liReceivingFiles.Find(x => x.FileID == eventArgs.FileID); if (file != null) { Log.i(TAG, "Aborted file " + file.FileName, true); file.Cancel(); m_liReceivingFiles.Remove(file); } else { Log.w(TAG, "Server requested cancelling of unknown file, Id:" + eventArgs.FileID); } } else if (eventArgs.FileEvent == ReceiveFileEventArgs.EFileEvent.DATA) { ReceiveFile file = m_liReceivingFiles.Find(x => x.FileID == eventArgs.FileID); if (file != null) { try { await file.Write(eventArgs.Data, eventArgs.FilePos); } catch (Exception e) { Log.e(TAG, "Error while writing received file data for file " + file.FileName + " - " + e.Message); eventArgs.CancelFile = true; file.Cancel(); m_liReceivingFiles.Remove(file); return; } if (file.Complete) { Log.i(TAG, "Completed file " + file.FileName, true); FinishedFiles.Add(file); m_liReceivingFiles.Remove(file); Selected = FinishedFiles.Count - 1; if (FinishedFiles.Count == 1) { ShowNotification = true; } } } } }