コード例 #1
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public string GetFileLink(ulong user, SharedFile file)
        {
            byte[] sources = null;


            // if local shared file, get the sources we know of
            if (user == Core.UserID && file.ClientID == Core.Network.Local.ClientID)
            {
                foreach (DhtClient client in file.Sources)
                {
                    sources = (sources == null) ? client.ToBytes() : Utilities.CombineArrays(sources, client.ToBytes());
                }
            }

            // else getting link from remote share, so add it's address as a location
            else
            {
                sources = new DhtClient(user, file.ClientID).ToBytes();
            }


            FileLink link = new FileLink()
            {
                OpName     = Core.User.Settings.Operation,
                FileName   = file.Name,
                PublicOpID = Core.User.Settings.PublicOpID,
                Size       = file.Size,
                Hash       = file.Hash,
                Key        = file.FileKey,
                Sources    = sources
            };

            return(link.Encode(Core));
        }
コード例 #2
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public void SendFile(string path, Tuple <FileProcessedHandler, object> processed)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(() => SendFile(path, processed));
                return;
            }

            // add to share list
            SharedFile file = new SharedFile(Core.Network.Local.ClientID);

            file.Name       = Path.GetFileName(path);
            file.SystemPath = path;

            file.Completed = true;
            file.Sources.Add(Core.Network.Local);
            file.FileStatus = "Processing...";
            file.Processed  = processed;

            // so user can see hash progress
            Local.Files.SafeAdd(file);
            Core.RunInGuiThread(GuiFileUpdate, file);

            ProcessFiles.Enqueue(() => ProcessFile(file));
        }
コード例 #3
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public void DownloadLink(string text)
        {
            FileLink link = FileLink.Decode(text, Core);

            SharedFile file = new SharedFile(Core.Network.Local.ClientID);

            file.Name = link.FileName;

            if (!Utilities.MemCompare(link.PublicOpID, Core.User.Settings.PublicOpID))
            {
                throw new Exception("File Link is not for this Op");
            }

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

            if (link.Sources != null)
            {
                for (int i = 0; i < link.Sources.Length; i += 10)
                {
                    file.Sources.Add(DhtClient.FromBytes(link.Sources, i));
                }
            }

            DownloadFile(file);
        }
コード例 #4
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        void OpenFile(SharedFile file)
        {
            if (!Directory.Exists(DownloadPath))
            {
                Directory.CreateDirectory(DownloadPath);
            }

            string finalpath = DownloadPath + file.Name;

            int i = 1;

            while (File.Exists(finalpath))
            {
                finalpath = DownloadPath + "(" + (i++) + ") " + file.Name;
            }


            // decrypt file to temp dir
            file.FileStatus = "Unsecuring...";
            Utilities.DecryptTagFile(GetFilePath(file), finalpath, file.FileKey, Core);

            file.SystemPath = finalpath;
            file.FileStatus = "File in Downloads Folder";

            Process.Start(finalpath);

            RunSave = true;
        }
コード例 #5
0
ファイル: SharingView.cs プロジェクト: nandub/DeOps
        private void SecondTimer_Tick(object sender, EventArgs e)
        {
            // sync items with local status, we can see our transfer in remote's view
            Sharing.Local.Files.LockReading(() =>
            {
                foreach (SharedFile file in SharedFiles.Items.Cast <ShareItem>().Select(i => i.Share))
                {
                    SharedFile localStatus = Sharing.Local.Files.Where(f => f.FileID == file.FileID).FirstOrDefault();

                    if (localStatus == null)
                    {
                        continue;
                    }

                    file.FileStatus     = localStatus.FileStatus;
                    file.TransferStatus = localStatus.TransferStatus;
                    file.TransferActive = localStatus.TransferActive;
                }
            });

            foreach (ShareItem item in SharedFiles.Items)
            {
                item.RefreshStatus();
            }

            ShareCollection collection;

            if (Sharing.Collections.SafeTryGetValue(UserID, out collection))
            {
                StatusLabel.Text = collection.Status;
            }

            SharedFiles.Invalidate(); // update download progress, file colors, etc..
        }
コード例 #6
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public string GetFilePath(SharedFile file)
        {
            if (file.Hash == null)
            {
                return("");
            }

            return(SharePath + Utilities.CryptFilename(Core, Core.UserID, file.Hash));
        }
