private static string GetOSName(OperatingSystem os)
        {
            Version version = os.Version;

            // perform simple detection of OS
            // TODO: more sophisticated detection; Windows 7 and Server 2008 have the same major/minor version number 
            string release;
            if (version.Major == 5 && version.Minor == 1)
                release = "XP";
            else if (version.Major == 5 && version.Minor == 2)
                release = "Server 2003";
            else if (version.Major == 6 && version.Minor == 0)
                release = "Vista";
            else if (version.Major == 6 && version.Minor == 1)
                release = "7";
            else if (version.Major == 6 && version.Minor == 2)
                release = "8";
            else if (version.Major == 6 && version.Minor == 3)
                release = "8.1";
            else
                release = version.ToString();

            string servicePack = string.IsNullOrEmpty(os.ServicePack) ? "" : (" " + os.ServicePack.Replace("Service Pack ", "SP"));

            return release + servicePack;
        }
 public void PopulateKillProcessThrowsExceptionForUnknownPlatform()
 {
     var killProcess = new Process();
     var operatingSystem = new OperatingSystem(PlatformID.Xbox, new Version(5, 0));
     Assert.Throws<CruiseControlException>(
         () => ProcessExecutor.PopulateKillProcess(killProcess, 1, operatingSystem));
 }
        //private static VapeTeam.Psimulex.Core.Historization.IHistory h = new Historization.History();

        public static OperatingSystem CreateOSWithRoundRobin()
        {
            var os = new OperatingSystem(new Schedulers.RoundRobinScheduler());
            os.ThreadFactory = new HistoricalThreadFactory(VapeTeam.Psimulex.Core.Historization.GlobalHistory.Instance);
            os.InstallLibrary(new VapeTeam.Psimulex.Core.Libraries.StandardLibrary());
            return os;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns>NT 4.0, 2000, XP, Vista,7</returns>
        public string getOSInfo()
        {
            os = Environment.OSVersion;
            vs = os.Version;

            string operatingSystem = "";

            if (os.Platform == PlatformID.Win32NT)
            {
                switch (vs.Major)
                {
                    case 3:
                        operatingSystem = "NT 3.51";
                        break;
                    case 4:
                        operatingSystem = "NT 4.0";
                        break;
                    case 5:
                        if (vs.Minor == 0)
                            operatingSystem = "2000";
                        else
                            operatingSystem = "XP";
                        break;
                    case 6:
                        if (vs.Minor == 0)
                            operatingSystem = "Vista";
                        else
                            operatingSystem = "7";
                        break;
                    default:
                        break;
                }
            }
            return operatingSystem;
        }
Example #5
0
        public void Test()
        {
            new TestCase("", Inp, Epc, delegate(TestCase c_)
            {
                PlatformID pfm = (PlatformID)Enum.Parse(typeof(PlatformID), c_.Input);
                Version ver;
                OperatingSystem os;
                try
                {
                    ver = new Version();
                    os = new OperatingSystem(pfm, ver);
                }
                catch (Exception exver)
                {
                    c_.Expected = exver.Message;
                    return exver.Message;
                }

                ILASMRunner r = new ILASMRunner();
                string act = "";
                try
                {
                    r.DetectILASM(os);
                    act = r.ILASMpath;
                }
                catch (Exception ex)
                {
                    c_.Expected = ex.Message;
                    act = ex.Message;
                }
                return act;
            })
            .Run();
        }
Example #6
0
        public void DetectILASM(OperatingSystem os)
        {
            if (ILASMpath == null)
            {
                ILASMpath = Environment.GetEnvironmentVariable(@"NANA_ILASM_PATH");
            }

            if (ILASMpath == null)
            {
                PlatformID pfm = os.Platform;
                switch (pfm)
                {
                    case PlatformID.MacOSX:
                    case PlatformID.Unix:
                        ILASMpath = "/usr/bin/ilasm";
                        break;
                    default:
                        string l = Path.DirectorySeparatorChar.ToString();
                        string systemRoot = Environment.GetEnvironmentVariable("SystemRoot");
                        string netfwdir = systemRoot + l + @"Microsoft.NET\Framework\v2.0.50727";
                        ILASMpath = netfwdir + l + @"ilasm.exe";
                        break;
                }
            }

            if (false == File.Exists(ILASMpath))
            {
                throw new Exception("Could not detect ilasm.exe. You can set ilasm.exe path to environment variable 'NANA_ILASM_PATH'. Detected path:" + ILASMpath);
            }
        }
Example #7
0
		public ClientInformation()
		{
			m_operatingSys = OperatingSystem.Win;
			m_architecture = ProcessorArchitecture.x86;
			Locale = ClientLocale.English;
			TimeZone = 0x258;
			IPAddress = new XmlIPAddress(System.Net.IPAddress.Loopback);
		}
Example #8
0
 public SystemInformation()
 {
     m_Operating = OperatingSystem.Win;
     m_architecture = ProcessorArch.x86;
     Locale = "enUS";
     TimeZone = 0x258;
     IPAddress = new XmlIPAddress(System.Net.IPAddress.Loopback);
 }
 // Constructor
 public Smartphone(string brand, float price, OperatingSystem operatingSystem, string versionOS, short memoryCapacity)
 {
     this.brand = brand;
     this.price = price;
     this.operatingSystem = operatingSystem;
     this.versionOS = versionOS;
     this.memoryCapacity = memoryCapacity;
 }
Example #10
0
        public static void AddUser(TcpClient tcpUser, string strUsername, Encryption encryption, OperatingSystem operatingSystem)
        {
            // create new user
            User user = new User(strUsername, tcpUser, encryption, DateTime.Now, operatingSystem);

            ChatServer.users.Add(strUsername);
            ChatServer.userInfos.Add(strUsername, user);

            SendAdminMessage(strUsername + " has joined us");
        }
Example #11
0
        static void Main(string[] args) {
            string myStr = "Hello";
            OperatingSystem os = new OperatingSystem(PlatformID.Unix, new Version());
            System.Data.SqlClient.SqlConnection sqlCnn = new System.Data.SqlClient.SqlConnection();
            CloneMe(myStr);
            CloneMe(os);
            CloneMe(sqlCnn);

            Console.ReadLine();
        }
 /// <summary>     
 /// The function determines whether the current operating system is a      
 /// 64-bit operating system.     
 /// </summary>     
 /// <returns>     
 /// The function returns true if the operating system is 64-bit;      
 /// otherwise, it returns false.     
 /// </returns>    
 public static bool IsWin64BitOS(OperatingSystem os)
 {
     if (IntPtr.Size == 8)
         // 64-bit programs run only on Win64           
         return true;
     else// 32-bit programs run on both 32-bit and 64-bit Windows     
     {   // Detect whether the current process is a 32-bit process                
         // running on a 64-bit system.               
         return Is64BitProc(Process.GetCurrentProcess());
     }
 }
Example #13
0
 private SysInfo(OperatingSystem os, Version clrVersion, int processorCount, int workerThreads, int ioThreads, int maxGcGeneration, bool isMono)
 {
     OS = os;
     ProcessorCount = processorCount;
     WorkerThreads = workerThreads;
     IOThreads = ioThreads;
     IsMono = isMono;
     ClrVersion = clrVersion;
     MaxGcGeneration = maxGcGeneration;
     NBenchAssemblyVersion = this.GetType().Assembly.FullName;
 }
		static void Main( string[] args) 
		{ Console.WriteLine("***** A First Look at Interfaces *****\ n"); 
			// All of these classes support the ICloneable interface.
			string myStr = "Hello"; 
			OperatingSystem unixOS = new OperatingSystem( PlatformID.Unix, new Version()); 
			System.Data.SqlClient.SqlConnection sqlCnn = new System.Data.SqlClient.SqlConnection(); 
			// Therefore, they can all be passed into a method taking ICloneable.
			CloneMe( myStr); 
			CloneMe( unixOS); 
			CloneMe( sqlCnn); 
			Console.ReadLine(); 
		}
 public void PopulateKillProcessHandlesWindows2000()
 {
     var killProcess = new Process();
     var operatingSystem = new OperatingSystem(PlatformID.Win32NT, new Version(5, 0));
     var platform = ProcessExecutor.PopulateKillProcess(killProcess, 1, operatingSystem);
     Assert.AreEqual("Windows", platform);
     var expectedPath = Path.Combine(
         ProcessExecutor.Win2KSupportToolsDir,
         "kill.exe");
     Assert.AreEqual(expectedPath, killProcess.StartInfo.FileName);
     Assert.AreEqual("-f 1", killProcess.StartInfo.Arguments);
 }
 public void PopulateKillProcessHandlesWindows()
 {
     var killProcess = new Process();
     var operatingSystem = new OperatingSystem(PlatformID.Win32NT, new Version(7, 0));
     var platform = ProcessExecutor.PopulateKillProcess(killProcess, 1, operatingSystem);
     Assert.AreEqual("Windows", platform);
     var expectedPath = Path.Combine(
         Environment.GetFolderPath(Environment.SpecialFolder.System),
         "taskkill.exe");
     Assert.AreEqual(expectedPath, killProcess.StartInfo.FileName);
     Assert.AreEqual("/pid 1 /t /f", killProcess.StartInfo.Arguments);
 }
Example #17
0
        static void Main(string[] args)
        {
            string myString = "Hello";
            OperatingSystem unixOS = new OperatingSystem(PlatformID.Unix, new Version());
            SqlConnection sqlConn = new SqlConnection();

            CloneMe(myString);
            CloneMe(unixOS);
            CloneMe(sqlConn);

            Console.ReadLine();
        }
Example #18
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** A First Look at Interfaces *****\n");
            string myStr = "Hello";
            OperatingSystem unixOS = new OperatingSystem(PlatformID.Unix, new Version());
            SqlConnection sqlCnn = new SqlConnection();

            CloneMe(myStr);
            CloneMe(unixOS);
            CloneMe(sqlCnn);

            Console.ReadLine();
        }
 public bool AppliesTo(OperatingSystem os)
 {
     if (OSType != os.Platform) return false;
     switch (Rule)
     {
         case FilterRules.Any:
             return true;
         case FilterRules.Equals:
             return os.Version == new Version(Version);
         case FilterRules.LessThan:
             return os.Version < new Version(Version);
         case FilterRules.GreaterThan:
             return os.Version > new Version(Version);
     }
     return false;
 }
