Settings is an class that holds CS-Script application settings.
示例#1
0
        public CSScriptInstaller(bool quiet, bool update)
        {
            //System.Diagnostics.Debug.Assert(false);
            this.quiet = quiet;

            //analyse previous installations
            bool oldVersionInstalled = CSScriptInstaller.IsInstalled() && update;

            ArrayList oldMenus = new ArrayList();
            string oldDblClickAction = "";
            string oldClrVersion = "";
            string oldHomeDir = "";
            string oldConfigFile = "";

            bool runningAsScript = Environment.GetEnvironmentVariable("CSScriptRuntime") != null &&
                                    Environment.GetEnvironmentVariable("CSScriptDebugging") == null;

            if (oldVersionInstalled)
            {
                oldHomeDir = GetEnvironmentVariable("CSSCRIPT_DIR");
                if (Path.GetFullPath(oldHomeDir) == Path.GetFullPath(CSScriptInstaller.GetExecutingEngineDir()))
                    oldVersionInstalled = false;
                else
                {
                    GetCurrentConfig(oldMenus, ref oldDblClickAction);

                    //oldClrVersion = GetTargetCLRVersion(Path.Combine(oldHomeDir, "cscs.exe.config")); //CLR versions are not supported any more
                }
            }

            try
            {
                using (RegistryKey envVars = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", true)) { }

                using (RegistryKey csReadOnly = Registry.ClassesRoot.OpenSubKey(".cs", false))
                    if (csReadOnly != null)
                        using (RegistryKey csWritable = Registry.ClassesRoot.OpenSubKey(".cs", true)) { }
            }
            catch
            {
                restrictedMode = true;
            }

            string scHomeDir = GetEnvironmentVariable("CSSCRIPT_DIR");
            bool preventMigration = false;
            #if CSS_PROJECT
            preventMigration = true; //we are running the script under VS
            #endif
            if (scHomeDir == null)
            {
                if (restrictedMode)
                    throw new Exception("CS-Script cannot be installed on this PC.\nYour current login does not allow you to change the system configuration.\n" +
                                        "Please login as a different user (with higher security level) and start the configuraion console again.");

                Install(true);

                string editor = GetNotepadPP();
                if (editor != null)
                    doubleClickAction = "\"" + editor + "\" \"%1\""; //default value
                else
                    doubleClickAction = ConfigForm.DoubleClickNotepadAction;

                scHomeDir = GetEnvironmentVariable("CSSCRIPT_DIR");
                MergeLocalIncluds(scHomeDir);
            }
            else if (string.Compare(GetExecutingEngineDir(), GetEnvironmentVariable("CSSCRIPT_DIR"), true) != 0 && !preventMigration)
            {
                bool deadInstallationDetected = false;
                try
                {
                    if (!Directory.Exists(GetEnvironmentVariable("CSSCRIPT_DIR")))
                        deadInstallationDetected = true;
                }
                catch { }

                string msg = "This configuration console corresponds to the CS-Script engine located in '" + GetExecutingEngineDir() + "'.\n" +
                    "However another copy of the CS-Script engine is currently installed on this computer ('" + GetEnvironmentVariable("CSSCRIPT_DIR") + "').\n\n";

                if (restrictedMode)
                    throw new Exception(msg + "Please run the configuration console from correct location.");

                if (quiet || deadInstallationDetected ||
                    DialogResult.OK == ShowMessageBox(msg +
                    "Please, press Ok if you want to activate the script engine from '" + GetExecutingEngineDir() + "' instead of the currently installed one.",
                    "CS-Script Configuration", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2))
                {
                    if (!quiet) SplashScreen.ShowSplash("CS-Script", "Please wait while CS-Script is being configured...");

                    oldConfigFile = ConfigFile;
                    bool doShellExt = GetComShellExtRegisteredDll() != null;
                    UnInstall();
                    Install(doShellExt);

                    this.ShellExtensionHasMoved = true;

                    scHomeDir = GetEnvironmentVariable("CSSCRIPT_DIR");
                    MergeLocalIncluds(scHomeDir);
                }
                else
                    throw new Exception("Operation cancelled by user.");
            }

            if (File.Exists(ConfigFile)) //installed
            {
                if (oldConfigFile != "" && File.Exists(oldConfigFile)) //previous installation config is available
                    settings = Settings.Load(oldConfigFile);
                else
                    settings = Settings.Load(ConfigFile);

                if (update)
                {
                    if (settings.DefaultArguments.IndexOf("/sconfig") == -1)
                    {
                        settings.DefaultArguments += " /sconfig"; //do it manualy for now but in future insure all new default DefaultArgs are added
                        settings.Save(ConfigFile);
                    }
                }
            }
            else
            {
                settings = new Settings();
                settings.Save(ConfigFile);

                if (File.Exists(Path.Combine(scHomeDir, @"Lib\clearTemp.cs")))
                    settings.CleanupShellCommand = "csws.exe clearTemp.cs";

                if (IsLightVersion)
                {
                    settings.UseAlternativeCompiler = "";
                }
                else
                {
                    if (File.Exists(Path.Combine(scHomeDir, @"Lib\CSSCodeProvider.dll")))
                        settings.UseAlternativeCompiler = @"%CSSCRIPT_DIR%\Lib\CSSCodeProvider.dll";

                    try
                    {
                        Version availableVer = GetHighestNetVersion();
                        if (File.Exists(Path.Combine(scHomeDir, @"Lib\CSSCodeProvider.dll"))
                            && availableVer.Major >= 3
                            && availableVer.Minor >= 5)
                        {
                            settings.UseAlternativeCompiler = @"%CSSCRIPT_DIR%\Lib\CSSCodeProvider.dll";
                        }
                    }
                    catch { }
                }
            }

            //CLR versions are not supported any more
            //if (!File.Exists(Path.Combine(HomeDir, "cscs.exe.config")))
            //{
            //CreateDefaultConfig(Path.Combine(HomeDir, "cscs.exe.config"));
            //CreateDefaultConfig(Path.Combine(HomeDir, "csws.exe.config"));
            //}
            GetCurrentConfig(this.contextMenus, ref doubleClickAction);
            targetCLRVersion = new CLRVersion(GetTargetCLRVersion(null));

            if (oldVersionInstalled)
            {
                for (int i = 0; i < oldMenus.Count; i++)
                    ((ContextMenuInfo)this.contextMenus[i]).Enabled = ((ContextMenuInfo)oldMenus[i]).Enabled;

                this.doubleClickAction = oldDblClickAction;
                this.targetCLRVersion.Version = oldClrVersion;

                UpdateFromInstallation(settings, oldHomeDir);

                //reset some defaults
                //if (settings.CleanupShellCommand == "" && File.Exists(Path.Combine(scHomeDir, @"Lib\clearTemp.cs")))
                //	settings.CleanupShellCommand = "csws.exe clearTemp.cs";

                //if (settings.UseAlternativeCompiler == "" && File.Exists(Path.Combine(scHomeDir, @"Lib\CSSCodeProvider.dll")))
                //	settings.UseAlternativeCompiler = Path.Combine(scHomeDir, @"Lib\CSSCodeProvider.dll");

                Update();
                CSScriptInstaller.justInstalled = false;
            }
        }
示例#2
0
文件: cfbuild.cs 项目: Diullei/Storm
        static void GenerateConfigFile()
        {
            if (File.Exists(configFile))
                File.Delete(configFile);

            string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
            string message =
                "The location of the Compact Framework assemblies is unknown at this stage.\n\n" +
                "Please press OK to specify the assemblies folder.\n" +
                "You need to do this only once. If you need to change the selection later \n" +
                "just run cfbuild.cs with /r switch.\n\n" +
                "These are the usual locations:\n" +
                "  " + programFiles + @"\Microsoft.NET\SDK\CompactFramework\v1.0\WindowsCE" + "\n" +
                "  " + programFiles + @"\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE" + "\n" +
                "  " + programFiles + @"\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE" + "\n" +
                "  " + programFiles + @"\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\1.0\WindowsCE" + "\n" +
                "  " + programFiles + @"\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\WindowsCE";
            DialogResult response = MessageBox.Show(message, "CS-Script", MessageBoxButtons.OKCancel);
            if (response == DialogResult.OK)
            {
                using (FolderBrowserDialog dlg = new FolderBrowserDialog())
                {
                    dlg.Description = "Select the Compact Framework assemblies folder.";
                    dlg.ShowNewFolderButton = false;

                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        Settings settings = new Settings();
                        settings.SearchDirs += ";" + dlg.SelectedPath;
                        settings.Save(configFile);
                    }
                    else
                        throw new Exception("Operation canceled by user");
                }
            }
            else
                throw new Exception("Operation canceled by user");
        }
