Exemplo n.º 1
0
 public DayZUpdater(GameLauncher gameLauncher)
 {
     Downloader = new TorrentLauncher(gameLauncher);
     Downloader.PropertyChanged += (sender, args) =>
     {
         if (args.PropertyName == "IsRunning")
         {
             PropertyHasChanged("InstallButtonVisible");
         }
         else if (args.PropertyName == "Status")
         {
             if (Downloader.Status == DayZeroLauncherUpdater.STATUS_INSTALLCOMPLETE)
             {
                 CheckForUpdates(_lastModsJsonLoc);
             }
         }
     };
 }
Exemplo n.º 2
0
        public TorrentUpdater(string versionString, List<MetaAddon> addOns, bool fullSystemCheck, TorrentLauncher downloader,
			DayZUpdater updater, bool errorMsgsOnly)
        {
            addOnTorrents = new List<AddOnTorrent>();
            this.versionString = versionString;
            this.fullSystemCheck = fullSystemCheck;
            this.downloader = downloader;
            this.updater = updater;
            this.errorMsgsOnly = errorMsgsOnly;

            string torrentsDir = null;
            try
            {
                torrentsDir = Path.Combine(UserSettings.ContentMetaPath, versionString);
                {
                    var dirInfo = new DirectoryInfo(torrentsDir);
                    if (!dirInfo.Exists)
                        dirInfo = Directory.CreateDirectory(torrentsDir);
                }
            }
            catch (Exception ex)
            {
                updater.Status = "Error creating torrents directory";
                downloader.Status = ex.Message;
                downloader.IsRunning = false;

                return;
            }

            foreach (MetaAddon addOn in addOns)
            {
                var newAddOn = new AddOnTorrent();
                newAddOn.Meta = addOn;
                newAddOn.torrentFileName = Path.Combine(torrentsDir,
                    newAddOn.Meta.Description + "-" + newAddOn.Meta.Version + ".torrent");
                newAddOn.torrentSavePath = null; //will be filled in if successfull download
                addOnTorrents.Add(newAddOn);
            }

            //delete .torrent files that do not match the ones we want
            string[] allTorrents = Directory.GetFiles(torrentsDir, "*.torrent", SearchOption.TopDirectoryOnly);
            foreach (string torrentPath in allTorrents)
            {
                if (
                    addOnTorrents.Count(
                        naot => { return naot.torrentFileName.Equals(torrentPath, StringComparison.InvariantCultureIgnoreCase); }) < 1)
                {
                    //this is an unwanted torrent file
                    try
                    {
                        var fileInfo = new FileInfo(torrentPath);
                        if (fileInfo.IsReadOnly)
                        {
                            fileInfo.IsReadOnly = false;
                            fileInfo.Refresh();
                        }
                        fileInfo.Delete();
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            for (int i = 0; i < addOnTorrents.Count; i++)
            {
                int idxCopy = i;
                AddOnTorrent newAddOn = addOnTorrents[i];
                try
                {
                    var wc = new HashWebClient();
                    wc.DownloadFileCompleted += (sender, args) => { TorrentDownloadComplete(sender, args, idxCopy); };
                    wc.BeginDownload(newAddOn.Meta.Torrent, newAddOn.torrentFileName);
                }
                catch (Exception ex)
                {
                    updater.Status = "Error starting torrent file download";
                    downloader.Status = ex.Message;
                    downloader.IsRunning = false;
                    return;
                }
            }
        }