Esempio n. 1
0
        void Session_Data(RudpSession session, byte[] data)
        {
            G2Header root = new G2Header(data);

            if (G2Protocol.ReadPacket(root))
            {
                switch (root.Name)
                {
                case SharePacket.PublicRequest:
                    ReceivePublicRequest(session);
                    break;

                case SharePacket.Collection:
                    ReceivePublicDetails(session, ShareCollection.Decode(root, session.UserID));
                    break;
                }
            }
        }
Esempio n. 2
0
        private void LoadHeaders()
        {
            List <string> goodPaths = new List <string>();

            // load shared file lists

            try
            {
                goodPaths.Add(HeaderPath);

                if (!File.Exists(HeaderPath))
                {
                    return;
                }

                using (IVCryptoStream crypto = IVCryptoStream.Load(HeaderPath, Core.User.Settings.FileKey))
                {
                    PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read);

                    G2Header root = null;


                    while (stream.ReadPacket(ref root))
                    {
                        if (root.Name == SharePacket.Collection)
                        {
                            ShareCollection copy = ShareCollection.Decode(root, Core.UserID);
                            //crit - ensure public path exists before loading up
                            Local.Hash = copy.Hash;
                            Local.Size = copy.Size;
                            Local.Key  = copy.Key;
                        }
                        else if (root.Name == SharePacket.File)
                        {
                            SharedFile file = SharedFile.Decode(root, Core.Network.Local.ClientID);

                            if (file.SystemPath != null && !File.Exists(GetFilePath(file)))
                            {
                                file.SystemPath = null;
                            }

                            file.FileID = OpTransfer.GetFileID(ServiceID, file.Hash, file.Size);

                            if (File.Exists(GetFilePath(file)))
                            {
                                file.Completed = true;
                                file.Sources.Add(Core.Network.Local);
                            }

                            // incomplete, ensure partial file is saved into next run if need be
                            else
                            {
                                foreach (OpTransfer partial in Core.Transfers.Partials.Where(p => p.FileID == file.FileID))
                                {
                                    partial.SavePartial = true;
                                }
                            }

                            file.FileStatus = file.Completed ? "Secured" : "Incomplete";

                            Local.Files.SafeAdd(file);

                            // unhashed files aren't saved anymore

                            /* if app previous closed without hashing share, hash now
                             * if (share.Hash == null && share.SystemPath != null &&
                             *  File.Exists(share.SystemPath))
                             *  ProcessFileShare(share);*/
                        }
                    }
                }

                // clears most of files in direcotry, others shared public lists are not persisted between runs
                foreach (string testPath in Directory.GetFiles(SharePath))
                {
                    if (!goodPaths.Contains(testPath))
                    {
                        try { File.Delete(testPath); }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                Network.UpdateLog("VersionedFile", "Error loading data " + ex.Message);
            }
        }