示例#3
0
        /// <summary>
        /// Loads CS-Script application settings from a file.
        /// </summary>
        /// <param name="fileName">File name of the XML file</param>
        /// <param name="createAlways">Create and return default settings object if it cannot be loaded from the file.</param>
        /// <returns>Setting object deserialized from the XML file</returns>
        public static Settings Load(string fileName, bool createAlways)
        {
            Settings settings = new Settings();
            if (File.Exists(fileName))
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fileName);
                    XmlNode data = doc.FirstChild;
                    settings.defaultArguments = data.SelectSingleNode("defaultArguments").InnerText;
                    settings.defaultApartmentState = (ApartmentState)Enum.Parse(typeof(ApartmentState), data.SelectSingleNode("defaultApartmentState").InnerText, false);
                    settings.reportDetailedErrorInfo = data.SelectSingleNode("reportDetailedErrorInfo").InnerText.ToLower() == "true";
                    settings.UseAlternativeCompiler = data.SelectSingleNode("useAlternativeCompiler").InnerText;
                    settings.UsePostProcessor = data.SelectSingleNode("usePostProcessor").InnerText;
                    settings.SearchDirs = data.SelectSingleNode("searchDirs").InnerText;
                    settings.cleanupShellCommand = data.SelectSingleNode("cleanupShellCommand").InnerText;
                    settings.doCleanupAfterNumberOfRuns = uint.Parse(data.SelectSingleNode("doCleanupAfterNumberOfRuns").InnerText);
                    settings.hideOptions = (HideOptions)Enum.Parse(typeof(HideOptions), data.SelectSingleNode("hideOptions").InnerText, true);
                    settings.hideCompilerWarnings = data.SelectSingleNode("hideCompilerWarnings").InnerText.ToLower() == "true";
                    settings.inMemoryAsm = data.SelectSingleNode("inMemoryAsm").InnerText.ToLower() == "true";
                    settings.TargetFramework = data.SelectSingleNode("TragetFramework").InnerText;
                    settings.defaultRefAssemblies = data.SelectSingleNode("defaultRefAssemblies").InnerText;
                    settings.useSurrogatepHostingProcess = data.SelectSingleNode("useSurrogatepHostingProcess").InnerText.ToLower() == "true";
                    settings.OpenEndDirectiveSyntax = data.SelectSingleNode("openEndDirectiveSyntax").InnerText.ToLower() == "true";
                    settings.Precompiler = data.SelectSingleNode("Precompiler").InnerText;
                    settings.CustomHashing = data.SelectSingleNode("CustomHashing").InnerText.ToLower() == "true";
                    settings.ConsoleEncoding = data.SelectSingleNode("ConsoleEncoding").InnerText;
                }
                catch
                {
                    if (!createAlways)
                        settings = null;
                    else
                        settings.Save(fileName);
                }

                CSharpParser.OpenEndDirectiveSyntax = settings.OpenEndDirectiveSyntax;
            }
            return settings;
        }
