예제 #1
0
        public static IEnumerator Postfix(IEnumerator __result, AddProgramApp __instance, OSProgramDesc desc, bool ___m_dayEnded)
        {
            if (!ConfigHandler.Instance.NoRebootInstallBool.Value)
            {
                yield return(__result);
            }
            ___m_dayEnded = false;
            SFReflect.Run("ShowProgressDialog", __instance, new[] { (object)ScriptLocalization.AddPrograms.INSTALLING, desc });
            yield return(SFReflect.Run <IEnumerator>("ShowProgress", __instance, new[] { (object)0f, (object)0.9f, (object)(float)((double)desc.m_installTime * 0.4f), (object)true }));

            yield return(SFReflect.Run <IEnumerator>("ShowProgress", __instance, new[] { (object)0.9f, (object)0.95f, (object)(float)((double)desc.m_installTime * 0.6f), (object)true }));

            yield return(SFReflect.Run <IEnumerator>("ShowProgress", __instance, new[] { (object)0.95f, (object)1f, (object)1f, (object)false }));

            ComputerSoftware software = __instance.GetComponentInParent <VirtualComputer>().GetComputer().m_software;

            software.m_programs = new List <string>(software.m_programs)
            {
                desc.m_id
            }.ToArray();
            __instance.m_installPopup.SetActive(false);
            var os = __instance.GetComponentInParent <OS>();

            SFLog.log($"Installing {desc.m_uiName} without rebooting...");
            SFReflect.Run("AddProgramIcon", os, Utils.fixArray(desc));
            var m_userDescs = SFReflect.Get <List <OSProgramDesc> >("m_userDescs", os);

            m_userDescs.Add(desc);
            SFReflect.Run("ShowPrograms", __instance);
            SFReflect.Run("BringToFront", os, Utils.fixArray(__instance.GetComponentInParent <WindowFrame>()));
            yield break;
        }
예제 #2
0
        static IEnumerator Postfix(IEnumerator __result, AddProgramApp __instance, OSProgramDesc desc, bool ___m_dayEnded)
        {
            ___m_dayEnded = false;
            ReflectionUtils.Run("ShowProgressDialog", __instance, new object[] { ScriptLocalization.AddPrograms.INSTALLING, desc });
            yield return(ReflectionUtils.Run <IEnumerator>("ShowProgress", __instance, new object[] { 0f, 0.9f, (float)desc.m_installTime * 0.4f, true }));

            yield return(ReflectionUtils.Run <IEnumerator>("ShowProgress", __instance, new object[] { 0.9f, 0.95f, (float)desc.m_installTime * 0.6f, true }));

            yield return(ReflectionUtils.Run <IEnumerator>("ShowProgress", __instance, new object[] { 0.95f, 1f, 1f, false }));

            ComputerSoftware software = __instance.GetComponentInParent <VirtualComputer>().GetComputer().m_software;

            software.m_programs = new List <string>(software.m_programs)
            {
                desc.m_id
            }.ToArray();
            var os = __instance.GetComponentInParent <OS>();

            __instance.m_installPopup.SetActive(false);
            OSLogic.InstanceFor(os).AddProgram(desc.m_id);
            OSLogic.InstanceFor(os).UpdatePrograms();
            ReflectionUtils.Run("UpdateProgramList", __instance);

            yield break;
        }