Example #20
0
        static void Main(string[] args)
        {
            string myStr = "Hello";
            OperatingSystem unixOS = new OperatingSystem(PlatformID.Unix, new Version());
            System.Data.SqlClient.SqlConnection sqlCnn = new System.Data.SqlClient.SqlConnection();

            CloneMe(myStr);
            CloneMe(unixOS);
            CloneMe(sqlCnn);

            InterfaceCloneable[] ainterface = { new CloneA(), new CloneB() };

            var file = @"C:\Users\sn01396\Desktop\柱温箱发送方法失败.txt";
            using (FileStream fs = new FileStream(file, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    var num = 0;
                    while (!sr.EndOfStream)
                    {
                        num++;
                        var str = sr.ReadLine();
                        var key = "7F FE 00 01 00 ";
                        var len = key.Length;
                        var index = str.IndexOf(key);
                        if (index != -1 && index + len + 2 <= str.Length)
                        {
                            var next = str.Substring(index + len, 2);
                            Console.WriteLine("源地址:" + next);
                            if (next != "28")
                            {
                                Console.WriteLine("出错在:" + num);
                            }
                        }
                    }
                }
            }



            Console.ReadLine();
        }
Example #21
0
        private void tsWeaponAccessoryAddGear_Click(object sender, EventArgs e)
        {
            WeaponAccessory objAccessory = (WeaponAccessory)_objFunctions.FindEquipment(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, typeof(WeaponAccessory));

            // Make sure the Weapon Accessory is allowed to accept Gear.
            if (objAccessory.AllowGear == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_WeaponGear"), LanguageManager.Instance.GetString("MessageTitle_CyberwareGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, false);
            string strCategories = "";
            foreach (XmlNode objXmlCategory in objAccessory.AllowGear)
                strCategories += objXmlCategory.InnerText + ",";
            frmPickGear.AllowedCategories = strCategories;
            frmPickGear.ShowDialog(this);

            if (frmPickGear.DialogResult == DialogResult.Cancel)
                return;

            TreeNode objNode = new TreeNode();

            // Open the Gear XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Gear objNewGear = new Gear(_objCharacter);
            switch (frmPickGear.SelectedCategory)
            {
                case "Commlink":
                case "Commlink Upgrade":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objCommlink.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objCommlink.DisplayName;

                    objNewGear = objCommlink;
                    break;
                case "Commlink Operating System":
                case "Commlink Operating System Upgrade":
                    OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter);
                    objOperatingSystem.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objOperatingSystem.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objOperatingSystem.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objOperatingSystem.DisplayName;

                    objNewGear = objOperatingSystem;
                    break;
                default:
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objGear.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objGear.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objGear.DisplayName;

                    objNewGear = objGear;
                    break;
            }

            if (objNewGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objNewGear.Cost != "")
                    objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1";
                if (objNewGear.Cost3 != "")
                    objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1";
                if (objNewGear.Cost6 != "")
                    objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1";
                if (objNewGear.Cost10 != "")
                    objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1";
                if (objNewGear.Extra == "")
                    objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objNewGear.Cost = "0";
                objNewGear.Cost3 = "0";
                objNewGear.Cost6 = "0";
                objNewGear.Cost10 = "0";
            }

            // Create any Weapons that came with this Gear.
            foreach (Weapon objWeapon in objWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            objAccessory.Gears.Add(objNewGear);

            objNode.ContextMenuStrip = cmsWeaponAccessoryGear;
            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryAddGear_Click(sender, e);

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
		/// <summary>
		/// Contruct a PlatformHelper for a particular operating
		/// system and common language runtime. Used in testing.
		/// </summary>
		/// <param name="os">OperatingSystem to be used</param>
		public PlatformHelper( OperatingSystem os, RuntimeFramework rt )
		{
			this.os = os;
			this.rt = rt;
		}
        private bool GetServerInfo()
        {
            if (serverName != null && serverOsInfo == null)
            {
                IntPtr buffer = new IntPtr(); //represents the struct pointer.

                WKSTA_INFO_100 wksInfo;

                // Call Win32 API NetWkstaGetInfo to get the server OS information.
                int result = SafeNativeMethods.NetWkstaGetInfo(serverName, 100, out buffer);

                // 0 indicates succeeded.
                if (result == 0)
                {
                    Int32 pointer = buffer.ToInt32();
                    wksInfo = (WKSTA_INFO_100)Marshal.PtrToStructure(
                        new IntPtr(pointer), typeof(WKSTA_INFO_100));

                    // Free unmanaged buffer.
                    SafeNativeMethods.NetApiBufferFree(buffer);

                    serverOsInfo = new OperatingSystem(
                        PlatformIDToEnum(wksInfo.wki102_platform_id),
                        new Version(wksInfo.wki102_ver_major, wksInfo.wki102_ver_minor)
                    );
                }
                else
                {
                    // If NetWkstaGetInfo failed, set the this information to null silently.
                    serverOsInfo = null;
                }
            }
            return (serverOsInfo != null);
        }
			public bool Match(OperatingSystem os)
			{
				return os.Version.Minor == _minor &&
					   os.Version.Major == _major &&
					   os.Platform == _platform;
			}
		/// <summary>
		/// Default constructor uses the operating system and
		/// common language runtime of the system.
		/// </summary>
		public PlatformHelper()
		{
			this.os = Environment.OSVersion;
			this.rt = RuntimeFramework.CurrentFramework;
		}
Example #26
0
        /// <summary>
        /// Select a piece of Gear to be added to the character.
        /// </summary>
        private bool PickGear()
        {
            bool blnNullParent = false;
            Gear objSelectedGear = (Gear)_objFunctions.FindEquipment(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear, typeof(Gear));
            if (objSelectedGear == null)
            {
                objSelectedGear = new Gear(_objCharacter);
                blnNullParent = true;
            }

            // Open the Gear XML file and locate the selected Gear.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + objSelectedGear.ExternalId + "\"]");

            bool blnFakeCareerMode = false;
            if (_objCharacter.Metatype == "A.I." || _objCharacter.MetatypeCategory == "Technocritters" || _objCharacter.MetatypeCategory == "Protosapients")
                blnFakeCareerMode = true;
            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, blnFakeCareerMode, objSelectedGear.ChildAvailModifier, objSelectedGear.ChildCostMultiplier);
            try
            {
                if (treGear.SelectedNode.Level > 0)
                {
                    if (objXmlGear["addoncategory"] != null)
                    {
                        string strCategories = "";
                        foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                            strCategories += objXmlCategory.InnerText + ",";
                        // Remove the trailing comma.
                        strCategories = strCategories.Substring(0, strCategories.Length - 1);
                        frmPickGear.AddCategory(strCategories);
                    }

                    if (frmPickGear.AllowedCategories != "")
                        frmPickGear.AllowedCategories += objSelectedGear.Category + ",";

                    // If the Gear has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity).
                    if (!objSelectedGear.Capacity.Contains('['))
                        frmPickGear.MaximumCapacity = objSelectedGear.CapacityRemaining;

                    if (objSelectedGear.Category == "Commlink")
                    {
                        Commlink objCommlink = (Commlink)objSelectedGear;
                        frmPickGear.CommlinkResponse = objCommlink.Response;
                        frmPickGear.CommlinkSignal = objCommlink.Signal;
                        frmPickGear.CommlinkFirewall = objCommlink.Firewall;
                        frmPickGear.CommlinkSystem = objCommlink.System;
                    }
                    if (objSelectedGear.Category == "Commlink Operating System")
                    {
                        OperatingSystem objOS = (OperatingSystem)objSelectedGear;
                        frmPickGear.CommlinkFirewall = objOS.Firewall;
                        frmPickGear.CommlinkSystem = objOS.System;
                    }
                }
            }
            catch
            {
            }

            frmPickGear.ShowDialog(this);

            // Make sure the dialogue window was not canceled.
            if (frmPickGear.DialogResult == DialogResult.Cancel)
                return false;

            TreeNode objNode = new TreeNode();

            // Open the Cyberware XML file and locate the selected piece.
            objXmlDocument = XmlManager.Instance.Load("gear.xml");
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Gear objNewGear = new Gear(_objCharacter);
            switch (frmPickGear.SelectedCategory)
            {
                case "Commlink":
                case "Commlink Upgrade":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objCommlink.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objCommlink.DisplayName;

                    // If a Commlink has just been added, see if the character already has one. If not, make it the active Commlink.
                    if (_objFunctions.FindCharacterCommlinks(_objCharacter.Gear).Count == 0 && frmPickGear.SelectedCategory == "Commlink")
                        objCommlink.IsActive = true;

                    objNewGear = objCommlink;
                    break;
                case "Commlink Operating System":
                case "Commlink Operating System Upgrade":
                    OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter);
                    objOperatingSystem.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objOperatingSystem.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objOperatingSystem.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objOperatingSystem.DisplayName;

                    objNewGear = objOperatingSystem;
                    break;
                default:
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objGear.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objGear.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objGear.DisplayName;

                    objNewGear = objGear;
                    break;
            }

            if (objNewGear.InternalId == Guid.Empty.ToString())
                return false;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objNewGear.Cost != "")
                    objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1";
                if (objNewGear.Cost3 != "")
                    objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1";
                if (objNewGear.Cost6 != "")
                    objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1";
                if (objNewGear.Cost10 != "")
                    objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1";
                if (objNewGear.Extra == "")
                    objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objNewGear.Cost = "0";
                objNewGear.Cost3 = "0";
                objNewGear.Cost6 = "0";
                objNewGear.Cost10 = "0";
            }

            // Create any Weapons that came with this Gear.
            foreach (Weapon objWeapon in objWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            objNewGear.Parent = objSelectedGear;
            if (blnNullParent)
                objNewGear.Parent = null;

            try
            {
                if (treGear.SelectedNode.Level > 0)
                {
                    objNode.ContextMenuStrip = cmsGear;
                    treGear.SelectedNode.Nodes.Add(objNode);
                    treGear.SelectedNode.Expand();
                    objSelectedGear.Gears.Add(objNewGear);
                }
                else
                {
                    objNode.ContextMenuStrip = cmsGear;
                    treGear.Nodes[0].Nodes.Add(objNode);
                    treGear.Nodes[0].Expand();
                    _objCharacter.Gear.Add(objNewGear);
                }
            }
            catch
            {
                treGear.Nodes[0].Nodes.Add(objNode);
                treGear.Nodes[0].Expand();
                _objCharacter.Gear.Add(objNewGear);
            }

            // Select the node that was just added.
            if (objNode.Level < 2)
                treGear.SelectedNode = objNode;

            UpdateCharacterInfo();
            RefreshSelectedGear();

            _blnIsDirty = true;
            UpdateWindowTitle();

            return frmPickGear.AddAgain;
        }