示例#4
0
		/// <summary>
		/// Loads CS-Script application settings from a file.
		/// </summary>
		/// <param name="fileName">File name of the XML file</param>
		/// <param name="createAlways">Create and return default settings object if it cannot be loaded from the file.</param>
		/// <returns>Setting object deserialized from the XML file</returns>
		public static Settings Load(string fileName, bool createAlways)
		{
			Settings settings = new Settings();
			if (File.Exists(fileName))
			{
				try
				{
					XmlDocument doc = new XmlDocument();
					doc.Load(fileName);
					XmlNode data = doc.FirstChild;
					settings.defaultArguments = data.SelectSingleNode("defaultArguments").InnerText;
					settings.defaultApartmentState = (ApartmentState)Enum.Parse(typeof(ApartmentState), data.SelectSingleNode("defaultApartmentState").InnerText, false);
					settings.reportDetailedErrorInfo = data.SelectSingleNode("reportDetailedErrorInfo").InnerText.ToLower() == "true";
					settings.UseAlternativeCompiler = data.SelectSingleNode("useAlternativeCompiler").InnerText;
					settings.extraLibDirectory = data.SelectSingleNode("extraLibDirectory").InnerText;
					settings.cleanupShellCommand = data.SelectSingleNode("cleanupShellCommand").InnerText;
					settings.doCleanupAfterNumberOfRuns = uint.Parse(data.SelectSingleNode("doCleanupAfterNumberOfRuns").InnerText);
					settings.hideOptions = (HideOptions)Enum.Parse(typeof(HideOptions), data.SelectSingleNode("hideOptions").InnerText, true);
					settings.hideCompilerWarnings = data.SelectSingleNode("hideCompilerWarnings").InnerText.ToLower() == "true";
				}
				catch
				{
					if (!createAlways)
						settings = null;
				}
			}
			return settings;
		}