示例#1
0
文件: fomod.cs 项目: BioBrainX/fomm
 /// <summary>
 /// Fills in missing info about the mod from the given info.
 /// </summary>
 /// <param name="p_mifInfo">A <see cref="ModInfo"/> describing the info of the mod.</param>
 public void SetMissingInfo(ModInfo p_mifInfo)
 {
     if (p_mifInfo == null)
         return;
     bool booUpdated = false;
     if (ModName.Equals(Path.GetFileNameWithoutExtension(filepath)) && !String.IsNullOrEmpty(p_mifInfo.ModName))
     {
         booUpdated = true;
         ModName = p_mifInfo.ModName;
     }
     if (DEFAULT_AUTHOR.Equals(Author) && !String.IsNullOrEmpty(p_mifInfo.Author))
     {
         booUpdated = true;
         Author = p_mifInfo.Author;
     }
     if (HumanReadableVersion.Equals(DEFAULT_VERSION) && (MachineVersion == DefaultVersion) && !String.IsNullOrEmpty(p_mifInfo.Version.ToString()))
     {
         HumanReadableVersion = p_mifInfo.Version.ToString();
         string strVersionString = p_mifInfo.Version.ToString();
         Regex rgxCleanVersion = new Regex(@"[^\d\.]");
         strVersionString = rgxCleanVersion.Replace(strVersionString, "");
         if (!String.IsNullOrEmpty(strVersionString))
         {
             if (!strVersionString.Contains("."))
                 strVersionString += ".0";
             if (strVersionString.StartsWith("."))
                 strVersionString = "0" + strVersionString;
             if (strVersionString.EndsWith("."))
                 strVersionString = strVersionString + "0";
             MachineVersion = new Version(strVersionString);
         }
     }
     if (!HasScreenshot && (p_mifInfo.Screenshot != null))
         booUpdated = true;
     if (String.IsNullOrEmpty(Website) && (p_mifInfo.URL != null))
     {
         booUpdated = true;
         Website = p_mifInfo.URL.ToString();
     }
     if (booUpdated)
         CommitInfo((p_mifInfo.Screenshot != null), p_mifInfo.Screenshot);
 }
示例#2
0
		/// <summary>
		/// Calls the callback method for <see cref="GetVersionAsync"/>.
		/// </summary>
		/// <param name="p_kvpCallback">An object whose key is the callback method to call and whose value is the user-supplied state info to pass to the callback method.</param>
		/// <param name="p_mifInfo">The info of the mod that was retrieved in the asynchronous call.</param>
		private void CallGetFileVersionAsyncCallback(KeyValuePair<Action<object, ModInfo>, object> p_kvpCallback, ModInfo p_mifInfo)
		{
			if (p_kvpCallback.Key != null)
				p_kvpCallback.Key(p_kvpCallback.Value, p_mifInfo);
		}
示例#3
0
文件: fomod.cs 项目: IntegralLee/fomm
    /// <summary>
    ///   Fills in missing info about the mod from the given info.
    /// </summary>
    /// <param name="p_mifInfo">A <see cref="ModInfo" /> describing the info of the mod.</param>
    public void SetMissingInfo(ModInfo p_mifInfo)
    {
      Version mv = null;

      if (p_mifInfo == null)
      {
        return;
      }
      var booUpdated = false;
      if (ModName.Equals(Path.GetFileNameWithoutExtension(filepath)) && !String.IsNullOrEmpty(p_mifInfo.ModName))
      {
        booUpdated = true;
        ModName = p_mifInfo.ModName;
      }
      if (DEFAULT_AUTHOR.Equals(Author) && !String.IsNullOrEmpty(p_mifInfo.Author))
      {
        booUpdated = true;
        Author = p_mifInfo.Author;
      }

      if (HumanReadableVersion.Equals(DEFAULT_VERSION) && (MachineVersion == DefaultVersion) &&
          !String.IsNullOrEmpty(p_mifInfo.Version))
      {
        HumanReadableVersion = p_mifInfo.Version;
        var strVersionString = p_mifInfo.Version;
        var rgxCleanVersion = new Regex(@"[^\d\.]");
        strVersionString = rgxCleanVersion.Replace(strVersionString, "");
        if (String.IsNullOrEmpty(strVersionString))
        {
          strVersionString = "0.0.0.0";
        }

        if (Version.TryParse(strVersionString, out mv))
        {
          MachineVersion = mv;
        }
      }

      if (!HasScreenshot && (p_mifInfo.Screenshot != null))
      {
        booUpdated = true;
      }

      if (String.IsNullOrEmpty(Website) && (p_mifInfo.URL != null))
      {
        booUpdated = true;
        Website = p_mifInfo.URL.ToString();
      }
      if (booUpdated)
      {
        CommitInfo((p_mifInfo.Screenshot != null), p_mifInfo.Screenshot);
      }
    }