コード例 #7
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
 public SharedFile(SharedFile copy, ushort client)
 {
     ClientID = client;
     Name     = copy.Name;
     Hash     = copy.Hash;
     Size     = copy.Size;
     FileKey  = copy.FileKey;
     FileID   = OpTransfer.GetFileID((uint)ServiceIDs.Share, Hash, Size);
 }
コード例 #8
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public void CollectionDownloadFinished(object[] args)
        {
            ShareCollection collection = args[0] as ShareCollection;
            ushort          client     = (ushort)args[1];

            collection.Files.LockWriting(() =>
            {
                foreach (SharedFile file in collection.Files.Where(c => c.ClientID == client).ToArray())
                {
                    collection.Files.Remove(file);
                }
            });

            try
            {
                string finalpath = GetPublicPath(collection);

                using (TaggedStream tagged = new TaggedStream(finalpath, Network.Protocol))
                    using (IVCryptoStream crypto = IVCryptoStream.Load(tagged, collection.Key))
                    {
                        PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read);

                        G2Header root = null;

                        collection.Files.LockWriting(() =>
                        {
                            while (stream.ReadPacket(ref root))
                            {
                                if (root.Name == SharePacket.File)
                                {
                                    SharedFile file = SharedFile.Decode(root, client);

                                    // dont add dupes from diff client ids
                                    if (collection.Files.Any(f => f.Size == file.Size && Utilities.MemCompare(f.Hash, file.Hash)))
                                    {
                                        continue;
                                    }

                                    file.FileID = OpTransfer.GetFileID(ServiceID, file.Hash, file.Size);
                                    collection.Files.SafeAdd(file);
                                }
                            }
                        });
                    }
            }
            catch (Exception ex)
            {
                Core.Network.UpdateLog("Mail", "Error loading local mail " + ex.Message);
            }

            collection.Status = collection.Files.SafeCount + " Files Shared";

            Core.RunInGuiThread(GuiCollectionUpdate, collection.UserID);
        }
コード例 #9
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public void FileDownloadFinished(object[] args)
        {
            SharedFile file = args[0] as SharedFile;

            file.Completed = true;
            file.Sources.Add(Core.Network.Local);

            file.FileStatus = "Download Finished";

            Core.RunInGuiThread(GuiFileUpdate, file);

            Core.MakeNews(ServiceIDs.Share, file.Name + " Finished Downloading", Core.UserID, 0, false);
        }
コード例 #10
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        private OpTransfer StartTransfer(DhtClient client, SharedFile file)
        {
            FileDetails details = new FileDetails(ServiceID, DataTypeShare, file.Hash, file.Size, null);

            object[] args = new object[] { file };

            OpTransfer transfer = Core.Transfers.StartDownload(client.UserID, details, GetFilePath(file), new EndDownloadHandler(FileDownloadFinished), args);

            transfer.AddPeer(client);

            file.TransferStatus = "Starting download from " + Core.GetName(client.UserID);

            return(transfer);
        }
コード例 #11
0
ファイル: SharingView.cs プロジェクト: nandub/DeOps
        public ShareItem(SharingView theView, SharedFile share)
        {
            Share   = share;
            TheView = theView;
            Local   = theView.Local && share.ClientID == theView.Core.Network.Local.ClientID;

            ImageIndex = theView.GetImageIndex(share);

            SubItems.Add("");
            SubItems.Add("");
            SubItems.Add("");

            RefreshStatus();
        }
コード例 #12
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        void DownloadFile(SharedFile file)
        {
            SharedFile existing = null;

            Local.Files.LockReading(() =>
                                    existing = Local.Files.Where(s => Utilities.MemCompare(s.Hash, file.Hash)).FirstOrDefault());

            // just add new targets if we already have this file
            if (existing != null)
            {
                if (existing.Completed)
                {
                    return;
                }

                existing.Sources = existing.Sources.Union(file.Sources).ToList();
                file             = existing;
            }
            else
            {
                Local.Files.SafeAdd(file);
            }


            // if downloading form another client of self
            if (file.ClientID != Core.Network.Local.ClientID)
            {
                file.ClientID = Core.Network.Local.ClientID;
                Core.RunInGuiThread(GuiCollectionUpdate, Core.UserID);
            }

            Core.RunInCoreAsync(() =>
            {
                if (file.Sources.Count > 0)
                {
                    OpTransfer transfer = StartTransfer(file.Sources[0], file);

                    file.Sources.ForEach(s => transfer.AddPeer(s));
                }

                TempLocation.Search(file.FileID, file, Search_FoundLocation);
            });

            RunSave = true;

            file.FileStatus = "Incomplete";

            Core.RunInGuiThread(GuiFileUpdate, file);
        }
