Ejemplo n.º 1
0
        public void SetRegistryPermissionsBySIDTest()
        {
            string builtInUsersSID = "S-1-5-32-545";

            if (Registry.LocalMachine.OpenSubKey("Software\\TestKey") != null)
            {
                Registry.LocalMachine.DeleteSubKeyTree("Software\\TestKey");
            }

            try
            {
                RegistryKey registryKey    = Registry.LocalMachine.CreateSubKey("Software\\TestKey");
                RegistryKey subRegistryKey = registryKey.CreateSubKey("TestSubKey");
                subRegistryKey.SetValue("TestValue", "Pork Muffins!");

                Assert.IsFalse(RegistryAccess.DoesUserHaveAccess(registryKey, builtInUsersSID, RegistryRights.FullControl));
                Assert.IsFalse(RegistryAccess.DoesUserHaveAccess(subRegistryKey, builtInUsersSID, RegistryRights.FullControl));

                RegistryAccess.SetUserAccessBySID(registryKey, builtInUsersSID, RegistryRights.FullControl);

                Assert.IsTrue(RegistryAccess.DoesUserHaveAccess(registryKey, builtInUsersSID, RegistryRights.FullControl));
                Assert.IsTrue(RegistryAccess.DoesUserHaveAccess(subRegistryKey, builtInUsersSID, RegistryRights.FullControl));
            }
            finally
            {
                if (Registry.LocalMachine.OpenSubKey("Software\\TestKey") != null)
                {
                    Registry.LocalMachine.DeleteSubKeyTree("Software\\TestKey");
                }
            }
        }
        //public override void Install(IDictionary stateSaver)
        //{
        //    string launcherPath = this.Context.Parameters["targetpath"];
        //    string launcherExe = Path.Combine(launcherPath, "Launcher.exe");

        //    if (File.Exists(launcherExe) == true)
        //        File.Delete(launcherExe);

        //    base.Install(stateSaver);
        //}

        protected override void OnAfterInstall(IDictionary savedState)
        {
            int stepCount = 0;

            try
            {
                //StringBuilder sb = new StringBuilder();
                //foreach (string key in this.Context.Parameters.Keys)
                //{
                //    sb.AppendLine(String.Format("{0} = {1}", key, this.Context.Parameters[key]));
                //}
                //string exePath = this.Context.Parameters["targetpath"];
                //sb.AppendLine("wtf: " + exePath);
                //File.WriteAllText("c:\\out.txt", sb.ToString());

                // Clear any old DS databases.
                foreach (string filename in Directory.GetFiles(this.Context.Parameters["targetpath"], "*.ds"))
                {
                    File.Delete(filename);
                }

                stepCount++;

                // Create registry keys if they don't exist.
                RegistryKey rootKey           = Registry.LocalMachine.OpenSubKey(GetAllegianceRoot(), true);
                RegistryKey productionKey     = rootKey.OpenSubKey("1.0");
                string      artPath           = (String)productionKey.GetValue("ArtPath");
                string      productionExePath = (String)productionKey.GetValue("EXE Path");

                stepCount++;

                try
                {
                    if (RegistryAccess.DoesUserHaveAccess(rootKey, BuiltinUsersSID, System.Security.AccessControl.RegistryRights.FullControl) == false)
                    {
                        RegistryAccess.SetUserAccessBySID(rootKey, BuiltinUsersSID, System.Security.AccessControl.RegistryRights.FullControl);
                    }
                }
                catch (Exception ex)
                {
                    this.Context.LogMessage(ex.ToString());

                    // Ignore security exceptions for Windows8 and up.
                    if (WindowsVersion < Windows8Version)
                    {
                        throw;
                    }


                    //if (WindowsVersion >= 6.2)
                    //{
                    //    if (MessageBox.Show("There was an error granting permissions to the BUILTIN\\User account to: " + rootKey + "\r\n\r\nThis is specific to Windows 8, and can be ignored. Continue Installation?", "Permissions Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                    //        throw;
                    //}
                    //else
                    //    throw;
                }

                stepCount++;

                RegistryKey developmentKey = rootKey.OpenSubKey("1.2", true);
                if (developmentKey == null)
                {
                    developmentKey = rootKey.CreateSubKey("1.2", RegistryKeyPermissionCheck.ReadWriteSubTree);
                }

                stepCount++;

                //if (developmentKey.GetValue("Allow3DAcceleration", null) == null)
                developmentKey.SetValue("Allow3DAcceleration", 1, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("AllowSecondary", null) == null)
                developmentKey.SetValue("AllowSecondary", 1, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("ArtPath", null) == null)
                developmentKey.SetValue("ArtPath", Path.Combine(this.Context.Parameters["targetpath"], Integration.LobbyType.Production.ToString() + "\\Artwork"), RegistryValueKind.String);

                developmentKey.SetValue("ProductionArtPath", Path.Combine(this.Context.Parameters["targetpath"], Integration.LobbyType.Production.ToString() + "\\Artwork"), RegistryValueKind.String);

                developmentKey.SetValue("BetaArtPath", Path.Combine(this.Context.Parameters["targetpath"], Integration.LobbyType.Beta.ToString() + "\\Artwork"), RegistryValueKind.String);

                stepCount++;

                //if (developmentKey.GetValue("Bandwidth", null) == null)
                developmentKey.SetValue("Bandwidth", 2, RegistryValueKind.DWord);

                stepCount++;

                // Don't delete this, might re-add post css beta.
                // If there is already a CfgFile entry, then store it for uninstallation only if there
                // is not already a PreviousCfgFile entry.
                //string cfgFile = (String)developmentKey.GetValue("CfgFile", null);
                //if (cfgFile != null)
                //{
                //    if (developmentKey.GetValue("PreviousCfgFile", null) == null)
                //        developmentKey.SetValue("PreviousCfgFile", cfgFile, RegistryValueKind.String);
                //}

                developmentKey.SetValue("CfgFile", "http://acss.alleg.net/allegiance.txt", RegistryValueKind.String);

                developmentKey.SetValue("ProductionCfgFile", "http://acss.alleg.net/allegiance.txt", RegistryValueKind.String);

                developmentKey.SetValue("BetaCfgFile", "http://acss.alleg.net/allegiance-beta.txt", RegistryValueKind.String);

                stepCount++;

                //if (developmentKey.GetValue("CharacterName", null) == null)
                developmentKey.SetValue("CharacterName", String.Empty, RegistryValueKind.String);

                stepCount++;

                //if (developmentKey.GetValue("CombatFullscreenXSize", null) == null)
                developmentKey.SetValue("CombatFullscreenXSize", 800, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("CombatFullscreenYSize", null) == null)
                developmentKey.SetValue("CombatFullscreenYSize", 600, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("CombatXSize", null) == null)
                developmentKey.SetValue("CombatXSize", 800, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("CombatYSize", null) == null)
                developmentKey.SetValue("CombatYSize", 600, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("DeadZone", null) == null)
                developmentKey.SetValue("DeadZone", 30, RegistryValueKind.DWord);

                stepCount++;

                // Don't delete this, might re-add post beta.
                //string exePath = (String)developmentKey.GetValue("EXE Path", null);
                //if (exePath != null)
                //{
                //    if (developmentKey.GetValue("PreviousEXEPath", null) == null)
                //        developmentKey.SetValue("PreviousEXEPath", exePath, RegistryValueKind.String);
                //}

                developmentKey.SetValue("Lobby Path", this.Context.Parameters["targetpath"].TrimEnd('\\'), RegistryValueKind.String);

                stepCount++;

                developmentKey.SetValue("EXE Path", productionExePath, RegistryValueKind.String);

                stepCount++;

                //if (developmentKey.GetValue("Gamma", null) == null)
                developmentKey.SetValue("Gamma", 1.13, RegistryValueKind.String);

                stepCount++;

                //if (developmentKey.GetValue("HasTrained", null) == null)
                developmentKey.SetValue("HasTrained", 1, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("LogToFile", null) == null)
                developmentKey.SetValue("LogToFile", 1, RegistryValueKind.String);

                stepCount++;

                //if (developmentKey.GetValue("Music", null) == null)
                developmentKey.SetValue("Music", 1, RegistryValueKind.DWord);

                stepCount++;

                //if (developmentKey.GetValue("OutputDebugString", null) == null)
                developmentKey.SetValue("OutputDebugString", 1, RegistryValueKind.DWord);

                stepCount++;

                developmentKey.SetValue("ClientService", "https://acss.alleg.net/CSSServer/ClientService.svc", RegistryValueKind.String);

                stepCount++;

                developmentKey.SetValue("ManagementWebRoot", "http://acss.alleg.net", RegistryValueKind.String);

                stepCount++;

                try
                {
                    if (FileSystemAccess.DoesUserHaveAccessToDirectory(artPath, BuiltinUsersSID, System.Security.AccessControl.FileSystemRights.FullControl) == false)
                    {
                        FileSystemAccess.SetDirectoryAccessBySID(artPath, BuiltinUsersSID, System.Security.AccessControl.FileSystemRights.FullControl);
                    }
                }
                catch (Exception ex)
                {
                    this.Context.LogMessage(ex.ToString());

                    // Ignore security exceptions for Windows8 and up.
                    if (WindowsVersion < Windows8Version)
                    {
                        throw;
                    }

                    //if (WindowsVersion >= 6.2)
                    //{
                    //    if (MessageBox.Show("There was an error granting permissions to the BUILTIN\\User account to: " + artPath + "\r\n\r\nThis is specific to Windows 8, and can be ignored. Continue Installation?", "Permissions Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                    //        throw;
                    //}
                    //else
                    //    throw;
                }

                stepCount++;

                try
                {
                    if (FileSystemAccess.DoesUserHaveAccessToDirectory(productionExePath, BuiltinUsersSID, System.Security.AccessControl.FileSystemRights.FullControl) == false)
                    {
                        FileSystemAccess.SetDirectoryAccessBySID(productionExePath, BuiltinUsersSID, System.Security.AccessControl.FileSystemRights.FullControl);
                    }
                }
                catch (Exception ex)
                {
                    this.Context.LogMessage(ex.ToString());

                    // Ignore security exceptions for Windows8 and up.
                    if (WindowsVersion < Windows8Version)
                    {
                        throw;
                    }

                    //if (WindowsVersion >= 6.2)
                    //{
                    //    if (MessageBox.Show("There was an error granting permissions to the BUILTIN\\User account to: " + productionExePath + "\r\n\r\nThis is specific to Windows 8, and can be ignored. Continue Installation?", "Permissions Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                    //        throw;
                    //}
                    //else
                    //    throw;
                }

                stepCount++;

                try
                {
                    if (FileSystemAccess.DoesUserHaveAccessToDirectory(this.Context.Parameters["targetpath"], BuiltinUsersSID, System.Security.AccessControl.FileSystemRights.FullControl) == false)
                    {
                        FileSystemAccess.SetDirectoryAccessBySID(this.Context.Parameters["targetpath"], BuiltinUsersSID, System.Security.AccessControl.FileSystemRights.FullControl);
                    }
                }
                catch (Exception ex)
                {
                    this.Context.LogMessage(ex.ToString());

                    // Ignore security exceptions for Windows8 and up.
                    if (WindowsVersion < Windows8Version)
                    {
                        throw;
                    }

                    //if (WindowsVersion >= 6.2)
                    //{
                    //    if (MessageBox.Show("There was an error granting permissions to the BUILTIN\\User account to: " + this.Context.Parameters["targetpath"] + "\r\n\r\nThis is specific to Windows 8, and can be ignored. Continue Installation?", "Permissions Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                    //        throw;
                    //}
                    //else
                    //    throw;
                }

                stepCount++;

                CopyProgress copyProgressBeta = new CopyProgress();
                copyProgressBeta.TopMost = true;
                //copyProgress.MinimizeBox = false;
                copyProgressBeta.SourceDirectory = artPath;
                copyProgressBeta.TargetDirectory = Path.Combine(Path.Combine(this.Context.Parameters["targetpath"], LobbyType.Beta.ToString()), "Artwork");
                copyProgressBeta.LobbyType       = LobbyType.Beta;

                if (copyProgressBeta.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    throw new InstallException("Beta Artwork file copy was canceled.");
                }

                stepCount++;

                CopyProgress copyProgressProduction = new CopyProgress();
                copyProgressProduction.TopMost = true;
                //copyProgress.MinimizeBox = false;
                copyProgressProduction.SourceDirectory = artPath;
                copyProgressProduction.TargetDirectory = Path.Combine(Path.Combine(this.Context.Parameters["targetpath"], LobbyType.Production.ToString()), "Artwork");
                copyProgressProduction.LobbyType       = LobbyType.Production;

                if (copyProgressProduction.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    throw new InstallException("Production Artwork file copy was canceled.");
                }


                base.OnAfterInstall(savedState);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "Windows Version: " + WindowsVersion +
                    "\r\nStep Count: " + stepCount +
                    "\r\n\r\n" + ex.ToString(), "BetaInstall::OnAfterInstall() - Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }