Represents an NXM url.
This is a convenice class that parses out parts of the URL that are of interest.
Inheritance: System.Uri
Exemplo n.º 1
0
		/// <summary>
		/// Build the obejct that describes the mod being added.
		/// </summary>
		/// <param name="p_uriPath">The path of the mod being added.</param>
		/// <returns>The obejct that describes the mod being added.</returns>
		private AddModDescriptor BuildDescriptor(Uri p_uriPath)
		{
			if (!m_eifEnvironmentInfo.Settings.QueuedModsToAdd.ContainsKey(m_gmdGameMode.ModeId))
				m_eifEnvironmentInfo.Settings.QueuedModsToAdd[m_gmdGameMode.ModeId] = new KeyedSettings<AddModDescriptor>();
			KeyedSettings<AddModDescriptor> dicQueuedMods = m_eifEnvironmentInfo.Settings.QueuedModsToAdd[m_gmdGameMode.ModeId];
			AddModDescriptor amdDescriptor = null;

			if ((p_uriPath.Scheme.ToLowerInvariant()) == "file")
			{
				if (dicQueuedMods.TryGetValue(p_uriPath.ToString(), out amdDescriptor))
					m_strFileserverCaptions = amdDescriptor.SourceName;
				else
				{
					amdDescriptor = new AddModDescriptor(p_uriPath, p_uriPath.LocalPath, null, TaskStatus.Running, new List<string>());
					dicQueuedMods[p_uriPath.ToString()] = amdDescriptor;
					lock (m_eifEnvironmentInfo.Settings)
						m_eifEnvironmentInfo.Settings.Save();
				}
			}
			else if (m_mrpModRepository.IsOffline)
			{
				if (dicQueuedMods.TryGetValue(p_uriPath.ToString(), out amdDescriptor))
					m_strFileserverCaptions = amdDescriptor.SourceName;
			}
			else
			{
				if (dicQueuedMods.ContainsKey(p_uriPath.ToString()))
					dicQueuedMods.Remove(p_uriPath.ToString());
				if (m_strFileserverCaptions.Count > 0)
					m_strFileserverCaptions.Clear();

				switch (p_uriPath.Scheme.ToLowerInvariant())
				{
					case "nxm":
						NexusUrl nxuModUrl = new NexusUrl(p_uriPath);

						if (String.IsNullOrEmpty(nxuModUrl.ModId))
						{
							Trace.TraceError("Invalid Nexus URI: " + p_uriPath.ToString());
							return null;
						}

						IModFileInfo mfiFile = null;
						List<FileserverInfo> lstFileServerInfo = new List<FileserverInfo>();
						List<Uri> uriFilesToDownload = new List<Uri>();
						try
						{
							if (String.IsNullOrEmpty(nxuModUrl.FileId))
								mfiFile = m_mrpModRepository.GetDefaultFileInfo(nxuModUrl.ModId);
							else
								mfiFile = m_mrpModRepository.GetFileInfo(nxuModUrl.ModId, nxuModUrl.FileId);
							if (mfiFile == null)
							{
								Trace.TraceInformation(String.Format("[{0}] Can't get the file: no file.", p_uriPath.ToString()));
								return null;
							}
							string strRepositoryMessage;
							lstFileServerInfo = m_mrpModRepository.GetFilePartInfo(nxuModUrl.ModId, mfiFile.Id.ToString(), m_eifEnvironmentInfo.Settings.UserLocation, out strRepositoryMessage);
							if (lstFileServerInfo.Count > 0)
							{
								foreach (FileserverInfo fsiFileServer in lstFileServerInfo)
									if (!String.IsNullOrEmpty(fsiFileServer.DownloadLink))
									{
										uriFilesToDownload.Add(new Uri(fsiFileServer.DownloadLink));
										m_strFileserverCaptions.Add(fsiFileServer.Name);
									}
								if (!String.IsNullOrEmpty(strRepositoryMessage))
									m_strRepositoryMessage = strRepositoryMessage;
							}
						}
						catch (RepositoryUnavailableException e)
						{
							TraceUtil.TraceException(e);
							return null;
						}

						if ((uriFilesToDownload == null) || (uriFilesToDownload.Count <= 0))
							return null;
						string strSourcePath = Path.Combine(m_gmdGameMode.GameModeEnvironmentInfo.ModDownloadCacheDirectory, mfiFile.Filename);
						amdDescriptor = new AddModDescriptor(p_uriPath, strSourcePath, uriFilesToDownload, TaskStatus.Running, m_strFileserverCaptions);
						break;
					default:
						Trace.TraceInformation(String.Format("[{0}] Can't get the file.", p_uriPath.ToString()));
						throw new Exception("Unable to retrieve file: " + p_uriPath.ToString());
				}
				dicQueuedMods[p_uriPath.ToString()] = amdDescriptor;
				lock (m_eifEnvironmentInfo.Settings)
					m_eifEnvironmentInfo.Settings.Save();
			}

			return amdDescriptor;
		}
Exemplo n.º 2
0
		/// <summary>
		/// Get the reposiroty info for the described mod.
		/// </summary>
		/// <param name="p_amdDescriptor">The obejct that describes the mod for which to retrieve the info.</param>
		/// <returns>The repository info for the described mod.</returns>
		private IModInfo GetModInfo(AddModDescriptor p_amdDescriptor)
		{
			switch (p_amdDescriptor.SourceUri.Scheme.ToLowerInvariant())
			{
				case "file":
					try
					{
						return new ModInfo(m_mrpModRepository.GetModInfoForFile(Path.GetFileName(p_amdDescriptor.DefaultSourcePath)));
					}
					catch (RepositoryUnavailableException e)
					{
						TraceUtil.TraceException(e);
						return null;
					}
				case "nxm":
					NexusUrl nxuModUrl = new NexusUrl(p_amdDescriptor.SourceUri);
					if ((String.IsNullOrEmpty(nxuModUrl.ModId)) || (string.IsNullOrEmpty(nxuModUrl.FileId)))
						throw new ArgumentException("Invalid Nexus URI: " + p_amdDescriptor.SourceUri.ToString());
					ModInfo modInfo = null;

					try
					{
						if (!m_mrpModRepository.IsOffline)
						{
							modInfo = (ModInfo)m_mrpModRepository.GetModInfo(nxuModUrl.ModId);

							IMod modMod = m_mrgModRegistry.RegisteredMods.Find(x => x.Id == nxuModUrl.ModId);
							if ((modMod != null) && (modInfo != null))
							{
								modInfo.IsEndorsed = modMod.IsEndorsed;
								modInfo.UpdateWarningEnabled = modMod.UpdateWarningEnabled;
								modInfo.CustomCategoryId = modMod.CustomCategoryId;
							}

							IModFileInfo mfiFileInfo = m_mrpModRepository.GetFileInfo(nxuModUrl.ModId, nxuModUrl.FileId);
							if ((modInfo != null) && (mfiFileInfo != null))
								modInfo = (ModInfo)AutoTagger.CombineInfo(modInfo, mfiFileInfo);
						}
					}
					catch (RepositoryUnavailableException e)
					{
						TraceUtil.TraceException(e);
					}
					return modInfo;
				default:
					Trace.TraceInformation(String.Format("[{0}] Can't get mod info.", p_amdDescriptor.SourceUri.ToString()));
					throw new Exception("Unable to retrieve mod info: " + p_amdDescriptor.SourceUri.ToString());
			}
		}