コード例 #13
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public void OpenFile(ulong user, SharedFile file)
        {
            if (!File.Exists(GetFilePath(file)))
            {
                return;
            }

            // check if already exists, if it does open
            if (file.SystemPath != null && File.Exists(file.SystemPath))
            {
                Process.Start(file.SystemPath);
                return;
            }

            OpenFiles.Enqueue(() => OpenFile(file));
        }
コード例 #14
0
ファイル: AcceptFileForm.cs プロジェクト: RoelofSol/DeOps
        public AcceptFileForm(OpCore core, DhtClient client, SharedFile share)
        {
            InitializeComponent();

            Core = core;
            Sharing = core.GetService(ServiceIDs.Share) as ShareService;

            TheFile = share;
            Source = client;

            DescriptionLabel.Text = core.GetName(client.UserID) + " wants to send you a file";

            NameLabel.Text = TheFile.Name;

            SizeLabel.Text = Utilities.ByteSizetoDecString(TheFile.Size);
        }
コード例 #15
0
ファイル: AcceptFileForm.cs プロジェクト: nandub/DeOps
        public AcceptFileForm(OpCore core, DhtClient client, SharedFile share)
        {
            InitializeComponent();

            Core    = core;
            Sharing = core.GetService(ServiceIDs.Share) as ShareService;

            TheFile = share;
            Source  = client;

            DescriptionLabel.Text = core.GetName(client.UserID) + " wants to send you a file";

            NameLabel.Text = TheFile.Name;

            SizeLabel.Text = Utilities.ByteSizetoDecString(TheFile.Size);
        }
コード例 #16
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public void DownloadFile(ulong user, SharedFile file)
        {
            // donwloading from a different user, make a copy of their share, and activate download
            // copies are checked for

            if (File.Exists(GetFilePath(file)))
            {
                return;
            }

            SharedFile localCopy = new SharedFile(file, Core.Network.Local.ClientID);

            localCopy.Sources.Add(new DhtClient(user, file.ClientID));

            DownloadFile(localCopy);
        }
コード例 #17
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            if (BrowseLink.Enabled)
            {
                if (File.Exists(BrowseLink.Text))
                {
                    Sharing.SendFile(BrowseLink.Text, FileProcessed);
                }

                else
                {
                    MessageBox.Show("No File Selected");
                    return;
                }
            }

            else if (RecentRadio.Checked)
            {
                SharedFile file = RecentCombo.SelectedItem as SharedFile;

                if (file != null)
                {
                    if (FileProcessed != null)
                    {
                        Core.RunInCoreAsync(() => FileProcessed.Param1.Invoke(file, FileProcessed.Param2));
                    }
                }
                else
                {
                    MessageBox.Show("No File Selected");
                    return;
                }
            }

            // show if processing otherwise, request immediately sent
            if (BrowseLink.Enabled)
            {
                if (!UI.GuiMain.ShowExistingView(typeof(SharingView)))
                {
                    UI.ShowView(new SharingView(Core, Core.UserID), true);
                }
            }


            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #18
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        void ProcessFile(SharedFile file)
        {
            try
            {
                // copied from storage service

                // hash file fast - used to gen key/iv
                file.FileStatus = "Identifying...";
                byte[] internalHash = null;
                long   internalSize = 0;
                Utilities.Md5HashFile(file.SystemPath, ref internalHash, ref internalSize);

                // dont bother find dupe, becaues dupe might be incomplete, in which case we want to add
                // completed file to our shared, have timer find dupes, and if both have the same file path that exists, remove one

                RijndaelManaged crypt = Utilities.CommonFileKey(Core.User.Settings.OpKey, internalHash);
                file.FileKey = crypt.Key;

                // encrypt file to temp dir
                file.FileStatus = "Securing...";
                string tempPath = Core.GetTempPath();
                Utilities.EncryptTagFile(file.SystemPath, tempPath, crypt, Network.Protocol, ref file.Hash, ref file.Size);
                file.FileID = OpTransfer.GetFileID(ServiceID, file.Hash, file.Size);

                // move to official path
                string path = GetFilePath(file);
                if (!File.Exists(path))
                {
                    File.Move(tempPath, path);
                }

                file.FileStatus = "Secured";

                // run in core thread -> save, send request to user
                if (file.Processed != null)
                {
                    Core.RunInCoreAsync(() => file.Processed.Param1.Invoke(file, file.Processed.Param2));
                }

                RunSave = true;
            }
            catch (Exception ex)
            {
                file.FileStatus = "Error: " + ex.Message;
            }
        }
