public override bool Equals(object obj) { HashPack pack = obj as HashPack; if (obj == null) { return(false); } return(string.Compare(Path, pack.Path, true) == 0); }
public void MarkforHash(LocalFile file, string path, uint project, string dir) { HashPack pack = new HashPack(file, path, project, dir); lock (HashFiles.Pending) if (HashFiles.Pending.Any(p => ((HashPack)p.Param2).File == file)) { return; } file.Info.Size = new FileInfo(path).Length; // set so we can get hash status HashFiles.Enqueue(() => HashFile(pack), pack); }
private void QuarterSecondTimer_Tick(object sender, EventArgs e) { if (Storages.HashFiles.Pending.Count == 0) { Close(); } // Securing test.mpg, 2 files left, 200 MB total HashPack pack = null; long totalSize = 0; lock (Storages.HashFiles.Pending) { pack = Storages.HashFiles.Pending.First.Value.Param2 as HashPack; foreach (HashPack packy in Storages.HashFiles.Pending.Select(p => p.Param2 as HashPack)) { totalSize += packy.File.Info.Size; } } if (pack == null) { return; } string status = "Securing '" + pack.File.Info.Name + "'\r\n"; int filesLeft = Storages.HashFiles.Pending.Count - 1; if (filesLeft > 0) { if (filesLeft == 1) { status += "1 File Left\r\n"; } else { status += filesLeft.ToString() + " Files Left\r\n"; } } status += Utilities.ByteSizetoString(totalSize) + " Total"; StatusLabel.Text = status; }
private void ReviseFile(HashPack pack, StorageFile info) { // called from hash thread if (Core.InvokeRequired) { Core.RunInCoreAsync(() => ReviseFile(pack, info)); return; } if (Working.ContainsKey(pack.Project)) { Working[pack.Project].ReadyChange(pack.File, info); } CallFileUpdate(pack.Project, pack.Dir, info.UID, WorkingChange.Updated); }
void HashFile(HashPack pack) { // three steps, hash file, encrypt file, hash encrypted file try { OpFile file = null; StorageFile info = pack.File.Info.Clone(); // remove old references from local file OpFile commonFile = null; if (FileMap.SafeTryGetValue(pack.File.Info.HashID, out commonFile)) { commonFile.DeRef(); //crit test } if (!File.Exists(pack.Path)) { return; } // do public hash Utilities.ShaHashFile(pack.Path, ref info.InternalHash, ref info.InternalSize); info.InternalHashID = BitConverter.ToUInt64(info.InternalHash, 0); // if file exists in public map, use key for that file OpFile internalFile = null; InternalFileMap.SafeTryGetValue(info.InternalHashID, out internalFile); if (internalFile != null) { file = internalFile; file.References++; // if file already encrypted in our system, continue if (File.Exists(GetFilePath(info.HashID))) { info.Size = file.Size; info.FileKey = file.Key; info.Hash = file.Hash; info.HashID = file.HashID; if (!Utilities.MemCompare(file.Hash, pack.File.Info.Hash)) { ReviseFile(pack, info); } return; } } // file key is opID and public hash xor'd so that files won't be duplicated on the network // apply special compartment key here as well, xor again RijndaelManaged crypt = Utilities.CommonFileKey(Core.User.Settings.OpKey, info.InternalHash); info.FileKey = crypt.Key; // encrypt file to temp dir string tempPath = Core.GetTempPath(); Utilities.EncryptTagFile(pack.Path, tempPath, crypt, Core.Network.Protocol, ref info.Hash, ref info.Size); info.HashID = BitConverter.ToUInt64(info.Hash, 0); // move to official path string path = GetFilePath(info.HashID); if (!File.Exists(path)) { File.Move(tempPath, path); } // if we dont have record of file make one if (file == null) { file = new OpFile(info); file.References++; FileMap.SafeAdd(info.HashID, file); InternalFileMap.SafeAdd(info.InternalHashID, file); } // else, record already made, just needed to put the actual file in the system else { Debug.Assert(info.HashID == file.HashID); } // if hash is different than previous mark as modified if (!Utilities.MemCompare(file.Hash, pack.File.Info.Hash)) { ReviseFile(pack, info); } } catch (Exception ex) { /*rotate file to back of queue * lock (HashQueue) * if (HashQueue.Count > 1) * HashQueue.Enqueue(HashQueue.Dequeue());*/ Core.Network.UpdateLog("Storage", "Hash thread: " + ex.Message); } }
public void MarkforHash(LocalFile file, string path, uint project, string dir) { HashPack pack = new HashPack(file, path, project, dir); lock (HashFiles.Pending) if (HashFiles.Pending.Any(p => ((HashPack)p.Param2).File == file)) return; file.Info.Size = new FileInfo(path).Length; // set so we can get hash status HashFiles.Enqueue(() => HashFile(pack), pack); }
private void ReviseFile(HashPack pack, StorageFile info) { // called from hash thread if (Core.InvokeRequired) { Core.RunInCoreAsync(() => ReviseFile(pack, info)); return; } if (Working.ContainsKey(pack.Project)) Working[pack.Project].ReadyChange(pack.File, info); CallFileUpdate(pack.Project, pack.Dir, info.UID, WorkingChange.Updated); }
void HashFile(HashPack pack) { // three steps, hash file, encrypt file, hash encrypted file try { OpFile file = null; StorageFile info = pack.File.Info.Clone(); // remove old references from local file OpFile commonFile = null; if (FileMap.SafeTryGetValue(pack.File.Info.HashID, out commonFile)) commonFile.DeRef(); //crit test if (!File.Exists(pack.Path)) return; // do public hash Utilities.ShaHashFile(pack.Path, ref info.InternalHash, ref info.InternalSize); info.InternalHashID = BitConverter.ToUInt64(info.InternalHash, 0); // if file exists in public map, use key for that file OpFile internalFile = null; InternalFileMap.SafeTryGetValue(info.InternalHashID, out internalFile); if (internalFile != null) { file = internalFile; file.References++; // if file already encrypted in our system, continue if (File.Exists(GetFilePath(info.HashID))) { info.Size = file.Size; info.FileKey = file.Key; info.Hash = file.Hash; info.HashID = file.HashID; if (!Utilities.MemCompare(file.Hash, pack.File.Info.Hash)) ReviseFile(pack, info); return; } } // file key is opID and public hash xor'd so that files won't be duplicated on the network // apply special compartment key here as well, xor again RijndaelManaged crypt = Utilities.CommonFileKey(Core.User.Settings.OpKey, info.InternalHash); info.FileKey = crypt.Key; // encrypt file to temp dir string tempPath = Core.GetTempPath(); Utilities.EncryptTagFile(pack.Path, tempPath, crypt, Core.Network.Protocol, ref info.Hash, ref info.Size); info.HashID = BitConverter.ToUInt64(info.Hash, 0); // move to official path string path = GetFilePath(info.HashID); if (!File.Exists(path)) File.Move(tempPath, path); // if we dont have record of file make one if (file == null) { file = new OpFile(info); file.References++; FileMap.SafeAdd(info.HashID, file); InternalFileMap.SafeAdd(info.InternalHashID, file); } // else, record already made, just needed to put the actual file in the system else { Debug.Assert(info.HashID == file.HashID); } // if hash is different than previous mark as modified if (!Utilities.MemCompare(file.Hash, pack.File.Info.Hash)) ReviseFile(pack, info); } catch (Exception ex) { /*rotate file to back of queue lock (HashQueue) if (HashQueue.Count > 1) HashQueue.Enqueue(HashQueue.Dequeue());*/ Core.Network.UpdateLog("Storage", "Hash thread: " + ex.Message); } }