Esempio n. 1
0
        private async void GetUpdatedFile()
        {
            //preciso de arranjar maneira de mudar o caminho do ficheiro
            await Tmanager.StopAsync();

            await TorrentClientAPI.engine.Unregister(Tmanager);

            Tmanager.Dispose();
            PastaRoot.ChildFiles.Remove(this);
            File.Delete(Environment.CurrentDirectory + FilePath);
            FileModel NewFile = FSDatabaseFunctions.GetOneFile(FileID, NetID);

            FileVersion = NewFile.FileVersion;
            Tmanager    = NewFile.Tmanager;
            FilePath    = NewFile.FilePath;
            ToggleWillDownload();
            DEP           = new SqlDependency(new SqlCommand("Select * FROM Files WHERE FileID = " + FileID, ConnectionStuff.con));
            DEP.OnChange += new OnChangeEventHandler(FileChangedRemotelyEH);
            PastaRoot.ChildFiles.Add(this);
        }
Esempio n. 2
0
        //Inicializar um ficheiro a partir de um ficheiro local
        public FileModel(string NewFilePath, string OldFilePath, string NewNetID, bool NewWillDownload = true)
        {
            FileVersion = 1;
            FileName    = NewFilePath.Substring(NewFilePath.LastIndexOf('\\') + 1);
            String PathPastaMae = NewFilePath.Remove(NewFilePath.LastIndexOf('\\'));

            if (!MainProps.EvryFolder.Exists(Obj => Obj.RelativePath == PathPastaMae))
            {
                PastaRoot = new FolderModel(PathPastaMae);
            }
            else
            {
                PastaRoot = MainProps.EvryFolder.Find(Obj => Obj.RelativePath == PathPastaMae);
            }
            if (File.Exists(OldFilePath))
            {
                File.Move(OldFilePath, Environment.CurrentDirectory + NewFilePath);
            }
            FilePath = NewFilePath;
            byte[]  bytes   = TCreator.GetBytesFromFile(NewFilePath);
            Torrent torrent = TCreator.GetTorrentFromByte(bytes);

            if (TorrentClientAPI.fastResume.ContainsKey(torrent.InfoHash.ToHex()))
            {
                Tmanager.LoadFastResume(new FastResume((BEncodedDictionary)TorrentClientAPI.fastResume[torrent.InfoHash.ToHex()]));
            }
            else
            {
                Tmanager = new TorrentManager(torrent, Environment.CurrentDirectory);
            }
            NetID        = NewNetID;
            WillDownload = NewWillDownload;
            FileID       = FSDatabaseFunctions.AddFileGetFileID(FilePath, NetID, bytes);
            ToggleWillDownload();
            DEP           = new SqlDependency(new SqlCommand("Select * FROM Files WHERE FileID = " + FileID, ConnectionStuff.con));
            DEP.OnChange += new OnChangeEventHandler(FileChangedRemotelyEH);
            PastaRoot.ChildFiles.Add(this);
        }
        private static async Task ShutdownV2()
        {
            fastResume = new BEncodedDictionary();
            foreach (var Tmanager in engine.Torrents)
            {
                var stoppingTask = Tmanager.StopAsync();
                while (Tmanager.State != TorrentState.Stopped)
                {
                    Thread.Sleep(250);
                }
                await stoppingTask;
                if (Tmanager.HashChecked)
                {
                    fastResume.Add(Tmanager.Torrent.InfoHash.ToHex(), Tmanager.SaveFastResume().Encode());
                }
            }

            var nodes = await engine.DhtEngine.SaveNodesAsync();

            File.WriteAllBytes(dhtNodeFile, nodes);
            File.WriteAllBytes(fastResumeFile, fastResume.Encode());
            engine.Dispose();
            Thread.Sleep(2000);
        }