コード例 #19
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        string Transfers_FileRequest(ulong key, FileDetails details)
        {
            SharedFile share = null;

            Local.Files.LockReading(() =>
            {
                share = Local.Files.Where(f => f.Size == details.Size && Utilities.MemCompare(f.Hash, details.Hash)).FirstOrDefault();
            });


            if (share != null && share.Completed)
            {
                return(GetFilePath(share));
            }


            return(null);
        }
コード例 #20
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public static SharedFile Decode(G2Header header, ushort client)
        {
            SharedFile root  = new SharedFile(client);
            G2Header   child = new G2Header(header.Data);

            while (G2Protocol.ReadNextChild(header, child) == G2ReadResult.PACKET_GOOD)
            {
                if (child.Name == Packet_Public)
                {
                    root.Public = true;
                }

                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Name:
                    root.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Hash:
                    root.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Size:
                    root.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_FileKey:
                    root.FileKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_SystemPath:
                    root.SystemPath = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(root);
        }
コード例 #21
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        public void RemoveFile(SharedFile file)
        {
            if (file.Hash != null)
            {
                // stop any current transfer of file
                Core.Transfers.CancelDownload(ServiceID, file.Hash, file.Size);

                try
                {
                    File.Delete(GetFilePath(file));
                }
                catch { }
            }

            Local.Files.SafeRemove(file);

            RunSave = true;

            Core.RunInGuiThread(GuiFileUpdate, file);
        }
コード例 #22
0
ファイル: SharingView.cs プロジェクト: nandub/DeOps
        public int GetImageIndex(SharedFile share)
        {
            string ext = Path.GetExtension(share.Name);

            if (!IconMap.ContainsKey(ext))
            {
                IconMap[ext] = FileIcons.Count;

                Bitmap img = Win32.GetIcon(ext);


                if (img == null)
                {
                    img = new Bitmap(16, 16);
                }

                FileIcons.Add(img);
            }

            return(IconMap[ext]);
        }
コード例 #23
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        void Search_FoundLocation(byte[] data, object arg)
        {
            SharedFile file = arg as SharedFile;

            if (file.Completed)
            {
                return;
            }

            OpTransfer transfer = null;

            // add locations to running transfer
            LocationData loc    = LocationData.Decode(data);
            DhtClient    client = new DhtClient(loc.UserID, loc.Source.ClientID);

            if (transfer == null)
            {
                transfer = StartTransfer(client, file);
            }

            Core.Network.LightComm.Update(loc);
            transfer.AddPeer(client);
        }
コード例 #24
0
ファイル: SharingView.cs プロジェクト: nandub/DeOps
        void Sharing_FileUpdate(SharedFile share)
        {
            // only for local user
            if (UserID != Core.UserID)
            {
                return;
            }

            bool deleted = false;

            Sharing.Local.Files.LockReading(() =>
            {
                deleted = !Sharing.Local.Files.Any(s => s == share);
            });

            // if share exists
            ShareItem exists = SharedFiles.Items.Cast <ShareItem>().Where(s => s.Share == share).FirstOrDefault();

            if (exists != null)
            {
                if (deleted)
                {
                    SharedFiles.Items.Remove(exists);
                }
                else
                {
                    exists.RefreshStatus();
                }
            }
            else if (!deleted)
            {
                SharedFiles.Items.Add(new ShareItem(this, share));
            }

            SharedFiles.Invalidate();
        }
コード例 #25
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
 public SharedFile(SharedFile copy, ushort client)
 {
     ClientID = client;
     Name = copy.Name;
     Hash = copy.Hash;
     Size = copy.Size;
     FileKey = copy.FileKey;
     FileID = OpTransfer.GetFileID((uint)ServiceIDs.Share, Hash, Size);
 }
コード例 #26
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public static SharedFile Decode(G2Header header, ushort client)
        {
            SharedFile root = new SharedFile(client);
            G2Header child = new G2Header(header.Data);

            while (G2Protocol.ReadNextChild(header, child) == G2ReadResult.PACKET_GOOD)
            {
                if (child.Name == Packet_Public)
                    root.Public = true;

                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Name:
                        root.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Hash:
                        root.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Size:
                        root.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_FileKey:
                        root.FileKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_SystemPath:
                        root.SystemPath = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;
                }
            }

            return root;
        }