Example #27
0
        /// <summary>
        /// Add a piece of Gear that was found in a PACKS Kit.
        /// </summary>
        /// <param name="objXmlGearDocument">XmlDocument that contains the Gear.</param>
        /// <param name="objXmlGear">XmlNode of the Gear to add.</param>
        /// <param name="objParent">TreeNode to attach the created items to.</param>
        /// <param name="objParentObject">Object to associate the newly-created items with.</param>
        /// <param name="cmsContextMenu">ContextMenuStrip to assign to the TreeNodes created.</param>
        /// <param name="blnCreateChildren">Whether or not the default plugins for the Gear should be created.</param>
        private void AddPACKSGear(XmlDocument objXmlGearDocument, XmlNode objXmlGear, TreeNode objParent, Object objParentObject, ContextMenuStrip cmsContextMenu, bool blnCreateChildren)
        {
            int intRating = 0;
            if (objXmlGear["rating"] != null)
                intRating = Convert.ToInt32(objXmlGear["rating"].InnerText);
            int intQty = 1;
            if (objXmlGear["qty"] != null)
                intQty = Convert.ToInt32(objXmlGear["qty"].InnerText);

            XmlNode objXmlGearNode;
            objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + objXmlGear["id"].InnerText + "\"]");

            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            string strForceValue = "";
            if (objXmlGear["name"].Attributes["select"] != null)
                strForceValue = objXmlGear["name"].Attributes["select"].InnerText;

            Gear objNewGear = new Gear(_objCharacter);
            switch (objXmlGearNode["category"].InnerText)
            {
                case "Commlink":
                case "Commlink Upgrade":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGearNode, _objCharacter, objNode, intRating, true, blnCreateChildren);
                    objCommlink.Quantity = intQty;
                    objNewGear = objCommlink;
                    break;
                case "Commlink Operating System":
                case "Commlink Operating System Upgrade":
                    OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter);
                    objOperatingSystem.Create(objXmlGearNode, _objCharacter, objNode, intRating, true, blnCreateChildren);
                    objOperatingSystem.Quantity = intQty;
                    objNewGear = objOperatingSystem;
                    break;
                default:
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGearNode, _objCharacter, objNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, true, blnCreateChildren);
                    objGear.Quantity = intQty;
                    objNode.Text = objGear.DisplayName;
                    objNewGear = objGear;
                    break;
            }

            if (objParentObject.GetType() == typeof(Character))
                ((Character)objParentObject).Gear.Add(objNewGear);
            if (objParentObject.GetType() == typeof(Gear) || objParentObject.GetType() == typeof(Commlink) || objParentObject.GetType() == typeof(OperatingSystem))
            {
                ((Gear)objParentObject).Gears.Add(objNewGear);
                objNewGear.Parent = (Gear)objParentObject;
            }
            if (objParentObject.GetType() == typeof(Armor))
                ((Armor)objParentObject).Gears.Add(objNewGear);
            if (objParentObject.GetType() == typeof(WeaponAccessory))
                ((WeaponAccessory)objParentObject).Gears.Add(objNewGear);
            if (objParentObject.GetType() == typeof(Cyberware))
                ((Cyberware)objParentObject).Gears.Add(objNewGear);

            // Look for child components.
            if (objXmlGear["gears"] != null)
            {
                foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear"))
                {
                    AddPACKSGear(objXmlGearDocument, objXmlChild, objNode, objNewGear, cmsContextMenu, blnCreateChildren);
                }
            }

            objParent.Nodes.Add(objNode);
            objParent.Expand();

            objNode.ContextMenuStrip = cmsContextMenu;
            objNode.Text = objNewGear.DisplayName;

            // Add any Weapons created by the Gear.
            foreach (Weapon objWeapon in objWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }
        }
