コード例 #1
0
        public TorrentUpdater(string torrentLink, DayZInstaller installer, DayZUpdater updater)
        {
            this.installer = installer;
            this.updater = updater;
            torrents = new List<TorrentManager>();							// This is where we will store the torrentmanagers

            if (!Directory.Exists(torrentsPath))
                Directory.CreateDirectory(torrentsPath);
            else
            {
                Directory.Delete(torrentsPath, true); // Delete old torrents
                Directory.CreateDirectory(torrentsPath);
            }

            ExtendedWebClient wc = new ExtendedWebClient(new Uri(torrentLink));
            try
            {
                var torrentLinks = torrentLink.Split(';');
                int i = 1;
                foreach (string torrent in torrentLinks)
                {
                    wc.DownloadFile(torrent, Path.Combine(torrentsPath, "DayZero-" + updater.LatestVersion + "-" + i + ".torrent"));
                    i++;
                }
            }
            catch (Exception)
            {
                updater.Status = "Could not download torrent.";
                CalculatedGameSettings.Current.Update();
                installer.Status = "";
                installer.IsRunning = false;
                return;
            }

            // We need to cleanup correctly when the user closes the window by using ctrl-c
            // or an unhandled exception happens
            Console.CancelKeyPress += delegate { shutdown(); };
            AppDomain.CurrentDomain.ProcessExit += delegate { shutdown(); };
            AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.ExceptionObject); shutdown(); };
            Thread.GetDomain().UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.ExceptionObject); shutdown(); };
        }
コード例 #2
0
        public TorrentUpdater(string torrentLink)
        {
            torrents = new List<TorrentManager>();							// This is where we will store the torrentmanagers
            // If the torrentsPath does not exist, we want to create it
            if (!Directory.Exists(torrentsPath))
                Directory.CreateDirectory(torrentsPath);
            else
            {
                Directory.Delete(torrentsPath, true); // Delete old torrents
                Directory.CreateDirectory(torrentsPath);
            }

            ExtendedWebClient wc = new ExtendedWebClient(new Uri(torrentLink));
            try
            {
                var torrentLinks = torrentLink.Split(';');
                int i = 1;
                foreach (string torrent in torrentLinks)
                {
                    wc.DownloadFile(torrent, Path.Combine(torrentsPath, "DayZero-" + i + ".torrent"));
                    i++;
                }
            }
            catch (Exception)
            {
                return;
            }

            // We need to cleanup correctly when the user closes the window by using ctrl-c
            // or an unhandled exception happens
            Console.CancelKeyPress += delegate { shutdown(); };
            AppDomain.CurrentDomain.ProcessExit += delegate { shutdown(); };
            AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.ExceptionObject); shutdown(); };
            Thread.GetDomain().UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.ExceptionObject); shutdown(); };
        }