コード例 #27
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public void DownloadFile(ulong user, SharedFile file)
        {
            // donwloading from a different user, make a copy of their share, and activate download
            // copies are checked for

            if (File.Exists(GetFilePath(file)))
                return;

            SharedFile localCopy = new SharedFile(file, Core.Network.Local.ClientID);
            localCopy.Sources.Add(new DhtClient(user, file.ClientID));

            DownloadFile(localCopy);
        }
コード例 #28
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public void DownloadLink(string text)
        {
            FileLink link = FileLink.Decode(text, Core);

            SharedFile file = new SharedFile(Core.Network.Local.ClientID);

            file.Name = link.FileName;

            if (!Utilities.MemCompare(link.PublicOpID, Core.User.Settings.PublicOpID))
                throw new Exception("File Link is not for this Op");

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

            if(link.Sources != null)
                for (int i = 0; i < link.Sources.Length; i += 10)
                    file.Sources.Add(DhtClient.FromBytes(link.Sources, i));

            DownloadFile(file);
        }
コード例 #29
0
ファイル: IMService.cs プロジェクト: RoelofSol/DeOps
        public void Share_FileProcessed(SharedFile file, object arg)
        {
            ulong user = (ulong)arg;

            ShareService share = Core.GetService(ServiceIDs.Share) as ShareService;

            string message = "File: " + file.Name +
                ", Size: " + Utilities.ByteSizetoDecString(file.Size) +
                ", Download: " + share.GetFileLink(Core.UserID, file);

            SendMessage(user, message, TextFormat.Plain);
        }
コード例 #30
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public string GetFilePath(SharedFile file)
        {
            if (file.Hash == null)
                return "";

            return SharePath + Utilities.CryptFilename(Core, Core.UserID, file.Hash);
        }
コード例 #31
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public void OpenFile(ulong user, SharedFile file)
        {
            if (!File.Exists(GetFilePath(file)))
                return;

            // check if already exists, if it does open
            if (file.SystemPath != null && File.Exists(file.SystemPath))
            {
                Process.Start(file.SystemPath);
                return;
            }

            OpenFiles.Enqueue(() => OpenFile(file));
        }
コード例 #32
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public void RemoveFile(SharedFile file)
        {
            if (file.Hash != null)
            {
                // stop any current transfer of file
                Core.Transfers.CancelDownload(ServiceID, file.Hash, file.Size);

                try
                {
                    File.Delete(GetFilePath(file));
                }
                catch { }
            }

            Local.Files.SafeRemove(file);

            RunSave = true;

            Core.RunInGuiThread(GuiFileUpdate, file);
        }
コード例 #33
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public void SendFile(string path, Tuple<FileProcessedHandler, object> processed)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(() => SendFile(path, processed));
                return;
            }

            // add to share list
            SharedFile file = new SharedFile(Core.Network.Local.ClientID);
            file.Name = Path.GetFileName(path);
            file.SystemPath = path;

            file.Completed = true;
            file.Sources.Add(Core.Network.Local);
            file.FileStatus = "Processing...";
            file.Processed = processed;

            // so user can see hash progress
            Local.Files.SafeAdd(file);
            Core.RunInGuiThread(GuiFileUpdate, file);

            ProcessFiles.Enqueue(() => ProcessFile(file));
        }
コード例 #34
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        void DownloadFile(SharedFile file)
        {
            SharedFile existing = null;

            Local.Files.LockReading(() =>
                existing = Local.Files.Where(s => Utilities.MemCompare(s.Hash, file.Hash)).FirstOrDefault());

            // just add new targets if we already have this file
            if (existing != null)
            {
                if (existing.Completed)
                    return;

                existing.Sources = existing.Sources.Union(file.Sources).ToList();
                file = existing;
            }
            else
                Local.Files.SafeAdd(file);

            // if downloading form another client of self
            if (file.ClientID != Core.Network.Local.ClientID)
            {
                file.ClientID = Core.Network.Local.ClientID;
                Core.RunInGuiThread(GuiCollectionUpdate, Core.UserID);
            }

            Core.RunInCoreAsync(() =>
            {
                if (file.Sources.Count > 0)
                {
                    OpTransfer transfer = StartTransfer(file.Sources[0], file);

                    file.Sources.ForEach(s => transfer.AddPeer(s));
                }

                TempLocation.Search(file.FileID, file, Search_FoundLocation);
            });

            RunSave = true;

            file.FileStatus = "Incomplete";

            Core.RunInGuiThread(GuiFileUpdate, file);
        }