Example #28
0
        private void tsWeaponAccessoryGearMenuAddAsPlugin_Click(object sender, EventArgs e)
        {
            // Locate the Vehicle Sensor Gear.
            bool blnFound = false;
            WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter);
            Gear objSensor = (Gear)_objFunctions.FindEquipment(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, typeof(Gear));
            if (objSensor != null)
                blnFound = true;

            if (objSensor.Parent != null)
                objFoundAccessory = (WeaponAccessory)objSensor.Parent;

            // Make sure the Gear was found.
            if (!blnFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_ModifyVehicleGear"), LanguageManager.Instance.GetString("MessageTitle_SelectGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + objSensor.ExternalId + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter);
            //frmPickGear.ShowNegativeCapacityOnly = true;

            if (objXmlGear["addoncategory"] != null)
            {
                string strCategories = "";
                foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                    strCategories += objXmlCategory.InnerText + ",";
                // Remove the trailing comma.
                strCategories = strCategories.Substring(0, strCategories.Length - 1);
                frmPickGear.AddCategory(strCategories);
            }

            if (frmPickGear.AllowedCategories != "")
                frmPickGear.AllowedCategories += objSensor.Category + ",";

            frmPickGear.ShowDialog(this);

            if (frmPickGear.DialogResult == DialogResult.Cancel)
                return;

            // Open the Gear XML file and locate the selected piece.
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlink":
                case "Commlink Upgrade":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objCommlink.DisplayName;

                    objGear = objCommlink;
                    break;
                case "Commlink Operating System":
                case "Commlink Operating System Upgrade":
                    OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter);
                    objOperatingSystem.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objOperatingSystem.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objOperatingSystem.DisplayName;

                    objGear = objOperatingSystem;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objNewGear.DisplayName;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objNode.Text = objGear.DisplayName;

            objNode.ContextMenuStrip = cmsWeaponAccessoryGear;

            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            objGear.Parent = objSensor;
            objSensor.Gears.Add(objGear);

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryGearMenuAddAsPlugin_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedWeapon();
        }
