Giter VIP home page Giter VIP logo

Comments (1)

scorpionsFC avatar scorpionsFC commented on May 28, 2024
    public async Task CreateAsync(CancellationToken token, string torrentsPath, string downloadsPath)
    {
        try
        {
            DAPLauncher.MainWindow targetWindow = System.Windows.Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is DAPLauncher.MainWindow) as DAPLauncher.MainWindow;
            targetWindow.file_local.Content = "1. Created Torrent File : " + torrentsPath;

            int CountF = 0;
            ViewModel._orders.Clear();
            DirectoryInfo dir = new(downloadsPath);
            Files = dir.GetFiles("*", SearchOption.AllDirectories);
            for (int fcount = 0; fcount < Files.Length; fcount++)
            {
                CountF++;
            }
            targetWindow.progressload.Maximum = CountF + 1;
            string pubIp = new WebClient().DownloadString("https://api.ipify.org");
            TorrentType torrentType = TorrentType.V1Only;
            if (bCheckV1Only)
            {
                 torrentType = TorrentType.V1Only;
            }
            if (bCheckV1OnlyWithPaddingFiles)
            {
                torrentType = TorrentType.V1OnlyWithPaddingFiles;
            }
            if (bCheckV2Only)
            {
                torrentType = TorrentType.V2Only;
            }
            if (bCheckV1V2Hybrid)
            {
                torrentType = TorrentType.V1V2Hybrid;
            }

            Factories factories = new()
            {
            };

            TorrentCreator torrentCreator = new(torrentType, factories);

            TorrentFileSource torrentFileSource = new(downloadsPath)
            {
                TorrentName = Path.GetFileName(torrentsPath).Replace(".torrent", string.Empty)
            };


            torrentCreator.Hashed += async delegate (object o, TorrentCreatorEventArgs e)
            {
                targetWindow.md5local.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                {
                    targetWindow.md5local.Content = e.CurrentFile + "[FileSize : " + TotalFile(e.FileSize) + "/ FileBytesHashed : " + TotalFile(e.FileBytesHashed) + "]FileCompletion : " + e.FileCompletion;
                    if (e.FileCompletion == 1.0)
                    {
                        targetWindow.progressload.Value++;
                        ViewModel._orders.Add(new TorrentFileEntity
                        {
                            Name = Path.GetFileName(e.CurrentFile),
                            Path = e.CurrentFile,
                            Size = TotalFile(e.FileSize),
                            PriorityText = "",
                            ProgressText = string.Format("{0:0.00}%", e.FileCompletion),
                            Progress = 100
                        });
                        targetWindow.DataGFileTorrent.ItemsSource = ViewModel._orders;
                    }
                }));
                StatusMessage?.Invoke(this, $"" + "DownloadAsync," + e.CurrentFile + "[FileSize : " + TotalFile(e.FileSize) + "/ FileBytesHashed : " + TotalFile(e.FileBytesHashed) + "]FileCompletion : " + e.FileCompletion);
                await Task.Delay(500, token);
            };
            StatusMessage?.Invoke(this, $"" + "Engine," + Path.GetFileName(torrentsPath).Replace(".torrent", string.Empty));
            torrentCreator.Announces.Add(new List<string>());
            try
            {
                torrentCreator.Announces[0].Add("http://" + pubIp + ":" + PortTrackerhttp + "/announce");
                torrentCreator.Announces[0].Add("udp://" + pubIp + ":" + PortTrackerudp + "/announce");
                for (int pBName = 0; pBName < ListTrackers.Count; pBName++)
                {
                    torrentCreator.Announces[0].Add(ListTrackers[pBName].Tracker);
                }
            }
            catch (Exception ex) { System.Windows.MessageBox.Show("ADD TRACKERS : " + ex.Message); }
            torrentCreator.Comment = "ServerManager[SM]";
            torrentCreator.Publisher = "https://discord.com/invite/ZTJTRpb9TF";
            await torrentCreator.CreateAsync(torrentFileSource, torrentsPath, token);
            await Task.Delay(1000, token);
            ViewModel._orders.Clear();
            targetWindow.DataGFileTorrent.ItemsSource = ViewModel._orders;
            targetWindow.RLogTorrent.Document.Blocks.Clear();
            targetWindow.RichLogFirst.Document.Blocks.Clear();
            TorrentCreatOrDownloading = false;
            Thread FileSearch = new(new ThreadStart(targetWindow.StartHeSH))
            {
                IsBackground = true
            };
            FileSearch.Start();
        }
        catch (Exception ex) { System.Windows.MessageBox.Show("CreateAsync : " + ex.Message); }
    }

from monotorrent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.