예제 #1
0
        //setGenocide creates the files in Local Appdata to set the game into a Genocide state
        public static void setGenocide(GenocideStates state)
        {
            File.Delete(Constants.AppdataPath + "system_information_963");
            File.Delete(Constants.AppdataPath + "system_information_962");

            switch (state)
            {
            case GenocideStates.Soulless:
                if (!File.Exists(Constants.AppdataPath + "system_information_963"))
                {
                    File.Create(Constants.AppdataPath + "system_information_963").Dispose();
                }
                goto case GenocideStates.Abyss;

            case GenocideStates.Abyss:
                if (!File.Exists(Constants.AppdataPath + "system_information_962"))
                {
                    File.Create(Constants.AppdataPath + "system_information_962").Dispose();
                }
                break;

            case GenocideStates.None:
                File.Create(Constants.AppdataPath + "system_information_963").Dispose();
                File.Create(Constants.AppdataPath + "system_information_962").Dispose();

                System.Security.AccessControl.FileSecurity readDeny = new System.Security.AccessControl.FileSecurity();
                readDeny.SetAccessRule(new System.Security.AccessControl.FileSystemAccessRule(
                                           new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null),
                                           System.Security.AccessControl.FileSystemRights.Read,
                                           System.Security.AccessControl.AccessControlType.Deny));

                System.Security.AccessControl.FileSecurity readDenyTwo = new System.Security.AccessControl.FileSecurity();
                readDenyTwo.SetAccessRule(new System.Security.AccessControl.FileSystemAccessRule(
                                              new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null),
                                              System.Security.AccessControl.FileSystemRights.Read,
                                              System.Security.AccessControl.AccessControlType.Deny));

                System.IO.File.SetAccessControl(Constants.AppdataPath + "system_information_963", readDeny);
                System.IO.File.SetAccessControl(Constants.AppdataPath + "system_information_962", readDenyTwo);
                break;
            }
        }
        /// <summary>
        /// The install controller requires that the process is elevated (aka Run as Administrator).
        /// The log files are created by this administrative account.
        /// Any non-admin account will NOT have permissions to write to these log files.
        /// By adding full control to "Everyone", the non-admin service can write to these logs.
        /// </summary>
        private void EnsureEveryoneHasPermissionsToWriteToLogFiles()
        {
            _installLog.Debug("Resetting permissions on all log files");

            const string log4NetConfig = "log4net.config";
            var assemblyPath = Assembly.GetExecutingAssembly().GetLocalPath();
            var configPath = Path.Combine(assemblyPath, log4NetConfig);
            var log4netConfig = File.ReadAllText(configPath);

            var matches = Regex.Matches(log4netConfig, @"<param name=""File"" value=""(?<logPath>[^""]+)""\s*/>", RegexOptions.ExplicitCapture);
            foreach (var logPath in matches.Cast<Match>().Select(m => m.Groups["logPath"].Value))
            {
                if (!File.Exists(logPath))
                {
                    _installLog.WarnFormat("Attempting to reset permissions for log file but it is missing at '{0}'", logPath);
                    continue;
                }

                try
                {
                    var fileSecurity = new FileSecurity(logPath, AccessControlSections.Access);
                    var everyoneSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                    fileSecurity.SetAccessRule(new FileSystemAccessRule(everyoneSid, FileSystemRights.FullControl, AccessControlType.Allow));
                    File.SetAccessControl(logPath, fileSecurity);
                    _installLog.DebugFormat("Reset permissions on '{0}'", logPath);
                }
                catch (Exception e)
                {
                    _installLog.Error(string.Format("Failed to reset permissions on '{0}'", logPath), e);
                }
            }
        }