示例#4
0
		/// <summary>
		/// Handles the callback of the http request that retrieves the file page when
		/// getting a file version.
		/// </summary>
		/// <remarks>
		/// This method parses the version out of the requested page and passes it to a user
		/// supplied method.
		/// </remarks>
		/// <param name="p_asrResult">The asynchronous result of the request for the file page.</param>
		private void GetFilePageCallback(IAsyncResult p_asrResult)
		{
			object[] objState = (object[])p_asrResult.AsyncState;
			HttpWebRequest hwrFilePage = (HttpWebRequest)objState[0];
			AsyncOperation aopOperation = (AsyncOperation)objState[1];
			bool booIncludeScreenshot = (bool)objState[2];

			string strFilePage = null;
			try
			{
				strFilePage = RetrievePageResponse(hwrFilePage.EndGetResponse(p_asrResult));
			}
			catch (Exception e)
			{
				strFilePage = "Error";
#if TRACE
				Trace.WriteLine("Problem parsing the version HTTP response from " + hwrFilePage.Address);
				Trace.Indent();
				Trace.WriteLine("Exception: ");
				Trace.WriteLine(e.Message);
				Trace.WriteLine(e.ToString());
				if (e.InnerException != null)
				{
					Trace.WriteLine("Inner Exception: ");
					Trace.WriteLine(e.InnerException.Message);
					Trace.WriteLine(e.InnerException.ToString());
				}
				Trace.Unindent();
				Trace.Flush();
#endif
			}

			ModInfo mifInfo = null;
			if (!"Error".Equals(strFilePage))
				mifInfo = ParseModInfo(hwrFilePage.RequestUri, strFilePage, booIncludeScreenshot);
			else
				mifInfo = new ModInfo("Error", "Error", "Error", hwrFilePage.RequestUri, null);

			aopOperation.PostOperationCompleted((p_mifInfo) => { CallGetFileVersionAsyncCallback((KeyValuePair<Action<object, ModInfo>, object>)aopOperation.UserSuppliedState, (ModInfo)p_mifInfo); }, mifInfo);
		}
示例#5
0
        /// <summary>
        /// The callback method for the call to retrieve a mod version from the Nexus website.
        /// </summary>
        /// <param name="p_objState">The base name of the mod whose version has been retrieved.</param>
        /// <param name="p_mifWebModInfo">The info of the mod on the Nexus website.</param>
        private void Nexus_GotFileVersion(object p_objState, ModInfo p_mifWebModInfo)
        {
            if (!this.Visible)
                return;
            m_dicWebVersions[(string)p_objState] = p_mifWebModInfo.Version.ToString();
            ListViewItem lviMod = lvModList.Items[(string)p_objState];
            lviMod.UseItemStyleForSubItems = false;
            if (!String.IsNullOrEmpty(p_mifWebModInfo.Version.ToString()) && !p_mifWebModInfo.Version.Equals(lviMod.SubItems["WebVersion"].Text))
            {
                lviMod.SubItems["WebVersion"].Text = p_mifWebModInfo.Version.ToString();
                string strWebVersion = p_mifWebModInfo.Version.ToString();

                ModVersion ver = ModVersion.Parse(strWebVersion);

                string strVersion = ((fomod)lviMod.Tag).HumanReadableVersion;
                if (!strWebVersion.Equals(strVersion))
                {
                    lviMod.SubItems["WebVersion"].BackColor = Color.LightSalmon;
                }
            }
        }