예제 #3
0
        public static IEnumerator Postfix(IEnumerator __result, AddProgramApp __instance, OSProgramDesc desc, bool ___m_dayEnded)
        {
            if (!ConfigHandler.Instance.NoRebootUnInstallBool.Value)
            {
                yield return(__result);
            }
            ___m_dayEnded = false;
            SFReflect.Run("ShowProgressDialog", __instance, new[] { (object)ScriptLocalization.AddPrograms.REMOVING, desc });
            yield return(SFReflect.Run <IEnumerator>("ShowProgress", __instance, new[] { (object)0f, (object)0.9f, (object)(float)((double)desc.m_removeTime * 0.2f), (object)true }));

            yield return(SFReflect.Run <IEnumerator>("ShowProgress", __instance, new[] { (object)0.9f, (object)0.95f, (object)(float)((double)desc.m_removeTime * 0.8f), (object)true }));

            yield return(SFReflect.Run <IEnumerator>("ShowProgress", __instance, new[] { (object)0.95f, (object)1f, (object)1f, (object)false }));

            ComputerSoftware software = __instance.GetComponentInParent <VirtualComputer>().GetComputer().m_software;
            List <string>    list     = new List <string>(software.m_programs);

            list.Remove(desc.m_id);
            software.m_programs = list.ToArray();
            __instance.m_installPopup.SetActive(false);
            var os = __instance.GetComponentInParent <OS>();

            SFLog.log($"Uninstalling {desc.m_uiName} without rebooting...");
            var m_icons = SFReflect.Get <List <ProgramIcon> >("m_icons", os);

            foreach (var icon in m_icons)
            {
                if (icon.m_text.text == desc.m_uiName)
                {
                    m_icons.Remove(icon);
                    UnityEngine.Object.Destroy((UnityEngine.Object)icon.gameObject);
                    break;
                }
            }
            var m_userDescs = SFReflect.Get <List <OSProgramDesc> >("m_userDescs", os);

            foreach (var userDesc in m_userDescs)
            {
                if (userDesc.m_id == desc.m_id)
                {
                    m_userDescs.Remove(userDesc);
                    UnityEngine.Object.Destroy(userDesc);
                    break;
                }
            }
            SFReflect.Run("ShowPrograms", __instance);
            yield break;
        }
        //WMI Query Registry for software details
        public int ReadRegistryForSoftwareWMI()
        {
            ComputerSoftware computerSoftwares = new ComputerSoftware();
            int rtn = -1;

            try
            {
                using (var db = new DatabaseContext())
                {
                    const int  REG_SZ          = 1;
                    const int  REG_EXPAND_SZ   = 2;
                    const int  REG_BINARY      = 3;
                    const int  REG_DWORD       = 4;
                    const int  REG_MULTI_SZ    = 7;
                    const int  REG_QWORD       = 11;
                    var        queryDBSoftware = db.ComputerSoftwares.Select(x => x.Name);
                    List <int> softwareBits    = new List <int> {
                        32, 64
                    };
                    foreach (int bit in softwareBits)
                    {
                        ManagementNamedValueCollection mContext = new ManagementNamedValueCollection
                        {
                            { "__ProviderArchitecture", bit },
                            { "__RequiredArchitecture", true }
                        };

                        ConnectionOptions connectionOptions = new ConnectionOptions
                        {
                            Impersonation = ImpersonationLevel.Impersonate,
                            Context       = mContext
                        };

                        ManagementScope scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\CIMV2", connectionOptions);
                        scope.Connect();

                        string softwareRegLoc = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";

                        ManagementClass      registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
                        ManagementBaseObject inParams = registry.GetMethodParameters("EnumKey");
                        inParams["hDefKey"]     = 0x80000002;//HKEY_LOCAL_MACHINE
                        inParams["sSubKeyName"] = softwareRegLoc;

                        // Read Registry Key Names
                        ManagementBaseObject outParams     = registry.InvokeMethod("EnumKey", inParams, null);
                        string[]             softwareGuids = outParams["sNames"] as string[];

                        foreach (string subKeyName in softwareGuids)
                        {
                            inParams                = registry.GetMethodParameters("EnumValues");
                            inParams["hDefKey"]     = 0x80000002;//HKEY_LOCAL_MACHINE
                            inParams["sSubKeyName"] = softwareRegLoc + @"\" + subKeyName;

                            // Read Registry Value
                            outParams = registry.InvokeMethod("EnumValues", inParams, null);
                            if (outParams.Properties["sNames"].Value != null &&
                                outParams.Properties["Types"].Value != null)
                            {
                                //For Names
                                string[] softwareValueNames = (outParams.Properties["sNames"].Value) as string[];
                                int[]    softwareValueTypes = (outParams.Properties["Types"].Value) as int[];

                                //For Types
                                for (int i = 0; i < softwareValueTypes.Count(); i++)
                                {
                                    int    valueTypes = softwareValueTypes[i];
                                    string valueNames = softwareValueNames[i];
                                    string executionMethod;
                                    switch (valueTypes)
                                    {
                                    case REG_SZ:
                                    {
                                        executionMethod = "GetStringValue";
                                        //inParams = registry.GetMethodParameters("GetStringValue");
                                        break;
                                    }

                                    case REG_EXPAND_SZ:
                                    {
                                        executionMethod = "GetExpandedStringValue";
                                        break;
                                    }

                                    case REG_BINARY:
                                    {
                                        executionMethod = "GetBinaryValue";
                                        break;
                                    }

                                    case REG_DWORD:
                                    {
                                        executionMethod = "GetDWORDValue";
                                        break;
                                    }

                                    case REG_MULTI_SZ:
                                    {
                                        executionMethod = "GetMultiStringValue";
                                        break;
                                    }

                                    case REG_QWORD:
                                    {
                                        executionMethod = "GetQWORDValue";
                                        break;
                                    }

                                    default:
                                    {
                                        executionMethod = "Close";
                                        break;
                                    }
                                    }
                                    if (executionMethod != "Close")
                                    {
                                        inParams                = registry.GetMethodParameters(executionMethod);
                                        inParams["hDefKey"]     = 0x80000002;//HKEY_LOCAL_MACHINE
                                        inParams["sSubKeyName"] = softwareRegLoc + @"\" + subKeyName;
                                        inParams["sValueName"]  = valueNames;
                                        outParams               = registry.InvokeMethod(executionMethod, inParams, null);

                                        int softwareSystemComponent;
                                        //Get values
                                        switch (valueNames)
                                        {
                                        case "DisplayName":
                                        {
                                            computerSoftwares.Name = outParams.Properties["sValue"].Value.ToString();
                                            break;
                                        }

                                        case "InstallLocation":
                                        {
                                            computerSoftwares.InstalledLocation = outParams.Properties["sValue"].Value.ToString();
                                            break;
                                        }

                                        case "DisplayVersion":
                                        {
                                            computerSoftwares.Version = outParams.Properties["sValue"].Value.ToString();
                                            break;
                                        }

                                        case "Publisher":
                                        {
                                            computerSoftwares.Publisher = outParams.Properties["sValue"].Value.ToString();
                                            break;
                                        }

                                        case "InstallDate":
                                        {
                                            DateTime dt;
                                            if (outParams.Properties["sValue"].Value.ToString() == null)
                                            {
                                                computerSoftwares.InstalledOn = Convert.ToDateTime("19900903");
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    if (DateTime.TryParseExact(outParams.Properties["sValue"].Value.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                                                    {
                                                        computerSoftwares.InstalledOn = dt;
                                                    }
                                                    else if (DateTime.TryParseExact(outParams.Properties["sValue"].Value.ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                                                    {
                                                        computerSoftwares.InstalledOn = dt;
                                                    }
                                                    else if (DateTime.TryParseExact(outParams.Properties["sValue"].Value.ToString(), "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                                                    {
                                                        computerSoftwares.InstalledOn = dt;
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    throw ex;
                                                }
                                            }
                                            break;
                                        }

                                        case "EstimatedSize":
                                        {
                                            computerSoftwares.Size = Convert.ToInt32(outParams.Properties["uValue"].Value);
                                            break;
                                        }

                                        case "SystemComponent":
                                        {
                                            softwareSystemComponent = Convert.ToInt32(outParams.Properties["uValue"].Value);
                                            if (softwareSystemComponent.Equals(""))
                                            {
                                                softwareSystemComponent = 1;
                                            }
                                            computerSoftwares.SystemComponent = softwareSystemComponent;
                                            break;
                                        }

                                        default:
                                            break;
                                        }
                                    }
                                }

                                //Filter unwanted softwares
                                if (softwareValueNames.Contains("WindowsInstaller") &&
                                    !softwareValueNames.Contains("ParentDisplayName") &&
                                    !softwareValueNames.Contains("ParentDisplayName") &&
                                    softwareValueNames.Contains("UninstallString"))
                                {
                                    var currentRegistryScan = computerSoftwares.Name.ToString();
                                    if (!string.IsNullOrEmpty(currentRegistryScan) &&
                                        char.IsUpper(currentRegistryScan[0]) &&
                                        !currentRegistryScan.Contains("-") &&
                                        !currentRegistryScan.ToLower().Contains("pack") &&
                                        !currentRegistryScan.ToLower().Contains("kb") &&
                                        !currentRegistryScan.ToLower().Contains("update") &&
                                        !queryDBSoftware.Contains(currentRegistryScan) &&
                                        computerSoftwares.SystemComponent == 1)
                                    {
                                        computerSoftwares.Status = "Active";
                                        db.ComputerSoftwares.Add(computerSoftwares);
                                        db.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                    rtn = 1;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(rtn);
        }