예제 #3
0
        void MyInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            StringBuilder path = new StringBuilder(260);
            SHGetSpecialFolderPath(IntPtr.Zero, path, 5, false);

            string p_addinOrg = this.Context.Parameters["path"] + @"ASEExpertVS2005.AddIn";
            string p_addin2005 = path.ToString() + @"\Visual Studio 2005\Addins\ASEExpertVS2005.AddIn";
            string p_addin2008 = path.ToString() + @"\Visual Studio 2008\Addins\ASEExpertVS2005.AddIn";
            string p_addin2010 = path.ToString() + @"\Visual Studio 2010\Addins\ASEExpertVS2005.AddIn";
            string p_dll = this.Context.Parameters["path"] + "ASEExpertVS2005.dll";
            XmlDocument xd;
            XmlNode node;

            try
            {
                if (this.Context.Parameters["cboxval1"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2005\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2005\Addins");

                    if (File.Exists(p_addin2005))
                        File.Delete(p_addin2005);

                    System.IO.File.Copy(p_addinOrg, p_addin2005);
                    xd = new XmlDocument();
                    xd.Load(p_addin2005);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    xd.Save(p_addin2005);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #1: " + exc.Message);
            }

            try
            {
                if (this.Context.Parameters["cboxval2"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2008\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2008\Addins");

                    if (File.Exists(p_addin2008))
                        File.Delete(p_addin2008);

                    System.IO.File.Copy(p_addinOrg, p_addin2008);
                    xd = new XmlDocument();
                    xd.Load(p_addin2008);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    foreach (XmlNode item in xd["Extensibility"].ChildNodes)
                        if (item.Name == "HostApplication")
                            item["Version"].InnerText = "9.0";
                    xd.Save(p_addin2008);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #2: " + exc.Message);
            }

            try
            {
                if (this.Context.Parameters["cboxval3"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2010\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2010\Addins");

                    if (File.Exists(p_addin2010))
                        File.Delete(p_addin2010);

                    System.IO.File.Copy(p_addinOrg, p_addin2010);
                    xd = new XmlDocument();
                    xd.Load(p_addin2010);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    foreach (XmlNode item in xd["Extensibility"].ChildNodes)
                        if (item.Name == "HostApplication")
                            item["Version"].InnerText = "10.0";
                    xd.Save(p_addin2010);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #3: " + exc.Message);
            }

            try
            {
                Assembly asm = Assembly.LoadFile(p_dll);

                string csp = File.ReadAllText(this.Context.Parameters["path"] + @"ASEExpertVS2005.Sample\ASEExpertVS2005.Sample.csproj", Encoding.UTF8);
                csp = csp.Replace("ASEExpertVS2005, Version=1.0.2904.23426", "ASEExpertVS2005, Version=" + asm.GetName().Version.ToString());
                csp = csp.Replace(@"<HintPath>..\ASEExpertVS2005\bin\ASEExpertVS2005.dll</HintPath>",
                    "<HintPath>" + p_dll + "</HintPath>");

                File.WriteAllText(this.Context.Parameters["path"] + @"ASEExpertVS2005.Sample\ASEExpertVS2005.Sample.csproj", csp, Encoding.UTF8);
                //<Reference Include="ASEExpertVS2005, Version=1.0.2904.23426, Culture=neutral, processorArchitecture=MSIL">
                //  <SpecificVersion>False</SpecificVersion>
                //  <HintPath>..\..\..\Program Files\ASE\ASE Expert VS2005\ASEExpertVS2005.dll</HintPath>
                //</Reference>

                DirectorySecurity ds = new DirectorySecurity();
                FileSystemAccessRule ar = new FileSystemAccessRule(
                    Environment.UserName,
                    FileSystemRights.FullControl,
                    AccessControlType.Allow);

                ds.SetAccessRule(ar);
                System.IO.Directory.CreateDirectory(this.Context.Parameters["path"] + "en-US", ds);

                FileSecurity fs = new FileSecurity();
                fs.SetAccessRule(ar);
                FileStream fsm = File.Create(this.Context.Parameters["path"] + "user.config", 1, FileOptions.None, fs);
                fsm.Close();
                StreamWriter tw = new StreamWriter(this.Context.Parameters["path"] + "user.config");
                tw.WriteLine("<ASE.Tools.XmlIni>");
                tw.WriteLine("  <Plugins>");
                tw.WriteLine("  </Plugins>");
                tw.WriteLine("</ASE.Tools.XmlIni>");
                tw.Close();
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #4: " + exc.Message);
            }
        }
 private void CopyMiscellaneousFiles(IEnumerable<string> keys)
 {
     var fileSecurity = new FileSecurity();
     fileSecurity.SetAccessRule(fileSystemAccessRule);
     foreach (string key in keys.Where(x => x.EndsWith("_FILE")))
     {
         string path = Context.Parameters[key];
         string destFileName = DestinationFilename(path);
         File.Copy(path, destFileName, true);
         File.SetAccessControl(destFileName, fileSecurity);
     }
 }
예제 #5
0
		/// <summary>
		/// Setzt volle Zugriffsrechte für eine Datei für den angemeldeten Benutzer.
		/// </summary>
		/// <param name="filename">Die Datei von welcher die Zugriffsrechte geändert werden sollen.</param>
		/// <returns>Gibt 'True' zurück wenn die Zugriffsrechte erfolgreich gesetzt wurden, andernfalls 'False'.</returns>
		protected bool SetFileAccessControl(string filename) {
			try {
				var fs = new FileSecurity();
				var fs_rule = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, FileSystemRights.FullControl,
				                                       AccessControlType.Allow);

				fs.SetAccessRule(fs_rule);

				File.SetAccessControl(filename, fs);

				return true;
			}
			catch {
				return false;
			}
		}