Example #29
0
        /// <summary>
        /// Enable/Disable the Paste Menu and ToolStrip items as appropriate.
        /// </summary>
        private void RefreshPasteStatus()
        {
            bool blnPasteEnabled = false;
            bool blnCopyEnabled = false;

            if (tabCharacterTabs.SelectedTab == tabStreetGear)
            {
                // Lifestyle Tab.
                if (tabStreetGearTabs.SelectedTab == tabLifestyle)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Lifestyle)
                        blnPasteEnabled = true;

                    try
                    {
                        foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles)
                        {
                            if (objLifestyle.InternalId == treLifestyles.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                // Armor Tab.
                if (tabStreetGearTabs.SelectedTab == tabArmor)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Armor)
                        blnPasteEnabled = true;
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                    {
                        // Gear can only be pasted into Armor, not Armor Mods.
                        try
                        {
                            foreach (Armor objArmor in _objCharacter.Armor)
                            {
                                if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                                {
                                    blnPasteEnabled = true;
                                    break;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }

                    try
                    {
                        foreach (Armor objArmor in _objCharacter.Armor)
                        {
                            if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        Gear objGear = (Gear)_objFunctions.FindEquipment(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, typeof(Gear));
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }

                // Weapons Tab.
                if (tabStreetGearTabs.SelectedTab == tabWeapons)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon)
                        blnPasteEnabled = true;
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                    {
                        // Check if the copied Gear can be pasted into the selected Weapon Accessory.
                        Gear objGear = new Gear(_objCharacter);
                        XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear");
                        if (objXmlNode != null)
                        {
                            switch (objXmlNode["category"].InnerText)
                            {
                                case "Commlink":
                                case "Commlink Upgrade":
                                    Commlink objCommlink = new Commlink(_objCharacter);
                                    objCommlink.Load(objXmlNode, true);
                                    objGear = objCommlink;
                                    break;
                                case "Commlink Operating System":
                                case "Commlink Operating System Upgrade":
                                    OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter);
                                    objOperatingSystem.Load(objXmlNode, true);
                                    objGear = objOperatingSystem;
                                    break;
                                default:
                                    Gear objNewGear = new Gear(_objCharacter);
                                    objNewGear.Load(objXmlNode, true);
                                    objGear = objNewGear;
                                    break;
                            }

                            objGear.Parent = null;

                            // Make sure that a Weapon Accessory is selected and that it allows Gear of the item's Category.
                            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                            try
                            {
                                foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                                {
                                    foreach (WeaponAccessory objWeaponAccessory in objCharacterWeapon.WeaponAccessories)
                                    {
                                        if (objWeaponAccessory.InternalId == treWeapons.SelectedNode.Tag.ToString())
                                        {
                                            objAccessory = objWeaponAccessory;
                                            break;
                                        }
                                    }
                                }
                                if (objAccessory.AllowGear != null)
                                {
                                    foreach (XmlNode objAllowed in objAccessory.AllowGear.SelectNodes("gearcategory"))
                                    {
                                        if (objAllowed.InnerText == objGear.Category)
                                        {
                                            blnPasteEnabled = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }

                    try
                    {
                        foreach (Weapon objWeapon in _objCharacter.Weapons)
                        {
                            if (objWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        Gear objGear = (Gear)_objFunctions.FindEquipment(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, typeof(Gear));
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }

                // Gear Tab.
                if (tabStreetGearTabs.SelectedTab == tabGear)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                        blnPasteEnabled = true;

                    try
                    {
                        Gear objGear = (Gear)_objFunctions.FindEquipment(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear, typeof(Gear));
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }
            }

            // Vehicles Tab.
            if (tabCharacterTabs.SelectedTab == tabVehicles)
            {
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Vehicle)
                    blnPasteEnabled = true;
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                {
                    // Gear can only be pasted into Vehicles and Vehicle Gear.
                    try
                    {
                        foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                        {
                            if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                blnPasteEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        Gear objGear = (Gear)_objFunctions.FindEquipment(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, typeof(Gear));
                        if (objGear != null)
                            blnPasteEnabled = true;
                    }
                    catch
                    {
                    }
                }
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon)
                {
                    // Weapons can only be pasted into Vehicle Mods that allow them (Weapon Mounts and Mechanical Arms).
                    try
                    {
                        VehicleMod objMod = new VehicleMod(_objCharacter);
                        foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                        {
                            foreach (VehicleMod objVehicleMod in objVehicle.VehicleMods)
                            {
                                if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    if (objVehicleMod.WeaponMount)
                                    {
                                        blnPasteEnabled = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                try
                {
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            blnCopyEnabled = true;
                            break;
                        }
                    }
                }
                catch
                {
                }
                try
                {
                    Gear objGear = (Gear)_objFunctions.FindEquipment(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, typeof(Gear));
                    if (objGear != null)
                        blnCopyEnabled = true;
                }
                catch
                {
                }
                try
                {
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.VehicleMods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    blnCopyEnabled = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            mnuEditPaste.Enabled = blnPasteEnabled;
            tsbPaste.Enabled = blnPasteEnabled;
            mnuEditCopy.Enabled = blnCopyEnabled;
            tsbCopy.Enabled = blnCopyEnabled;
        }
Example #30
0
        private void tsVehicleAddGear_Click(object sender, EventArgs e)
        {
            // Make sure a parent items is selected, then open the Select Gear window.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (treVehicles.SelectedNode.Level > 1)
                treVehicles.SelectedNode = treVehicles.SelectedNode.Parent;

            // Locate the selected Vehicle.
            Vehicle objSelectedVehicle = (Vehicle)_objFunctions.FindEquipment(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, typeof(Vehicle));

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter);
            frmPickGear.ShowPositiveCapacityOnly = true;
            frmPickGear.ShowDialog(this);

            if (frmPickGear.DialogResult == DialogResult.Cancel)
                return;

            // Open the Gear XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlink":
                case "Commlink Upgrade":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, false);
                    objCommlink.Quantity = frmPickGear.SelectedQty;

                    objGear = objCommlink;
                    break;
                case "Commlink Operating System":
                case "Commlink Operating System Upgrade":
                    OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter);
                    objOperatingSystem.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, false);
                    objOperatingSystem.Quantity = frmPickGear.SelectedQty;

                    objGear = objOperatingSystem;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, false, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objGear.Quantity = frmPickGear.SelectedQty;
            objNode.Text = objGear.DisplayName;
            try
            {
                nudVehicleRating.Increment = objGear.CostFor;
                nudVehicleRating.Minimum = nudGearQty.Increment;
            }
            catch
            {
            }

            // Change the cost of the Sensor itself to 0.
            if (frmPickGear.SelectedCategory == "Sensors")
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objNode.ContextMenuStrip = cmsVehicleGear;

            bool blnMatchFound = false;
            // If this is Ammunition, see if the character already has it on them.
            if (objGear.Category == "Ammunition")
            {
                foreach (Gear objVehicleGear in objSelectedVehicle.Gears)
                {
                    if (objVehicleGear.Name == objGear.Name && objVehicleGear.Category == objGear.Category && objVehicleGear.Rating == objGear.Rating && objVehicleGear.Extra == objGear.Extra)
                    {
                        // A match was found, so increase the quantity instead.
                        objVehicleGear.Quantity += objGear.Quantity;
                        blnMatchFound = true;

                        foreach (TreeNode objGearNode in treVehicles.SelectedNode.Nodes)
                        {
                            if (objVehicleGear.InternalId == objGearNode.Tag.ToString())
                            {
                                objGearNode.Text = objVehicleGear.DisplayName;
                                break;
                            }
                        }

                        break;
                    }
                }
            }

            if (!blnMatchFound)
            {
                treVehicles.SelectedNode.Nodes.Add(objNode);
                treVehicles.SelectedNode.Expand();

                // Add the Gear to the Vehicle.
                objSelectedVehicle.Gears.Add(objGear);
            }

            if (frmPickGear.AddAgain)
                tsVehicleAddGear_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedVehicle();
        }