Ejemplo n.º 1
0
 private void TorrentRemovedAlert(Core.torrent_removed_alert a)
 {
     Interlocked.MemoryBarrier();
     using (Core.Sha1Hash sha1hash = a.info_hash)
     {
         string hash = sha1hash.ToString();
         if (TorrentList.ToList().Any(e => e.Hash == hash))
         {
             Models.TorrentItem ti = TorrentList.ToList().First(f => f.Hash == hash);
             log.Debug("removing {0}", ti.Name);
             Application.Current.Dispatcher.BeginInvoke(
                 System.Windows.Threading.DispatcherPriority.Normal,
                 (Action) delegate()
             {
                 TorrentList.Remove(ti);
             });
             log.Info("{0} removed", ti.Name);
         }
         if (File.Exists("./Fastresume/" + hash + ".fastresume"))
         {
             File.Delete("./Fastresume/" + hash + ".fastresume");
         }
         if (File.Exists("./Fastresume/" + hash + ".torrent"))
         {
             File.Delete("./Fastresume/" + hash + ".torrent");
         }
     }
 }
Ejemplo n.º 2
0
        private void PieceFinishedAlert(piece_finished_alert a)
        {
            Interlocked.MemoryBarrier();
            using (Core.TorrentHandle th = a.handle)
                using (Core.Sha1Hash hash = th.info_hash())
                {
                    if (TorrentList.ToList().Any(x => x.Hash == hash.ToString()))
                    {
                        Models.TorrentItem ti = TorrentList.First(z => z.Hash == hash.ToString());
                        if (!ReferenceEquals(null, ti.Pieces.Parts) && ti.Pieces.Parts.Any(q => q.Id == a.piece_index))
                        {
                            ti.Pieces.Parts[a.piece_index].Downloaded = true;
                            log.Debug("{0} for {1}", a.piece_index, ti.Name);
                            foreach (Models.FileEntry item in ti.FileList)
                            {
                                foreach (Models.Part part in item.Pieces.Where(k => k.Id == a.piece_index))
                                {
                                    part.Downloaded = true;
                                }
                            }

                            if (ti.SequentialDownload)
                            {
                                if (ti.Pieces.Parts.Any(w => w.Downloaded == false))
                                {
                                    Models.Part mp = ti.Pieces.Parts.First(w => w.Downloaded == false);
                                    mp.Priority = 7;
                                    th.piece_priority(mp.Id, 7);
                                }
                            }
                        }
                    }
                }
        }
