public FileDirInfo(SdCardFile File, SdCardDirectoryFileInfo Info, UInt32 CRC, Image Ico) { InitializeComponent(); pictureBox_ico.Image = Ico; label_name.Text = File.FileName; var fileType = MainForm.SystemFileName(File.FilePath, false, ""); label_type.Text = $"Тип: файл {(fileType != InfoType.Unknown ? "(системный " + fileType.ToString() + ')' : "")}"; label_size.Text = $"Размер: {MainForm.ProccedSize(Info.FileDirectorySize)}"; label_path.Text = $"Путь к файлу: {File.FilePath}"; label_created.Text = $"Создан: {Info.CreationTime.ToString("g")}"; label_hash.Text = $"CRC32: {CRC.ToString()}"; label_isHidden.Text = $"IsHidden: {Info.IsHidden}"; label_isLfn.Text = $"IsLFN: {Info.IsLFN}"; label_isRO.Text = $"IsReadOnly: {Info.IsReadOnly}"; label_isSystem.Text = $"IsSystem: {Info.IsSystem}"; }
public bool ReceiveFileSync(string pcName, string DeviceName) { //if (ParentMaster.isClosed) //TODO: –азобратьс¤ с мастерами //throw .CloseEx; DTPMaster.CheckConnAndVal(); TimerThread = new Thread(TimerThreadMethod); TimerThread.Start(); DateTime startTime = DateTime.Now; MainFile = new SdCardFile(DeviceName, Master); //TODO: сделать мастер/ MainFile! try { if (!MainFile.IsExists) { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.FileNotExists, true)); return(false); } } catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantOpenFile, true)); return(false); } try { MainFile.Open(false); } catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantOpenFile, true)); return(false); } var bf = MainFile.BinnaryFile; bf.CursorPos = 0; UInt32 len = 0; try { len = MainFile.Length; } catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetFileSize, true)); return(false); } byte[] buffer = new byte[len]; UInt32 currentPacket = 0; UInt32 totalPackets = (UInt32)(len / PacketLength); UInt32 currIndex = 0, delta = 0, index = 0; while (currIndex < len) { if (currIndex + PacketLength > len) { delta = len - currIndex; currIndex = len; } else { currIndex += (UInt32)PacketLength; delta = (UInt32)PacketLength; } SdCardBinnaryFileReadResult <byte[]> res; try { res = bf.ReadByteArray(delta); } catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetPacket, true)); return(false); } if (!res.Succeed) { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetPacket, true)); return(false); } else { if (ForceStop) { try { MainFile.Close(); } catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantCloseFile, true)); } RaiseEndEvent(new FileTransferEndArgs((DateTime.Now - startTime).TotalSeconds, true)); return(false); } currentPacket++; RaiseProcessEvent(new FileTransferProcessArgs((long)(DateTime.Now - startTime).TotalSeconds, LeftTime, totalPackets - currentPacket, currentPacket, Speed, PacketLength)); Buffer.BlockCopy(res.Result, 0, buffer, (int)index, (int)delta); index += delta; } } File.Create(pcName).Close(); File.WriteAllBytes(pcName, buffer); if (CheckLen) { if (len != new FileInfo(pcName).Length) { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.NotEqualSizes, false)); } } if (CheckSum) { UInt32 localHash = CrCHandler.CRC32(pcName); UInt32 deviceHash = 0; try { deviceHash = MainFile.CRC32; } catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetHashOfFile, true)); return(false); } if (localHash != deviceHash) { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.HashesNotEqual, false)); } } try { MainFile.Close(); } catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantCloseFile, true)); return(false); } RaiseEndEvent(new FileTransferEndArgs((DateTime.Now - startTime).TotalSeconds, false)); return(true); }