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(); }; }
public void StartFromContentFile(string versionString, bool forceFullSystemsCheck, DayZUpdater updater) { if (string.IsNullOrWhiteSpace(versionString)) return; string metaJsonFilename = MetaModDetails.GetFileName(versionString); if (!File.Exists(metaJsonFilename)) return; if (IsRunning) { if (_updatingVersion.Equals(versionString, StringComparison.OrdinalIgnoreCase)) return; //already running for this same version } _updatingVersion = versionString; Status = "Loading from local index..."; ContinueFromContentFile(versionString, metaJsonFilename, forceFullSystemsCheck, updater, true); }
public void DownloadAndInstall(string latestDownloadUrl, string deletedFilesUrl, DayZUpdater updater) { _latestDownloadUrl = latestDownloadUrl; _deletedFilesUrl = deletedFilesUrl; if(string.IsNullOrEmpty(CalculatedGameSettings.Current.DayZPath) || string.IsNullOrEmpty(_latestDownloadUrl)) { return; } CalculatedGameSettings.Current.DayZPath.MakeSurePathExists(); IsRunning = true; updater.Status = DayZeroLauncherUpdater.STATUS_DOWNLOADING; Status = "Initiating Download .."; System.Threading.Tasks.Task.Factory.StartNew(() => GetDayZFiles(updater)); }
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(); }; }
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; } } }
private void GetDayZFiles(DayZUpdater updater) { TorrentUpdater tu = new TorrentUpdater(_latestDownloadUrl, this, updater); tu.StartTorrents(1000); }
public void DownloadAndInstall(string latestDownloadUrl, string deletedFilesUrl, DayZUpdater updater) { _latestDownloadUrl = latestDownloadUrl; _deletedFilesUrl = deletedFilesUrl; if (string.IsNullOrEmpty(CalculatedGameSettings.Current.DayZPath) || string.IsNullOrEmpty(_latestDownloadUrl)) { return; } CalculatedGameSettings.Current.DayZPath.MakeSurePathExists(); IsRunning = true; updater.Status = DayZeroLauncherUpdater.STATUS_DOWNLOADING; Status = "Initiating Download .."; System.Threading.Tasks.Task.Factory.StartNew(() => GetDayZFiles(updater)); }
private void ContinueFromContentFile(string versionString, string metaJsonFilename, bool forceFullSystemsCheck, DayZUpdater updater, bool errorMsgsOnly) { MetaModDetails modDetails = null; bool fullSystemCheck = true; try { modDetails = MetaModDetails.LoadFromFile(metaJsonFilename); if (!forceFullSystemsCheck) { CalculatedGameSettings.Current.Update(); if (versionString.Equals(CalculatedGameSettings.Current.ModContentVersion, StringComparison.OrdinalIgnoreCase)) fullSystemCheck = false; } } catch (Exception ex) { updater.Status = "Error parsing content index file"; Status = ex.Message; IsRunning = false; _gameLauncher.SetModDetails(null, false, ex); } //start new torrents if needed if (modDetails != null) { _gameLauncher.SetModDetails(modDetails); //stop existing torrents going on if (_torrentUpdater != null) { TorrentUpdater.StopAllTorrents(); _torrentUpdater = null; } _torrentUpdater = new TorrentUpdater(versionString, modDetails.AddOns, fullSystemCheck, this, updater, errorMsgsOnly); //this automatically starts it's async thread } }
public void StartFromNetContent(string versionString, bool forceFullSystemsCheck, HashWebClient.RemoteFileInfo jsonIndex, DayZUpdater updater, bool errorMsgsOnly = false) { if (jsonIndex == null) { MessageBox.Show("No version index specified, please Check first.", "Error initiating torrent download", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (string.IsNullOrWhiteSpace(versionString)) { MessageBox.Show("Invalid version specified for download", "Error initiating torrent download", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (IsRunning) { if (_updatingVersion.Equals(versionString, StringComparison.OrdinalIgnoreCase)) return; //already running for this same version } _updatingVersion = versionString; if (!errorMsgsOnly) updater.Status = DayZeroLauncherUpdater.STATUS_DOWNLOADING; Status = "Initiating Download..."; string metaJsonFilename = MetaModDetails.GetFileName(versionString); var wc = new HashWebClient(); wc.DownloadFileCompleted += (sender, args) => { if (args.Cancelled) { Status = updater.Status = "Async operation cancelled"; IsRunning = false; _gameLauncher.SetModDetails(null, true, null); } else if (args.Error != null) { updater.Status = "Error downloading content index file"; Status = args.Error.Message; IsRunning = false; _gameLauncher.SetModDetails(null, false, args.Error); } else ContinueFromContentFile(versionString, metaJsonFilename, forceFullSystemsCheck, updater, errorMsgsOnly); }; wc.BeginDownload(jsonIndex, metaJsonFilename); }