Ejemplo n.º 3
0
        private async void SearchToday()
        {
            if (groupBoxFano.IsVisible || groupBoxKinozal.IsVisible || groupBoxFilebase.IsVisible)
            {
                UIDisable();

                borderBack.Visibility = Visibility.Collapsed;
                btnBack.Visibility    = Visibility.Collapsed;

                Title = txtToday.Text + " torrenti";
                progressBar.Visibility = Visibility.Visible;
                containerCovers.Children.Clear();
                containerList.Children.Clear();
                filterPanel.Content          = null;
                filterPanelCategorys.Content = null;

                TorrentList tList = new TorrentList();
                containerList.Children.Add(tList);
                await tList.Search("", "Visas", "Visi", "Visi", true);

                while (!tList.fanoCompleted || !tList.kinozalCompleted || !tList.filebaseCompleted)
                {
                    await Task.Delay(300);
                }

                UIEnable();
                CategoryFilter catFilter = new CategoryFilter(tList, tList.categorySet);
                filterPanelCategorys.Content    = catFilter;
                filterPanelCategorys.Visibility = Visibility.Visible;
            }
            else
            {
                MessageBox.Show("Jāpievieno vismaz viens trakeris, lai meklētu!", "TM", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Ejemplo n.º 4
0
 public void Resume(TorrentList torrents)
 {
     foreach (Sohvaperuna.TorrentEngine.Torrent tor in torrents)
     {
         if (torrentMapping.ContainsKey(tor.Hash))
         {
             global::AzureusEngine.AzCommunication.Download dl = torrentMapping[tor.Hash];
             dl.Start();
         }
     }
 }
Ejemplo n.º 5
0
        public TorrentList TorrentsByLabel(TorrentLabel _selectedLabel)
        {
            TorrentList list = new TorrentList();

            foreach (Sohvaperuna.TorrentEngine.Torrent torrent in _torrentsAll)
            {
                if (_selectedLabel.Name.CompareTo(torrent.Label) == 0)
                {
                    //label match!
                    list.Add(torrent);
                }
            }

            return(list);
        }
Ejemplo n.º 6
0
 public void Stop(TorrentList torrents)
 {
     if (torrents.Count == TorrentsAll.Count)
     {
         string response = GetResponse("core.stop_all_torrents", null);
     }
     else
     {
         List <string> Hashs = new List <string>();
         foreach (Torrent torrent in torrents)
         {
             Hashs.Add(torrent.Hash);
         }
         string response = GetResponse("core.stop_torrent", Hashs);
     }
 }
Ejemplo n.º 7
0
        private async void MekletStart()
        {
            if (groupBoxFano.IsVisible || groupBoxKinozal.IsVisible || groupBoxFilebase.IsVisible)
            {
                UIDisable();

                borderBack.Visibility = Visibility.Collapsed;
                btnBack.Visibility    = Visibility.Collapsed;

                progressBar.Visibility = Visibility.Visible;
                containerCovers.Children.Clear();
                containerList.Children.Clear();
                filterPanel.Content          = null;
                filterPanelCategorys.Content = null;

                TorrentList tList = new TorrentList();
                containerList.Children.Add(tList);
                await tList.Search(CmbMeklet.Text, cmbCategory.Text, cmbGenre.Text, cmbYear.Text, false);

                while (!tList.fanoCompleted || !tList.kinozalCompleted || !tList.filebaseCompleted)
                {
                    await Task.Delay(300);
                }

                CategoryFilter catFilter = new CategoryFilter(tList, tList.categorySet);
                filterPanelCategorys.Content    = catFilter;
                filterPanelCategorys.Visibility = Visibility.Visible;

                if (!string.IsNullOrEmpty(CmbMeklet.Text.Trim()))
                {
                    Title = CmbMeklet.Text.Trim();
                    config.DeleteHistoryElementIfExist(CmbMeklet.Text.Trim());
                    config.AddHistory(CmbMeklet.Text.Trim());
                    CmbMeklet.Items.Clear();
                    LoadHistory();
                    CmbMeklet.Text = "";
                }

                UIEnable();
                cmbCategory.IsEnabled = true;
                EnableComboBoxes(cmbCategory.Text);
            }
            else
            {
                MessageBox.Show("Jāpievieno vismaz viens trakeris, lai meklētu!", "TM", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Ejemplo n.º 8
0
    static void InitMonoTorrent()
    {
        queue            = new ArrayList();
        engine_settings  = new EngineSettings(config.DownloadDir, config.ListenPort);
        torrent_settings = new TorrentSettings(config.UploadSlots, config.MaxConnections,
                                               (int)config.UploadSpeed, (int)config.DownloadSpeed);

        engine = new ClientEngine(engine_settings);

        // Our store
        torrent_list = new TorrentList();
        foreach (TorrentDesc td in config.Torrents)
        {
            if (File.Exists(td.Filename))
            {
                torrent_list.Add(td.Filename);
            }
        }
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Remove torrent without data.
        /// </summary>
        /// <param name="id">Torrent id.</param>
        private async void RemoveTorrent(uint id)
        {
            if (_transmissionClient is not null)
            {
                var toRemoveIds = new[] { id };

                var result = await _transmissionClient.TorrentRemoveAsync(toRemoveIds, new CancellationToken(), false);


                foreach (var toRemoveId in toRemoveIds)
                {
                    var itm = TorrentList.First(x => x.Id == toRemoveId);
                    TorrentList.Remove(itm);

                    //FOR WHAT IS THAT?!
                    //TODO: Remove maybe
                    allTorrents.Torrents = allTorrents.Torrents.Where(torrentInfo => torrentInfo.Id == toRemoveId).ToArray();
                }
            }
        }
Ejemplo n.º 10
0
 private async void StateUpdateAlert(Core.state_update_alert a)
 {
     Interlocked.MemoryBarrier();
     log.Trace("state update alert for {0} torrents", a.status.Count());
     if (a.status.Count() > 0 && log.IsDebugEnabled)
     {
         log.Debug("state update alert for {0} torrents", a.status.Count());
     }
     foreach (Core.TorrentStatus ts in a.status)
     {
         using (ts)
             using (Core.Sha1Hash hash = ts.info_hash)
             {
                 if (TorrentList.ToList().Any(z => z.Hash == hash.ToString()))
                 {
                     Models.TorrentItem ti = TorrentList.First(e => e.Hash == hash.ToString());
                     await System.Threading.Tasks.Task.Run(() => ti.Update(ts));
                 }
             }
     }
 }
Ejemplo n.º 11
0
        private async void TorrentAddedAlert(Core.torrent_added_alert a)
        {
            Interlocked.MemoryBarrier();
            using (Core.TorrentHandle th = a.handle)
                using (Core.TorrentStatus ts = th.status())
                {
                    Models.TorrentItem ti = new Models.TorrentItem(ts);
                    ti.PropertyChanged += torrentItem_PropertyChanged;

                    await Application.Current.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Send,
                        (Action) delegate()
                    {
                        TorrentList.Add(ti);
                        log.Debug("{0} added", ti.Name);
                        //Hardcodet.Wpf.TaskbarNotification.TaskbarIcon tbi = (Hardcodet.Wpf.TaskbarNotification.TaskbarIcon)App.Current.MainWindow.FindName("tsunamiNotifyIcon");
                        //string title = "Tsunami";
                        //string text = "New torrent added!";
                        //tbi.ShowBalloonTip(title, text, tbi.Icon, true);
                    });
                }
        }
Ejemplo n.º 12
0
        public void Sort()
        {
            var selected = orderbyPanel.Children.OfType <RadioButton>().FirstOrDefault(r => r.IsChecked.Value);

            if (selected == null || TorrentList == null)
            {
                return;
            }
            switch (selected.Content.ToString())
            {
            case "Smallest size":
                TorrentList = TorrentList.OrderBy(t => t.SizeMB).ToList();
                break;

            case "Most recent":
                TorrentList = TorrentList.OrderByDescending(t => t.Added).ToList();
                break;

            case "Most seeded":
                TorrentList = TorrentList.OrderByDescending(t => t.Seeders).ToList();
                break;
            }
        }
 private void ReturnWithSave_Click(object sender, EventArgs e)
 {
     string[] strArray;
     if (this.BTCMDSelect.Checked)
     {
         strArray = Strings.Split(this.TornadoCommandLine.Text, "|", -1, CompareMethod.Binary);
         ArrayList list = new ArrayList();
         foreach (string str in strArray)
         {
             TorrentList list3 = new TorrentList();
             ArrayList list2 = new ArrayList();
             foreach (string str2 in Strings.Split(Strings.Trim(str), ",", -1, CompareMethod.Binary))
             {
                 if (Strings.Trim(str2) != "")
                 {
                     TorrentString str3 = new TorrentString {
                         Value = Strings.Trim(str2)
                     };
                     list2.Add(str3);
                 }
             }
             if (list2.Count > 0)
             {
                 list3.Value = list2;
                 list.Add(list3);
             }
         }
         MultiTrackerTiers.Value = list;
     }
     else if (this.BTGuiSelect.Checked)
     {
         strArray = Strings.Split(this.BitTornadoGUI.Text, "\n", -1, CompareMethod.Binary);
         ArrayList list4 = new ArrayList();
         foreach (string str4 in strArray)
         {
             string mystr4 = "";
             if (Strings.Right(str4, 1) == "\r")
             {
                 mystr4 = Strings.Left(str4, Strings.Len(str4) - 1);
             }
             mystr4 = Strings.Trim(mystr4);
             TorrentList list6 = new TorrentList();
             ArrayList list5 = new ArrayList();
             foreach (string str5 in Strings.Split(mystr4, " ", -1, CompareMethod.Binary))
             {
                 if (Strings.Trim(str5) != "")
                 {
                     TorrentString str6 = new TorrentString {
                         Value = Strings.Trim(str5)
                     };
                     list5.Add(str6);
                 }
             }
             if (list5.Count > 0)
             {
                 list6.Value = list5;
                 list4.Add(list6);
             }
         }
         MultiTrackerTiers.Value = list4;
     }
     this.Close();
 }
Ejemplo n.º 14
0
 public static int GetWebSeedData(ArrayList returnarray)
 {
     int count = 0;
     if (File.Exists(TorrentBuild.LocalPath + "wsa.configure"))
     {
         int fileNumber = FileSystem.FreeFile();
         FileSystem.FileOpen(fileNumber, TorrentBuild.LocalPath + "wsa.configure", OpenMode.Binary, OpenAccess.Read, OpenShare.LockRead, -1);
         string str = Strings.Space((int) FileSystem.FileLen(TorrentBuild.LocalPath + "wsa.configure"));
         FileSystem.FileGet(fileNumber, ref str, -1L, false);
         FileSystem.FileClose(new int[] { fileNumber });
         TorrentDictionary dictionary = new TorrentDictionary();
         dictionary.Parse(str);
         if (dictionary.Contains("seedlist"))
         {
             TorrentList list = new TorrentList();
             list = (TorrentList) dictionary["seedlist"];
             returnarray = list.Value;
             count = returnarray.Count;
         }
         else
         {
             TorrentString str2 = new TorrentString();
             TorrentString str3 = new TorrentString();
             TorrentString str4 = new TorrentString();
             TorrentString str5 = new TorrentString();
             TorrentString str6 = new TorrentString();
             str2 = (TorrentString) dictionary["seed1"];
             str3 = (TorrentString) dictionary["seed2"];
             str4 = (TorrentString) dictionary["seed3"];
             str5 = (TorrentString) dictionary["seed4"];
             str6 = (TorrentString) dictionary["seed5"];
             ArrayList list2 = new ArrayList();
             TorrentList list3 = new TorrentList();
             if (str2.Value != "")
             {
                 returnarray.Add(str2);
                 count++;
             }
             if (str3.Value != "")
             {
                 returnarray.Add(str3);
                 count++;
             }
             if (str4.Value != "")
             {
                 returnarray.Add(str4);
                 count++;
             }
             if (str5.Value != "")
             {
                 returnarray.Add(str5);
                 count++;
             }
             if (str6.Value != "")
             {
                 returnarray.Add(str6);
                 count++;
             }
         }
         if (TorrentBuild.GenerateVerbose)
         {
             Interaction.MsgBox("Number of Webseeds loaded: " + Conversions.ToString(count), MsgBoxStyle.OkOnly, null);
         }
     }
     return count;
 }
Ejemplo n.º 15
0
 public void MakeTorrentFromFile(string NameOfFile)
 {
     FileStream stream;
     string str6 = "";
     string hexhash = "";
     string str13 = "";
     string str14 = "";
     long filesize = FileSystem.FileLen(NameOfFile);
     TorrentString str10 = new TorrentString();
     TorrentString str7 = new TorrentString();
     TorrentString str5 = new TorrentString();
     TorrentString str4 = new TorrentString();
     TorrentString str12 = new TorrentString();
     StringBuilder builder = new StringBuilder();
     HashChanger changer = new HashChanger();
     this.OptionalHashProgress.Maximum = CountMultiplier;
     this.OptionalHashProgress.Value = 0;
     if (filesize < 0x100000000L)
     {
         if (this.IncludeTiger.Checked)
         {
             this.TigerHash = new ThexThreaded();
             changer = new HashChanger {
                 bytehash = this.TigerHash.GetTTH_Value(NameOfFile)
             };
             Application.DoEvents();
             str12.Value = changer.rawhash;
             str13 = changer.base32;
             this.OptionalHashProgress.Value++;
         }
     }
     else
     {
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeSHA1.Checked)
     {
         changer = new HashChanger();
         stream = new FileStream(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         this.sha1.ComputeHash(stream);
         stream.Close();
         Application.DoEvents();
         changer.bytehash = this.sha1.Hash;
         str10.Value = changer.rawhash;
         hexhash = changer.hexhash;
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeMD5.Checked)
     {
         changer = new HashChanger();
         stream = new FileStream(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         this.md5.ComputeHash(stream);
         stream.Close();
         changer.bytehash = this.md5.Hash;
         Application.DoEvents();
         str7.Value = changer.hexhash;
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeCRC32.Checked)
     {
         CRC32 crc = new CRC32();
         int num7 = 0;
         stream = new FileStream(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         Stream stream2 = stream;
         stream = (FileStream) stream2;
         num7 = crc.GetCrc32(ref stream2);
         stream.Close();
         str4.Value = string.Format("{0:X8}", num7);
         Application.DoEvents();
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeED2K.Checked)
     {
         string str3 = "";
         this.GetED2KHash(NameOfFile, ref str6, ref str3);
         this.OptionalHashProgress.Value++;
         str5.Value = str3;
     }
     this.FileHandling = File.Open(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     byte[] bytes = new byte[0x15];
     if (this.AutomaticPieceSize.Checked)
     {
         this.piecesizetouse = this.getautopiecesize(filesize);
     }
     else
     {
         this.piecesizetouse = Conversions.ToInteger(this.PieceSize.Text);
     }
     long num3 = 0L;
     this.FileHandling.Seek(0L, SeekOrigin.Begin);
     while (num3 < filesize)
     {
         this.TorrentProgress.Value = (int) Math.Round((double) ((((double) num3) / ((double) filesize)) * 100.0));
         Application.DoEvents();
         byte[] array = new byte[((int) this.piecesizetouse) + 1];
         long num5 = this.FileHandling.Read(array, 0, (int) this.piecesizetouse);
         byte[] buffer = new byte[((int) (num5 - 1L)) + 1];
         long num16 = num5 - 1L;
         for (long i = 0L; i <= num16; i += 1L)
         {
             buffer[(int) i] = array[(int) i];
         }
         bytes = this.sha1.ComputeHash(buffer);
         int index = 0;
         do
         {
             str14 = str14 + Encoding.Default.GetString(bytes, index, 1);
             index++;
         }
         while (index <= 0x13);
         num3 += this.piecesizetouse;
         buffer = null;
         array = null;
         Thread.Sleep(10);
         GC.Collect();
     }
     this.TorrentProgress.Value = 100;
     this.FileHandling.Close();
     TorrentString str20 = new TorrentString();
     int length = NameOfFile.LastIndexOf(@"\");
     int num = Strings.Len(NameOfFile) - length;
     string str8 = Strings.Right(NameOfFile, num - 1);
     string str9 = Strings.Left(NameOfFile, length);
     TorrentString str19 = new TorrentString {
         Value = str8
     };
     TorrentString str17 = new TorrentString();
     TorrentNumber number = new TorrentNumber {
         Value = filesize
     };
     TorrentNumber number2 = new TorrentNumber {
         Value = this.piecesizetouse
     };
     str20.Value = str14;
     str17.Value = "UTF8";
     TorrentDictionary dictionary2 = new TorrentDictionary();
     TorrentDictionary dictionary = new TorrentDictionary();
     TorrentString str16 = new TorrentString {
         Value = this.AnnounceURL.Text
     };
     dictionary.Add("length", number);
     dictionary.Add("name", str19);
     dictionary.Add("pieces", str20);
     dictionary.Add("piece length", number2);
     if (this.MultiTrackerEnabled.Checked)
     {
         this.CheckMultitTrackerTiers();
         dictionary2.Add("announce-list", MultiTrackerGenerator.MultiTrackerTiers);
     }
     if (this.IncludeSHA1.Checked)
     {
         dictionary.Add("sha1", str10);
     }
     if (this.IncludeMD5.Checked)
     {
         dictionary.Add("md5sum", str7);
     }
     if (this.IncludeCRC32.Checked)
     {
         dictionary.Add("crc32", str4);
     }
     if (this.IncludeED2K.Checked)
     {
         dictionary.Add("ed2k", str5);
     }
     if (this.IncludeTiger.Checked)
     {
         dictionary.Add("tiger", str12);
     }
     if (UseWSAConfig)
     {
         ArrayList returnarray = new ArrayList();
         TorrentList list2 = new TorrentList();
         int webSeedData = TorrentGenFamily.GetWebSeedData(returnarray);
         list2.Value = returnarray;
         if (webSeedData >= 1)
         {
             dictionary2.Add("httpseeds", list2);
         }
     }
     TorrentString str2 = new TorrentString {
         Value = "Torrent Generated by VB.Net TorrentGen - Written by DWKnight"
     };
     dictionary2.Add("created by", str2);
     TorrentString str = new TorrentString();
     if (Strings.Trim(this.TorrentComment.Text) != "")
     {
         str.Value = Strings.Trim(this.TorrentComment.Text);
         dictionary2.Add("comment", str);
     }
     if (this.PrivateTorrent.Checked)
     {
         TorrentNumber number3 = new TorrentNumber {
             Value = 1L
         };
         dictionary["private"] = number3;
     }
     dictionary2.Add("info", dictionary);
     if (this.AnnounceURL.Text != "")
     {
         dictionary2.Add("announce", str16);
     }
     dictionary2.Add("encoding", str17);
     int fileNumber = FileSystem.FreeFile();
     string fileName = NameOfFile + ".torrent";
     FileSystem.FileOpen(fileNumber, fileName, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1);
     FileSystem.FilePut(fileNumber, dictionary2.BEncoded, -1L, false);
     FileSystem.FileClose(new int[] { fileNumber });
     bytes = null;
     if (this.MakeExternals.Checked)
     {
         if (this.IncludeSHA1.Checked)
         {
             int num11 = FileSystem.FreeFile();
             FileSystem.FileOpen(num11, NameOfFile + ".sha1", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num11, new object[] { str19.Value + " " + hexhash });
             FileSystem.FileClose(new int[] { num11 });
         }
         if ((filesize <= 0x118940000L) && this.IncludeTiger.Checked)
         {
             int num12 = FileSystem.FreeFile();
             FileSystem.FileOpen(num12, NameOfFile + ".tiger", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num12, new object[] { str19.Value + " " + str13 });
             FileSystem.FileClose(new int[] { num12 });
         }
         if (this.IncludeMD5.Checked)
         {
             int num13 = FileSystem.FreeFile();
             FileSystem.FileOpen(num13, NameOfFile + ".md5", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num13, new object[] { str19.Value + " " + str7.Value });
             FileSystem.FileClose(new int[] { num13 });
         }
         if (this.IncludeCRC32.Checked)
         {
             int num14 = FileSystem.FreeFile();
             FileSystem.FileOpen(num14, NameOfFile + ".sfv", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num14, new object[] { str19.Value + " " + str4.Value });
             FileSystem.FileClose(new int[] { num14 });
         }
         if (this.IncludeED2K.Checked)
         {
             LinkGeneration generation = new LinkGeneration {
                 FileName = str19.Value,
                 FileSize = number.Value,
                 ED2KHex = str6
             };
             int num15 = FileSystem.FreeFile();
             FileSystem.FileOpen(num15, NameOfFile + ".ed2k", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num15, new object[] { generation.ClassicED2KLink });
             FileSystem.PrintLine(num15, new object[] { str19.Value + " " + generation.ED2KHex + "\r\n" });
             FileSystem.FileClose(new int[] { num15 });
         }
     }
     GC.Collect();
 }
Ejemplo n.º 16
0
 private void CheckMultitTrackerTiers()
 {
     IEnumerator enumerator = null;
     try
     {
         enumerator = MultiTrackerGenerator.MultiTrackerTiers.Value.GetEnumerator();
         while (enumerator.MoveNext())
         {
             IEnumerator enumerator2 = null;
             TorrentList current = (TorrentList) enumerator.Current;
             try
             {
                 enumerator2 = current.Value.GetEnumerator();
                 while (enumerator2.MoveNext())
                 {
                     TorrentString str2 = (TorrentString) enumerator2.Current;
                     if (str2.Value == Strings.Trim(this.AnnounceURL.Text))
                     {
                         return;
                     }
                 }
                 continue;
             }
             finally
             {
                 if (enumerator2 is IDisposable)
                 {
                     (enumerator2 as IDisposable).Dispose();
                 }
             }
         }
     }
     finally
     {
         if (enumerator is IDisposable)
         {
             (enumerator as IDisposable).Dispose();
         }
     }
     TorrentString str = new TorrentString {
         Value = Strings.Trim(this.AnnounceURL.Text)
     };
     TorrentList list = new TorrentList();
     list.Value.Add(str);
     MultiTrackerGenerator.MultiTrackerTiers.Value.Add(list);
     GC.Collect();
 }
Ejemplo n.º 17
0
 private void TorrentBuild_Load(object sender, EventArgs e)
 {
     string[] commandLineArgs = Environment.GetCommandLineArgs();
     if (commandLineArgs.GetLength(0) > 1)
     {
         this.FileNameToMake.Text = commandLineArgs[1];
     }
     TorrentString str3 = new TorrentString();
     TorrentString str = new TorrentString();
     TorrentString str2 = new TorrentString();
     str3.Value = ".sfv";
     str.Value = ".cdp";
     str2.Value = ".cdt";
     BlackListedFiles.Add(str3);
     BlackListedFiles.Add(str);
     BlackListedFiles.Add(str2);
     int length = Strings.Left(commandLineArgs[0], Strings.Len(commandLineArgs[0])).LastIndexOf(@"\");
     LocalPath = Path.GetFullPath(Strings.Left(commandLineArgs[0], length)) + @"\";
     if (File.Exists(LocalPath + "tgen.configure"))
     {
         int fileNumber = FileSystem.FreeFile();
         FileSystem.FileOpen(fileNumber, LocalPath + "tgen.configure", OpenMode.Binary, OpenAccess.Read, OpenShare.LockRead, -1);
         string str4 = Strings.Space((int) FileSystem.FileLen(LocalPath + "tgen.configure"));
         FileSystem.FileGet(fileNumber, ref str4, -1L, false);
         FileSystem.FileClose(new int[] { fileNumber });
         TorrentDictionary dictionary = new TorrentDictionary();
         dictionary.Parse(str4);
         TorrentString str5 = new TorrentString();
         TorrentNumber number2 = new TorrentNumber();
         TorrentNumber number8 = new TorrentNumber();
         TorrentNumber number7 = new TorrentNumber();
         TorrentNumber number5 = new TorrentNumber();
         TorrentString str6 = new TorrentString();
         TorrentNumber number6 = new TorrentNumber();
         TorrentNumber number9 = new TorrentNumber();
         TorrentNumber number = new TorrentNumber();
         TorrentNumber number3 = new TorrentNumber();
         TorrentNumber number4 = new TorrentNumber();
         str5 = (TorrentString) dictionary["tracker"];
         number2 = (TorrentNumber) dictionary["piecesize"];
         if (dictionary.Contains("externals"))
         {
             number4 = (TorrentNumber) dictionary["externals"];
             this.MakeExternals.Checked = number4.Value > 0L;
         }
         if (dictionary.Contains("folder"))
         {
             number3 = (TorrentNumber) dictionary["folder"];
             this.MakeSeparateTorrents.Checked = number3.Value > 0L;
         }
         if (dictionary.Contains("sha1"))
         {
             number8 = (TorrentNumber) dictionary["sha1"];
             this.IncludeSHA1.Checked = number8.Value > 0L;
         }
         if (dictionary.Contains("md5"))
         {
             number7 = (TorrentNumber) dictionary["md5"];
             this.IncludeMD5.Checked = number7.Value > 0L;
         }
         if (dictionary.Contains("crc"))
         {
             number5 = (TorrentNumber) dictionary["crc"];
             this.IncludeCRC32.Checked = number5.Value > 0L;
         }
         if (dictionary.Contains("ed2k"))
         {
             number6 = (TorrentNumber) dictionary["ed2k"];
             this.IncludeED2K.Checked = number6.Value > 0L;
         }
         if (dictionary.Contains("tiger"))
         {
             number9 = (TorrentNumber) dictionary["tiger"];
             this.IncludeTiger.Checked = number9.Value > 0L;
         }
         if (dictionary.Contains("comment"))
         {
             str6 = (TorrentString) dictionary["comment"];
             this.TorrentComment.Text = str6.Value;
         }
         if (dictionary.Contains("advanced"))
         {
             TorrentDictionary dictionary2 = new TorrentDictionary();
             dictionary2 = (TorrentDictionary) dictionary["advanced"];
             TorrentNumber number12 = new TorrentNumber();
             TorrentNumber number11 = new TorrentNumber();
             TorrentNumber number10 = new TorrentNumber();
             number12 = (TorrentNumber) dictionary2["verbose"];
             number11 = (TorrentNumber) dictionary2["usewsa"];
             number10 = (TorrentNumber) dictionary2["delay"];
             GenerateVerbose = number12.Value > 0L;
             UseWSAConfig = number11.Value > 0L;
             DelayMessages = number10.Value > 0L;
         }
         else
         {
             GenerateVerbose = true;
             UseWSAConfig = false;
             DelayMessages = true;
         }
         if (dictionary.Contains("blankblacklist"))
         {
             TorrentNumber number13 = new TorrentNumber();
             if (number13.Value == -1L)
             {
                 BlackListedFiles = new ArrayList();
             }
         }
         if (dictionary.Contains("blacklist"))
         {
             TorrentList list = new TorrentList();
             list = (TorrentList) dictionary["blacklist"];
             BlackListedFiles = list.Value;
         }
         if (dictionary.Contains("multitracker"))
         {
             MultiTrackerGenerator.MultiTrackerTiers = (TorrentList) dictionary["multitracker"];
             this.Multitracker.UpdateInput();
         }
         if (dictionary.Contains("usemultitracker"))
         {
             TorrentNumber number14 = new TorrentNumber();
             number14 = (TorrentNumber) dictionary["usemultitracker"];
             this.MultiTrackerEnabled.Checked = number14.Value > 0L;
         }
         number = (TorrentNumber) dictionary["autopiece"];
         this.AutomaticPieceSize.Checked = number.Value > 0L;
         this.AnnounceURL.Text = str5.Value;
         this.PieceSize.Text = Conversions.ToString(number2.Value);
     }
     this.AutomaticPieceSize_CheckedChanged(RuntimeHelpers.GetObjectValue(sender), e);
     GC.Collect();
 }
Ejemplo n.º 18
0
	static void InitMonoTorrent ()
	{
		queue = new ArrayList ();
		engine_settings = new EngineSettings (config.DownloadDir, config.ListenPort);
		torrent_settings = new TorrentSettings (config.UploadSlots, config.MaxConnections,
							(int) config.UploadSpeed, (int) config.DownloadSpeed);
		
		engine = new ClientEngine (engine_settings);

		// Our store
		torrent_list = new TorrentList ();
		foreach (TorrentDesc td in config.Torrents){
			if (File.Exists (td.Filename)){
				torrent_list.Add (td.Filename);
			}
		}
	}
Ejemplo n.º 19
0
        public bool UpdateData()
        {
            lock (lockUpdate)
            {
                string response = GetResponse("web.update_ui", DelugeAPI.UpdateParams);
                if (response == null || response.Length == 0)
                {
                    return(false);
                }
                TorrentLabelList lbls   = new TorrentLabelList();
                UpdateResponse   update = js.Deserialize <UpdateResponse>(response);

                foreach (object[] lbl in update.filters.label)
                {
                    TorrentLabel label = new TorrentLabel();
                    label.Name  = (string)lbl[0];
                    label.Count = (int)lbl[1];
                    lbls.Add(label);
                }
                _labels = lbls;
                TorrentList oldTorrentsAll = _torrentsAll;
                TorrentList newTorrentsAll = new TorrentList();
                foreach (KeyValuePair <string, DelugeTorrent> pair in update.torrents)
                {
                    DelugeTorrent tor     = pair.Value;
                    Torrent       torrent = new Torrent(this);
                    try
                    {
                        torrent.Hash              = pair.Key;
                        torrent.Status            = 0;// get Status code
                        torrent.Name              = tor.name;
                        torrent.Size              = tor.total_size;
                        torrent.Progress          = tor.progress;
                        torrent.Downloaded        = tor.total_done;
                        torrent.Uploaded          = tor.total_uploaded;
                        torrent.Ratio             = (long)Math.Round(tor.ratio);
                        torrent.UploadSpeed       = (long)Math.Round(tor.upload_payload_rate);
                        torrent.DownloadSpeed     = (long)Math.Round(tor.download_payload_rate);
                        torrent.ETA               = (int)Math.Round(tor.eta);
                        torrent.Label             = tor.label;
                        torrent.PeersConnected    = tor.num_peers;
                        torrent.PeersInSwarm      = tor.total_peers;
                        torrent.SeedsConnected    = tor.num_seeds;
                        torrent.SeedsInSwarm      = tor.total_seeds;
                        torrent.Availability      = (int)Math.Round(tor.distributed_copies);
                        torrent.TorrentQueueOrder = (int)Math.Round(tor.queue);
                        torrent.Remaining         = tor.total_size - tor.total_done;
                        torrent.DownloadURL       = "";
                        torrent.RSSFeedURL        = "";
                        torrent.StatusMessage     = tor.state;
                        torrent.StreamID          = "";
                        torrent.AddedOn           = (int)Math.Round(tor.time_added);
                        torrent.CompletedOn       = 0;
                        torrent.AppUpdateURL      = "";
                        torrent.TorrentSavePath   = tor.save_path;
                    }
                    catch { }


                    newTorrentsAll.Add(torrent);
                }

                TorrentList newTorrentsActive = new TorrentList();

                foreach (Torrent torrent in newTorrentsAll)
                {
                    if (torrent.HasStatus((int)Torrent.UTorrentStatus.Started))
                    {
                        newTorrentsActive.Add(torrent);
                    }

                    if (oldTorrentsAll != null)
                    {
                        Torrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash);
                        if (oldTorrent == null)
                        {
                            //this is new torrent! Send event!
                            TimeSpan t   = (DateTime.UtcNow - new DateTime(1970, 1, 1));
                            int      now = (int)t.TotalSeconds;
                            if (TorrentAdded != null && ((now - torrent.AddedOn) < Math.Max(60, Convert.ToInt32(_outtimer) * 2)))
                            {
                                TorrentAdded(torrent);
                            }
                        }
                        else
                        {
                            if (torrent.Progress == 100 && oldTorrent.Progress < 100)
                            {
                                TorrentCompleted(torrent);
                            }
                            oldTorrentsAll.Remove(oldTorrent);
                        }
                    }
                }

                if (oldTorrentsAll != null && newTorrentsAll != null && oldTorrentsAll.Count != 0)
                {
                    if (newTorrentsAll.Count / oldTorrentsAll.Count > 0.95)
                    {
                        foreach (Torrent torrent in oldTorrentsAll)
                        {
                            //there are all removed torrents, send events!
                            if (TorrentRemoved != null)
                            {
                                TorrentRemoved(torrent);
                            }
                        }
                    }
                }

                //create no label label!
                TorrentLabel nolabel = new TorrentLabel();
                nolabel.Name = "";

                foreach (Torrent torrent in newTorrentsAll)
                {
                    if (torrent.Label == "")
                    {
                        torrent.Label = nolabel.Name;
                        nolabel.Count = nolabel.Count + 1;
                    }
                }
                if (!_labels.Exists(e => e.Name == ""))
                {
                    _labels.Insert(0, nolabel);
                }
                if (_torrentsAll == null)
                {
                    _torrentsAll = new TorrentList();
                }
                _torrentsAll.Clear();
                foreach (Torrent torrent in newTorrentsAll)
                {
                    _torrentsAll.Add(torrent);
                }
            }
            return(true);
        }
Ejemplo n.º 20
0
 private void MultiTrackerSettings_Click(object sender, EventArgs e)
 {
     TorrentList multiTrackerTiers = new TorrentList();
     multiTrackerTiers = MultiTrackerGenerator.MultiTrackerTiers;
     this.Multitracker = new MultiTrackerGenerator();
     MultiTrackerGenerator.MultiTrackerTiers = multiTrackerTiers;
     this.Multitracker.UpdateInput();
     this.Multitracker.Show();
 }
Ejemplo n.º 21
0
        public bool UpdateData()
        {
            lock (lockUpdate)
            {
                prot.DownloadManager.Update();
                TorrentList __torrentsAll    = new TorrentList();
                TorrentList __torrentsActive = new TorrentList();
                Dictionary <string, global::AzureusEngine.AzCommunication.Download> _torrentMapping = new Dictionary <string, global::AzureusEngine.AzCommunication.Download>();
                Dictionary <string, int> categories = new Dictionary <string, int>();

                foreach (Download dl in prot.DownloadManager.Downloads)
                {
                    Sohvaperuna.TorrentEngine.Torrent tor = toUtorrent(dl);
                    if (!categories.ContainsKey(tor.Label))
                    {
                        categories.Add(tor.Label, 1);
                    }
                    else
                    {
                        categories[tor.Label] = categories[tor.Label] + 1;
                    }
                    __torrentsAll.Add(tor);
                    if (!torrentMapping.ContainsKey(tor.Hash))
                    {
                        torrentMapping.Add(tor.Hash, dl);
                        if (TorrentAdded != null)
                        {
                            TorrentAdded(tor);
                        }
                    }
                    if (tor.Status == 1)
                    {
                        __torrentsActive.Add(tor);
                    }
                }
                foreach (Sohvaperuna.TorrentEngine.Torrent tor in __torrentsAll)
                {
                    Sohvaperuna.TorrentEngine.Torrent _tor = _torrentsAll.TorrentByHash(tor.Hash);
                    if (tor != null)
                    {
                        _torrentsAll.Remove(tor);
                    }
                }


                _torrentsActive = __torrentsActive;
                _torrentsAll    = __torrentsAll;

                TorrentLabelList labels = new TorrentLabelList();
                //_labels.Clear();
                foreach (string s in categories.Keys)
                {
                    TorrentLabel lbl = new TorrentLabel();
                    lbl.Name  = s;
                    lbl.Count = categories[s];
                    labels.Add(lbl);
                }
                _labels = labels;

                /*
                 * string response = GetResponse("list=1");
                 * Regex re = new Regex("\\[\"(.*?)\",([0-9])+]");
                 * MatchCollection matches = re.Matches(response);
                 * _labels = new UTorrentLabelList();
                 * foreach (Match match in matches)
                 * {
                 *  UTorrentLabel label = new UTorrentLabel();
                 *  label.Name = match.Groups[1].Value.Replace(@"\\", @"\"); ;
                 *  label.Count = Convert.ToInt32( match.Groups[2].Value );
                 *  _labels.Add(label);
                 * }
                 *
                 * re = new Regex("\\[\"(.*?)\",([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+)]");
                 * matches = re.Matches(response);
                 *
                 * UTorrentList oldTorrentsAll = _torrentsAll;
                 * UTorrentList newTorrentsAll = new UTorrentList();
                 * foreach (Match match in matches)
                 * {
                 *  UTorrent torrent = new UTorrent( this );
                 *  torrent.Hash = match.Groups[1].Value;
                 *  torrent.Status = Convert.ToInt32(match.Groups[2].Value);
                 *  torrent.Name = match.Groups[3].Value;
                 *  torrent.Size = Convert.ToInt64(match.Groups[4].Value);
                 *  torrent.Progress = Convert.ToInt32(match.Groups[5].Value) / 10.0;
                 *  torrent.Downloaded = Convert.ToInt64(match.Groups[6].Value);
                 *  torrent.Uploaded = Convert.ToInt64(match.Groups[7].Value);
                 *  torrent.Ratio = Convert.ToInt64(match.Groups[8].Value);
                 *  torrent.UploadSpeed = Convert.ToInt64(match.Groups[9].Value);
                 *  torrent.DownloadSpeed = Convert.ToInt64(match.Groups[10].Value);
                 *  torrent.ETA = Convert.ToInt32(match.Groups[11].Value);
                 *  torrent.Label = match.Groups[12].Value.Replace( @"\\", @"\" );
                 *  torrent.PeersConnected = Convert.ToInt32(match.Groups[13].Value);
                 *  torrent.PeersInSwarm = Convert.ToInt32(match.Groups[14].Value);
                 *  torrent.SeedsConnected = Convert.ToInt32(match.Groups[15].Value);
                 *  torrent.SeedsInSwarm = Convert.ToInt32(match.Groups[16].Value);
                 *  torrent.Availability = Convert.ToInt32(match.Groups[17].Value);
                 *  torrent.TorrentQueueOrder = Convert.ToInt32(match.Groups[18].Value);
                 *  torrent.Remaining = Convert.ToInt64(match.Groups[19].Value);
                 *
                 *  newTorrentsAll.Add(torrent);
                 * }
                 *
                 * UTorrentList newTorrentsActive = new UTorrentList();
                 *
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  if (torrent.HasStatus((int)UTorrent.UTorrentStatus.Started))
                 *  {
                 *      newTorrentsActive.Add(torrent);
                 *  }
                 *
                 *  if (oldTorrentsAll != null)
                 *  {
                 *      UTorrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash);
                 *      if (oldTorrent == null)
                 *      {
                 *          //this is new torrent! Send event!
                 *          if (TorrentAdded != null)
                 *          {
                 *              TorrentAdded(torrent);
                 *          }
                 *      }
                 *      else
                 *      {
                 *          oldTorrentsAll.Remove(oldTorrent);
                 *      }
                 *  }
                 * }
                 *
                 * if (oldTorrentsAll != null)
                 * {
                 *  foreach (UTorrent torrent in oldTorrentsAll)
                 *  {
                 *      //there are all removed torrents, send events!
                 *      if (TorrentRemoved != null)
                 *      {
                 *          TorrentRemoved(torrent);
                 *      }
                 *  }
                 * }
                 *
                 * //create no label label!
                 * UTorrentLabel nolabel = new UTorrentLabel();
                 * nolabel.Name = "";
                 *
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  if (torrent.Label == "")
                 *  {
                 *      torrent.Label = nolabel.Name;
                 *      nolabel.Count = nolabel.Count + 1;
                 *  }
                 * }
                 *
                 * _labels.Insert(0, nolabel);
                 *
                 * if (_torrentsActive == null)
                 * {
                 *  _torrentsActive = new UTorrentList();
                 * }
                 * _torrentsActive.Clear();
                 * foreach (UTorrent torrent in newTorrentsActive)
                 * {
                 *  _torrentsActive.Add(torrent);
                 * }
                 * if (_torrentsAll == null)
                 * {
                 *  _torrentsAll = new UTorrentList();
                 * }
                 * _torrentsAll.Clear();
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  _torrentsAll.Add(torrent);
                 * }*/
            }
            return(true);
        }
Ejemplo n.º 22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int page = 1;

            if (Request.QueryString["page"] != null)
            {
                Int32.TryParse(Request.QueryString["page"], out page);
                if (page < 1)
                {
                    page = 1;
                }
            }

            if (Request.QueryString["action"] != null)
            {
                if (Request.QueryString["action"].Equals("delete") && Request.QueryString["sha"] != null)
                {
                    try {
                        deleteAction(Request.QueryString["sha"]);
                        TopLabel.Text = "Record deleted successfully<br/>";
                    }
                    catch (Exception ex)
                    {
                        TopLabel.Text = String.Format("Error deleting record: {0}<br/>", ex.Message);
                        return;
                    }
                }
            }

            int rows = 0;

            try
            {
                rows = getRows();
            }
            catch (Exception ex)
            {
                TopLabel.Text = "Error: " + ex.Message;
                return;
            }
            if (rows > 0)
            {
                DataTable torrentDataTable = createTorrentDataTable();

                int max_pages;
                Int32.TryParse(ConfigurationManager.AppSettings["config_max_torrent_page"], out max_pages);

                int pages;
                if (max_pages > 0)
                {
                    pages = (int)Math.Ceiling((double)rows / max_pages);
                }
                else
                {
                    pages = 1;
                }

                if (page > pages)
                {
                    page = pages;
                }
                int offset = (page - 1) * max_pages;

                try {
                    createTorrentRows(offset, max_pages, torrentDataTable);
                }
                catch (Exception ex)
                {
                    TopLabel.Text = String.Format("Error: {0}", ex.Message);
                    return;
                }
                TorrentList.DataSource = torrentDataTable;
                TorrentList.DataBind();
                BotLabel.Text = "Page";
                for (int i = 1; i <= pages; ++i)
                {
                    BotLabel.Text += String.Format(" <a href=\"torrent.aspx?page={0}\">{0}</a>", i);
                }
            }
            else
            {
                TopLabel.Text += "0 results";
            }
        }
Ejemplo n.º 23
0
        public void MakeTorrentFromFolder(string fullPath)
        {
            string[] pathArray          = Directory.GetFiles(fullPath, "*", SearchOption.AllDirectories);
            string[] relative_pathArray = new string[pathArray.Length];

            int pathNameSize = fullPath.LastIndexOf(@"\");
            int fileNameSize = fullPath.Length - pathNameSize;

            string fileName       = fullPath.Substring(pathNameSize + 1, fileNameSize - 1);
            string fullPathToSave = parent.folderToSave + @"\" + fileName;

            TorrentDictionary mainDict = new TorrentDictionary();
            TorrentDictionary infoDict = new TorrentDictionary();

            ArrayList   fileArrayList = new ArrayList();
            TorrentList torr_fileList = new TorrentList();

            for (int i = 0; i < pathArray.Length; i++)
            {
                FileInfo myFile   = new FileInfo(pathArray[i]);
                long     filesize = myFile.Length;

                relative_pathArray[i] = pathArray[i].Substring(fullPath.Length + 1);

                string[]      path_splitted = relative_pathArray[i].Split('\\');
                TorrentNumber torr_filesize = new TorrentNumber {
                    Value = filesize
                };

                ArrayList pathArrayList = new ArrayList();

                TorrentDictionary itemDict = new TorrentDictionary();

                foreach (string path_chunk in path_splitted)
                {
                    TorrentString path_chunkString = new TorrentString {
                        Value = path_chunk
                    };
                    pathArrayList.Add(path_chunkString);
                }

                TorrentList torr_pathList = new TorrentList {
                    Value = pathArrayList
                };

                itemDict.Add("length", torr_filesize);
                itemDict.Add("path", torr_pathList);

                fileArrayList.Add(itemDict);
                if (i == pathArray.Length - 1)
                {
                    MakeContinuousHash(pathArray[i], true);
                }
                else
                {
                    MakeContinuousHash(pathArray[i], false);
                }
            }

            torr_fileList.Value = fileArrayList;
            infoDict.Add("files", torr_fileList);

            TorrentString torr_pieces = new TorrentString {
                Value = sha1_full.ToString()
            };

            infoDict.Add("pieces", torr_pieces);

            TorrentNumber torr_pieceLength = new TorrentNumber {
                Value = this.currentPieceSize
            };

            infoDict.Add("piece length", torr_pieceLength);

            TorrentString torr_name = new TorrentString {
                Value = fileName
            };

            infoDict.Add("name", torr_name);

            TorrentString torr_createdBy = new TorrentString {
                Value = "Criado por TorrentBuild Simplificado."
            };

            mainDict.Add("created by", torr_createdBy);

            TorrentString torr_encode = new TorrentString {
                Value = "UTF-8"
            };

            mainDict.Add("encoding", torr_encode);

            mainDict.Add("info", infoDict);

            using (FileStream fs = File.Open(fullPathToSave + ".torrent", FileMode.OpenOrCreate))
            {
                byte[] bencodedDict = Encoding.ASCII.GetBytes(mainDict.BEncoded);
                fs.Write(bencodedDict, 0, bencodedDict.Length);
            }
        }
Ejemplo n.º 24
0
 public void MakeOneTorrentFromFolder()
 {
     long num = 0;
     long num6 = 0;
     long num8 = 0;
     long num9 = 0;
     long num12 = 0;
     string[] strArray = Directory.GetFiles(this.FileNameToMake.Text, "*", SearchOption.AllDirectories);
     if (Strings.Right(this.FileNameToMake.Text, 1) != @"\")
     {
         this.FileNameToMake.Text = this.FileNameToMake.Text + @"\";
     }
     TorrentDictionary dictionary2 = new TorrentDictionary();
     TorrentList list = new TorrentList();
     ArrayList list2 = new ArrayList();
     this.OptionalHashProgress.Maximum = strArray.GetLength(0) * CountMultiplier;
     foreach (string str10 in strArray)
     {
         if (this.IsFileCleared(str10))
         {
             FileStream stream;
             byte[] hash;
             IEnumerator enumerator = null;
             TorrentDictionary dictionary3 = new TorrentDictionary();
             TorrentNumber number2 = new TorrentNumber();
             TorrentList list3 = new TorrentList();
             ArrayList list4 = new ArrayList();
             TorrentString str11 = new TorrentString();
             number2.Value = FileSystem.FileLen(str10);
             num12 += FileSystem.FileLen(str10);
             if (this.AutomaticPieceSize.Checked)
             {
                 num += number2.Value;
             }
             Array array = Strings.Right(str10, Strings.Len(str10) - Strings.Len(this.FileNameToMake.Text)).Split(new char[] { '\\' });
             try
             {
                 enumerator = array.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     string str13 = Conversions.ToString(enumerator.Current);
                     if (str13 != "")
                     {
                         TorrentString str14 = new TorrentString {
                             Value = str13
                         };
                         list4.Add(str14);
                     }
                 }
             }
             finally
             {
                 if (enumerator is IDisposable)
                 {
                     (enumerator as IDisposable).Dispose();
                 }
             }
             list3.Value = list4;
             dictionary3.Add("length", number2);
             dictionary3.Add("path", list3);
             StringBuilder builder = new StringBuilder();
             HashChanger changer = new HashChanger();
             if (number2.Value < 0x100000000L)
             {
                 if (this.IncludeTiger.Checked)
                 {
                     string str16 = "";
                     this.TigerHash = new ThexThreaded();
                     TorrentString str15 = new TorrentString();
                     hash = this.TigerHash.GetTTH_Value(str10);
                     Application.DoEvents();
                     int index = 0;
                     foreach (byte num13 in hash)
                     {
                         str16 = str16 + Encoding.Default.GetString(hash, index, 1);
                         index++;
                     }
                     str15.Value = str16;
                     str16 = "";
                     hash = null;
                     this.OptionalHashProgress.Value++;
                     dictionary3.Add("tiger", str15);
                 }
                 GC.Collect();
             }
             else
             {
                 this.OptionalHashProgress.Value++;
             }
             if (this.IncludeSHA1.Checked)
             {
                 TorrentString str17 = new TorrentString();
                 stream = new FileStream(str10, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                 this.sha1.ComputeHash(stream);
                 stream.Close();
                 Application.DoEvents();
                 hash = this.sha1.Hash;
                 changer.bytehash = this.sha1.Hash;
                 str17.Value = changer.rawhash;
                 builder.Remove(0, builder.Length);
                 hash = null;
                 this.OptionalHashProgress.Value++;
                 dictionary3.Add("sha1", str17);
                 GC.Collect();
             }
             if (this.IncludeMD5.Checked)
             {
                 TorrentString str19 = new TorrentString();
                 stream = new FileStream(str10, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                 builder = new StringBuilder();
                 this.md5.ComputeHash(stream);
                 Application.DoEvents();
                 stream.Close();
                 foreach (byte num13 in this.md5.Hash)
                 {
                     builder.AppendFormat("{0:x2}", num13);
                 }
                 str19.Value = builder.ToString();
                 builder.Remove(0, builder.Length);
                 hash = null;
                 this.OptionalHashProgress.Value++;
                 dictionary3.Add("md5sum", str19);
                 GC.Collect();
             }
             if (this.IncludeCRC32.Checked)
             {
                 TorrentString str20 = new TorrentString();
                 CRC32 crc = new CRC32();
                 int num15 = 0;
                 stream = new FileStream(str10, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                 Stream stream2 = stream;
                 stream = (FileStream) stream2;
                 num15 = crc.GetCrc32(ref stream2);
                 stream.Close();
                 Application.DoEvents();
                 str20.Value = string.Format("{0:X8}", num15);
                 this.OptionalHashProgress.Value++;
                 dictionary3.Add("crc32", str20);
                 GC.Collect();
             }
             if (this.IncludeED2K.Checked)
             {
                 string str21 = "";
                 string str22 = "";
                 TorrentString str23 = new TorrentString();
                 this.GetED2KHash(str10, ref str22, ref str21);
                 this.OptionalHashProgress.Value++;
                 str23.Value = str21;
                 dictionary3.Add("ed2k", str23);
                 GC.Collect();
             }
             list2.Add(dictionary3);
         }
         else
         {
             this.OptionalHashProgress.Maximum -= CountMultiplier;
         }
     }
     if (this.AutomaticPieceSize.Checked)
     {
         num9 = this.getautopiecesize(num);
     }
     else
     {
         num9 = Conversions.ToInteger(this.PieceSize.Text);
     }
     list.Value = list2;
     TorrentNumber number = new TorrentNumber {
         Value = num9
     };
     dictionary2.Add("files", list);
     dictionary2.Add("piece length", number);
     long upperBound = strArray.GetUpperBound(0);
     long num2 = 0L;
     long num3 = 0L;
     byte[] buffer = new byte[((int) num9) + 1];
     byte[] bytes = new byte[0x15];
     while (true)
     {
         if (this.IsFileCleared(strArray[(int) num2]))
         {
             this.FileHandling = File.Open(strArray[(int) num2], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
             if (GenerateVerbose)
             {
                 Interaction.MsgBox("Current File: " + strArray[(int) num2] + "\n File offset for Piece 0 of this file: " + Conversions.ToString(num3), MsgBoxStyle.OkOnly, null);
             }
             break;
         }
         num2 += 1L;
     }
     Label_062B:
     Thread.Sleep(10);
     Application.DoEvents();
     this.TorrentProgress.Value = (int) Math.Round((double) ((((double) num3) / ((double) num12)) * 100.0));
     byte[] buffer4 = new byte[((int) (num9 - 1L)) + 1];
     Label_0668:
     num6 = this.FileHandling.Read(buffer4, (int) num8, (int) (num9 - num8));
     num8 += num6;
     if (!((num2 <= upperBound) & (num8 < num9)))
     {
         string str3 = "";
         byte[] buffer5 = new byte[((int) (num8 - 1L)) + 1];
         long num27 = num8 - 1L;
         for (long i = 0L; i <= num27; i += 1L)
         {
             buffer5[(int) i] = buffer4[(int) i];
         }
         buffer4 = null;
         bytes = this.sha1.ComputeHash(buffer5);
         int num17 = 0;
         do
         {
             str3 = str3 + Encoding.Default.GetString(bytes, num17, 1);
             num17++;
         }
         while (num17 <= 0x13);
         bytes = null;
         num3 += num8;
         num8 = 0L;
         GC.Collect();
         if (num3 >= num12)
         {
             this.FileHandling.Close();
             if (GenerateVerbose)
             {
                 Interaction.MsgBox("Size of files hashed: " + Conversions.ToString(num3) + " Size of files compared: " + Conversions.ToString(num12) + "\nNow Generating .torrent file", MsgBoxStyle.OkOnly, null);
             }
             this.TorrentProgress.Value = 100;
             string path = Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1) + ".torrent";
             TorrentString str9 = new TorrentString {
                 Value = str3
             };
             dictionary2.Add("pieces", str9);
             int num5 = Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1).LastIndexOf(@"\");
             int num4 = Strings.Len(this.FileNameToMake.Text) - num5;
             string str8 = Strings.Right(Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1), num4 - 2);
             TorrentString str7 = new TorrentString {
                 Value = str8
             };
             TorrentDictionary dictionary = new TorrentDictionary();
             TorrentString str4 = new TorrentString();
             dictionary2.Add("name", str7);
             str4.Value = this.AnnounceURL.Text;
             if (UseWSAConfig)
             {
                 ArrayList returnarray = new ArrayList();
                 TorrentList list6 = new TorrentList();
                 int webSeedData = TorrentGenFamily.GetWebSeedData(returnarray);
                 list6.Value = returnarray;
                 if (webSeedData >= 1)
                 {
                     dictionary.Add("httpseeds", list6);
                 }
             }
             TorrentString str2 = new TorrentString {
                 Value = "Torrent Generated by VB.Net TorrentGen - Written by DWKnight"
             };
             dictionary.Add("created by", str2);
             TorrentString str = new TorrentString();
             if (Strings.Trim(this.TorrentComment.Text) != "")
             {
                 str.Value = Strings.Trim(this.TorrentComment.Text);
                 dictionary.Add("comment", str);
             }
             if (this.AnnounceURL.Text != "")
             {
                 dictionary.Add("announce", str4);
             }
             if (this.PrivateTorrent.Checked)
             {
                 TorrentNumber number3 = new TorrentNumber {
                     Value = 1L
                 };
                 dictionary2["private"] = number3;
             }
             dictionary.Add("info", dictionary2);
             TorrentString str5 = new TorrentString {
                 Value = "UTF8"
             };
             dictionary.Add("encoding", str5);
             if (this.MultiTrackerEnabled.Checked)
             {
                 this.CheckMultitTrackerTiers();
                 dictionary.Add("announce-list", MultiTrackerGenerator.MultiTrackerTiers);
             }
             if (File.Exists(path))
             {
                 FileSystem.Kill(path);
             }
             int fileNumber = FileSystem.FreeFile();
             FileSystem.FileOpen(fileNumber, path, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1);
             FileSystem.FilePut(fileNumber, dictionary.BEncoded, -1L, false);
             FileSystem.FileClose(new int[] { fileNumber });
             GC.Collect();
             if (this.MakeExternals.Checked)
             {
                 string str26 = "";
                 string str28 = "";
                 string str29 = "";
                 string str30 = "";
                 string str32 = "";
                 string str34 = "";
                 IEnumerator enumerator2 = null;
                 string expression = Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1);
                 string str27 = expression + ".md5";
                 string str31 = expression + ".sha1";
                 string str25 = expression + ".ed2k";
                 string str33 = expression + ".tiger";
                 string[] strArray2 = Strings.Split(expression, @"\", -1, CompareMethod.Binary);
                 strArray2[strArray2.GetUpperBound(0)] = Strings.Replace(strArray2[strArray2.GetUpperBound(0)], " ", ".", 1, -1, CompareMethod.Binary);
                 strArray2[strArray2.GetUpperBound(0)] = Strings.Replace(strArray2[strArray2.GetUpperBound(0)], "_", ".", 1, -1, CompareMethod.Binary);
                 foreach (string str35 in strArray2)
                 {
                     str29 = str29 + @"\" + str35;
                 }
                 str29 = Strings.Mid(str29, 2, Strings.Len(str29) - 1) + ".sfv";
                 LinkGeneration generation = new LinkGeneration();
                 HashChanger changer2 = new HashChanger();
                 try
                 {
                     enumerator2 = list2.GetEnumerator();
                     while (enumerator2.MoveNext())
                     {
                         IEnumerator enumerator3 = null;
                         TorrentDictionary current = (TorrentDictionary) enumerator2.Current;
                         generation = new LinkGeneration();
                         TorrentString str36 = new TorrentString();
                         try
                         {
                             enumerator3 = ((IEnumerable) NewLateBinding.LateGet(current["path"], null, "value", new object[0], null, null, null)).GetEnumerator();
                             while (enumerator3.MoveNext())
                             {
                                 TorrentString str37 = (TorrentString) enumerator3.Current;
                                 str36 = str37;
                             }
                         }
                         finally
                         {
                             if (enumerator3 is IDisposable)
                             {
                                 (enumerator3 as IDisposable).Dispose();
                             }
                         }
                         if (this.IncludeMD5.Checked)
                         {
                             TorrentString str38 = new TorrentString();
                             str38 = (TorrentString) current["md5sum"];
                             str28 = str28 + str36.Value + " " + str38.Value + "\r\n";
                         }
                         if (this.IncludeSHA1.Checked)
                         {
                             changer2 = new HashChanger {
                                 rawhash = Conversions.ToString(NewLateBinding.LateGet(current["sha1"], null, "value", new object[0], null, null, null))
                             };
                             str32 = str32 + str36.Value + " " + changer2.hexhash + "\r\n";
                         }
                         if (this.IncludeTiger.Checked && current.Contains("tiger"))
                         {
                             changer2 = new HashChanger {
                                 rawhash = Conversions.ToString(NewLateBinding.LateGet(current["tiger"], null, "value", new object[0], null, null, null))
                             };
                             str34 = str34 + str36.Value + " " + changer2.base32 + "\r\n";
                         }
                         if (this.IncludeCRC32.Checked)
                         {
                             str30 = Conversions.ToString(Operators.AddObject(Operators.AddObject(Operators.AddObject(str30 + str36.Value + " ", NewLateBinding.LateGet(current["crc32"], null, "value", new object[0], null, null, null)), '\r'), '\n'));
                         }
                         if (this.IncludeED2K.Checked)
                         {
                             generation.ED2KRaw = Conversions.ToString(NewLateBinding.LateGet(current["ed2k"], null, "Value", new object[0], null, null, null));
                             generation.FileSize = Conversions.ToLong(NewLateBinding.LateGet(current["length"], null, "Value", new object[0], null, null, null));
                             generation.FileName = str36.Value;
                             str26 = str26 + generation.ClassicED2KLink + "\r\n";
                             str26 = str26 + str36.Value + " " + generation.ED2KHex + "\r\n";
                         }
                         GC.Collect();
                     }
                 }
                 finally
                 {
                     if (enumerator2 is IDisposable)
                     {
                         (enumerator2 as IDisposable).Dispose();
                     }
                 }
                 if (this.IncludeMD5.Checked)
                 {
                     if (File.Exists(str27))
                     {
                         FileSystem.Kill(str27);
                     }
                     int num19 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num19, str27, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num19, new object[] { str28 });
                     FileSystem.FileClose(new int[] { num19 });
                 }
                 if (this.IncludeTiger.Checked)
                 {
                     if (File.Exists(str33))
                     {
                         FileSystem.Kill(str33);
                     }
                     int num20 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num20, str33, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num20, new object[] { str34 });
                     FileSystem.FileClose(new int[] { num20 });
                 }
                 if (this.IncludeSHA1.Checked)
                 {
                     if (File.Exists(str31))
                     {
                         FileSystem.Kill(str31);
                     }
                     int num21 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num21, str31, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num21, new object[] { str32 });
                     FileSystem.FileClose(new int[] { num21 });
                 }
                 if (this.IncludeED2K.Checked)
                 {
                     if (File.Exists(str25))
                     {
                         FileSystem.Kill(str25);
                     }
                     int num22 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num22, str25, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num22, new object[] { str26 });
                     FileSystem.FileClose(new int[] { num22 });
                 }
                 if (this.IncludeCRC32.Checked)
                 {
                     if (File.Exists(str29))
                     {
                         FileSystem.Kill(str29);
                     }
                     int num23 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num23, str29, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num23, new object[] { str30 });
                     FileSystem.FileClose(new int[] { num23 });
                 }
             }
             GC.Collect();
             return;
         }
         goto Label_062B;
     }
     num2 += 1L;
     while (true)
     {
         if (num2 > strArray.GetUpperBound(0))
         {
             goto Label_0668;
         }
         if (this.IsFileCleared(strArray[(int) num2]))
         {
             break;
         }
         num2 += 1L;
     }
     this.FileHandling.Close();
     this.FileHandling = File.Open(strArray[(int) num2], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     if (GenerateVerbose)
     {
         Interaction.MsgBox("Current File: " + strArray[(int) num2] + "\n File offset for Piece 0 of this file: " + Conversions.ToString(num3), MsgBoxStyle.OkOnly, null);
     }
     goto Label_0668;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Creates continuation instance of get list request query command.
 /// </summary>
 /// <param name="list">List object, on which conntinuation request will be based.</param>
 public TorrentListQueryCommand(TorrentList list)
     : base(ListQuery, CommandType.List, 
         new KeyValuePair<string, string>("cid",list.CacheId.ToString()))
 {
     ContinuationListIdentity = list.CacheId;
 }
Ejemplo n.º 26
0
 private void SaveSettings_Click(object sender, EventArgs e)
 {
     this.AnnounceURL.Text = Strings.Trim(this.AnnounceURL.Text);
     TorrentString str = new TorrentString();
     TorrentNumber number3 = new TorrentNumber();
     TorrentNumber number11 = new TorrentNumber();
     TorrentNumber number9 = new TorrentNumber();
     TorrentNumber number7 = new TorrentNumber();
     TorrentNumber number8 = new TorrentNumber();
     TorrentNumber number12 = new TorrentNumber();
     TorrentNumber number6 = new TorrentNumber();
     TorrentNumber number = new TorrentNumber();
     TorrentNumber number5 = new TorrentNumber();
     TorrentDictionary dictionary = new TorrentDictionary();
     TorrentNumber number14 = new TorrentNumber();
     TorrentNumber number13 = new TorrentNumber();
     TorrentNumber number4 = new TorrentNumber();
     TorrentList list = new TorrentList();
     TorrentString str2 = new TorrentString();
     TorrentNumber number10 = new TorrentNumber();
     list.Value = BlackListedFiles;
     number14.Value = (long) -(Convert.ToInt32(GenerateVerbose));
     number13.Value = (long) -(Convert.ToInt32(UseWSAConfig));
     number4.Value = (long) -(Convert.ToInt32(DelayMessages));
     dictionary.Add("verbose", number14);
     dictionary.Add("usewsa", number13);
     dictionary.Add("delay", number4);
     str.Value = this.AnnounceURL.Text;
     number3.Value = Conversions.ToInteger(this.PieceSize.Text);
     number5.Value = (long) -(Convert.ToInt32(this.MakeSeparateTorrents.Checked));
     number11.Value = (long) -(Convert.ToInt32(this.IncludeSHA1.Checked));
     number9.Value = (long) -(Convert.ToInt32(this.IncludeMD5.Checked));
     number7.Value = (long) -(Convert.ToInt32(this.IncludeCRC32.Checked));
     number8.Value = (long) -(Convert.ToInt32(this.IncludeED2K.Checked));
     number12.Value = (long) -(Convert.ToInt32(this.IncludeTiger.Checked));
     number6.Value = (long) -(Convert.ToInt32(this.MakeExternals.Checked));
     number.Value = (long) -(Convert.ToInt32(this.AutomaticPieceSize.Checked));
     str2.Value = Strings.Trim(this.TorrentComment.Text);
     number10.Value = (long)-(Convert.ToInt32(this.MultiTrackerEnabled.Checked));
     TorrentDictionary dictionary2 = new TorrentDictionary();
     TorrentNumber number2 = new TorrentNumber();
     TorrentList list2 = new TorrentList {
         Value = new ArrayList()
     };
     if (list.BEncoded != list2.BEncoded)
     {
         dictionary2.Add("blacklist", list);
         number2.Value = 0L;
     }
     else
     {
         number2.Value = -1L;
     }
     if (MultiTrackerGenerator.MultiTrackerTiers.BEncoded != list2.BEncoded)
     {
         this.CheckMultitTrackerTiers();
         dictionary2.Add("multitracker", MultiTrackerGenerator.MultiTrackerTiers);
     }
     dictionary2.Add("usemultitracker", number10);
     dictionary2.Add("blankblacklist", number2);
     dictionary2.Add("advanced", dictionary);
     dictionary2.Add("tracker", str);
     dictionary2.Add("piecesize", number3);
     dictionary2.Add("sha1", number11);
     dictionary2.Add("md5", number9);
     dictionary2.Add("crc", number7);
     dictionary2.Add("ed2k", number8);
     dictionary2.Add("tiger", number12);
     dictionary2.Add("externals", number6);
     dictionary2.Add("autopiece", number);
     dictionary2.Add("folder", number5);
     dictionary2.Add("comment", str2);
     int fileNumber = FileSystem.FreeFile();
     if (File.Exists(LocalPath + "tgen.configure"))
     {
         FileSystem.Kill(LocalPath + "tgen.configure");
     }
     FileSystem.FileOpen(fileNumber, LocalPath + "tgen.configure", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1);
     FileSystem.FilePut(fileNumber, dictionary2.BEncoded, -1L, false);
     FileSystem.FileClose(new int[] { fileNumber });
     GC.Collect();
 }