コード例 #35
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        void OpenFile(SharedFile file)
        {
            if (!Directory.Exists(DownloadPath))
                Directory.CreateDirectory(DownloadPath);

            string finalpath = DownloadPath + file.Name;

            int i = 1;
            while (File.Exists(finalpath))
                finalpath = DownloadPath + "(" + (i++) + ") " + file.Name;

            // decrypt file to temp dir
            file.FileStatus = "Unsecuring...";
            Utilities.DecryptTagFile(GetFilePath(file), finalpath, file.FileKey, Core);

            file.SystemPath = finalpath;
            file.FileStatus = "File in Downloads Folder";

            Process.Start(finalpath);

            RunSave = true;
        }
コード例 #36
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        public string GetFileLink(ulong user, SharedFile file)
        {
            byte[] sources = null;

            // if local shared file, get the sources we know of
            if (user == Core.UserID && file.ClientID == Core.Network.Local.ClientID)
            {
                foreach (DhtClient client in file.Sources)
                    sources = (sources == null) ? client.ToBytes() : Utilities.CombineArrays(sources, client.ToBytes());
            }

            // else getting link from remote share, so add it's address as a location
            else
                sources = new DhtClient(user, file.ClientID).ToBytes();

            FileLink link = new FileLink()
            {
                OpName = Core.User.Settings.Operation,
                FileName = file.Name,
                PublicOpID = Core.User.Settings.PublicOpID,
                Size = file.Size,
                Hash = file.Hash,
                Key = file.FileKey,
                Sources = sources
            };

            return link.Encode(Core);
        }
コード例 #37
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        private OpTransfer StartTransfer(DhtClient client, SharedFile file)
        {
            FileDetails details = new FileDetails(ServiceID, DataTypeShare, file.Hash, file.Size, null);
            object[] args = new object[] { file };

            OpTransfer transfer = Core.Transfers.StartDownload(client.UserID, details, GetFilePath(file), new EndDownloadHandler(FileDownloadFinished), args);

            transfer.AddPeer(client);

            file.TransferStatus =  "Starting download from " + Core.GetName(client.UserID);

            return transfer;
        }
コード例 #38
0
ファイル: ShareService.cs プロジェクト: nandub/DeOps
        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);
            }
        }
コード例 #39
0
ファイル: ShareService.cs プロジェクト: RoelofSol/DeOps
        void ProcessFile(SharedFile file)
        {
            try
            {
                // copied from storage service

                // hash file fast - used to gen key/iv
                file.FileStatus = "Identifying...";
                byte[] internalHash = null;
                long internalSize = 0;
                Utilities.Md5HashFile(file.SystemPath, ref internalHash, ref internalSize);

                // dont bother find dupe, becaues dupe might be incomplete, in which case we want to add
                // completed file to our shared, have timer find dupes, and if both have the same file path that exists, remove one

                RijndaelManaged crypt = Utilities.CommonFileKey(Core.User.Settings.OpKey, internalHash);
                file.FileKey = crypt.Key;

                // encrypt file to temp dir
                file.FileStatus = "Securing...";
                string tempPath = Core.GetTempPath();
                Utilities.EncryptTagFile(file.SystemPath, tempPath, crypt, Network.Protocol, ref file.Hash, ref file.Size);
                file.FileID = OpTransfer.GetFileID(ServiceID, file.Hash, file.Size);

                // move to official path
                string path = GetFilePath(file);
                if (!File.Exists(path))
                    File.Move(tempPath, path);

                file.FileStatus = "Secured";

                // run in core thread -> save, send request to user
                if (file.Processed != null)
                    Core.RunInCoreAsync(() => file.Processed.Param1.Invoke(file, file.Processed.Param2));

                RunSave = true;
            }
            catch(Exception ex)
            {
                file.FileStatus = "Error: " + ex.Message;
            }
        }