예제 #1
0
        internal static void LogException(Exception e, InstallContext context)
        {
            bool flag = true;

            for (; e != null; e = e.InnerException)
            {
                if (flag)
                {
                    context.LogMessage(e.GetType().FullName + ": " + e.Message);
                    flag = false;
                }
                else
                {
                    context.LogMessage(Res.GetString("InstallLogInner", (object)e.GetType().FullName, (object)e.Message));
                }
                if (context.IsParameterTrue("showcallstack"))
                {
                    context.LogMessage(e.StackTrace);
                }
            }
        }
예제 #2
0
        /// <include file='doc\Installer.uex' path='docs/doc[@for="Installer.LogException"]/*' />
        /// <devdoc>
        /// Writes exception information for the given inner exception and any
        /// inner exceptions it may have to the given context object.
        /// </devdoc>
        internal static void LogException(Exception e, InstallContext context)
        {
            bool toplevel = true;

            while (e != null)
            {
                if (toplevel)
                {
                    context.LogMessage(e.GetType().FullName + ": " + e.Message);
                    toplevel = false;
                }
                else
                {
                    context.LogMessage(Res.GetString(Res.InstallLogInner, e.GetType().FullName, e.Message));
                }
                if (context.IsParameterTrue("showcallstack"))
                {
                    context.LogMessage(e.StackTrace);
                }
                e = e.InnerException;
            }
        }
 internal static void LogException(Exception e, InstallContext context)
 {
     bool flag = true;
     while (e != null)
     {
         if (flag)
         {
             context.LogMessage(e.GetType().FullName + ": " + e.Message);
             flag = false;
         }
         else
         {
             context.LogMessage(Res.GetString("InstallLogInner", new object[] { e.GetType().FullName, e.Message }));
         }
         if (context.IsParameterTrue("showcallstack"))
         {
             context.LogMessage(e.StackTrace);
         }
         e = e.InnerException;
     }
 }
예제 #4
0
        // Load an assembly by name and get the information object for it.
        internal static AssemblyInfo LoadInstallerAssembly
            (String filename, InstallContext logContext)
        {
            String       fullName;
            AssemblyInfo info;

            AssemblyInfo[] newAssemblies;
            int            index;

            lock (typeof(AssemblyInstaller))
            {
                try
                {
                    // See if we have a cached information block,
                    // from when we loaded the assembly previously.
                    fullName = IO.Path.GetFullPath(filename);
                    if (assemblies != null)
                    {
                        for (index = 0; index < assemblies.Length; ++index)
                        {
                            info = assemblies[index];
                            if (info.filename == fullName)
                            {
                                if (info.loadException == null)
                                {
                                    return(info);
                                }
                                throw info.loadException;
                            }
                        }
                        newAssemblies = new AssemblyInfo
                                        [assemblies.Length + 1];
                        Array.Copy(assemblies, 0, newAssemblies, 0,
                                   assemblies.Length);
                        info = new AssemblyInfo();
                        newAssemblies[assemblies.Length] = info;
                        assemblies = newAssemblies;
                    }
                    else
                    {
                        info       = new AssemblyInfo();
                        assemblies = new AssemblyInfo [] { info };
                    }

                    // Try to load the assembly into memory.
                    info.filename = fullName;
                    try
                    {
                        info.assembly = Assembly.LoadFrom(fullName);
                    }
                    catch (SystemException e)
                    {
                        info.loadException = e;
                        throw;
                    }

                    // Wrap the assembly in an installer.
                    info.installer = new AssemblyInstaller();
                    info.installer.assemblyPath = filename;
                    info.installer.info         = info;

                    // Search for all public installer types.
                    LoadInstallers(info);

                    // The assembly is ready to go.
                    return(info);
                }
                catch (SystemException e)
                {
                    if (logContext != null)
                    {
                        if (logContext.IsParameterTrue("ShowCallStack"))
                        {
                            logContext.LogLine
                                ("LoadAssembly: " + e.ToString());
                        }
                        else
                        {
                            logContext.LogLine
                                ("LoadAssembly: " + e.Message);
                        }
                    }
                    throw new InvalidOperationException
                              (String.Format
                                  (S._("Installer_CouldNotLoadAssembly"),
                                  filename), e);
                }
            }
        }
	// Run the installation process.
	private int Install()
			{
				// Scan the command-line options in groups.
				int posn = 0;
				int start;
				String arg;
				bool both;
				uninstall = false;
				if(args.Length == 0)
				{
					Usage();
					return 1;
				}
				while(posn < args.Length)
				{
					// Extract the next group of options.
					start = posn;
					while(posn < args.Length)
					{
						arg = args[posn];
						if(arg.Length == 0)
						{
							break;
						}
						if(arg[0] == '-')
						{
							// Option that starts with "-".
							++posn;
							if(arg.Length == 2 && arg[1] == '-')
							{
								// We use "--" to terminate the option
								// list just prior to a filename that
								// starts with "-" or "/".
								break;
							}
						}
						else if(arg[0] == '/')
						{
							// Compatibility option that starts with "/".
							++posn;
						}
						else if(arg[0] == '=')
						{
							// May be specifying a value for a previous option.
							++posn;
						}
						else if(posn > start && args[posn - 1].EndsWith("="))
						{
							// Specifying a value for a previous option name.
							++posn;
						}
						else
						{
							// This is a filename.
							break;
						}
					}

					// Parse the command line options that we just received.
					optionDict = InstallContext.ParseCommandLine
						(args, start, posn - start, out options);

					// Extract the filename.
					if(posn < args.Length)
					{
						filename = args[posn++];
					}
					else
					{
						filename = null;
					}

					// Create an install context for this option group.
					context = new InstallContext(optionDict);

					// Check for the "uninstall" and "install" flags.
					both = false;
					if(context.IsParameterTrue("uninstall") ||
					   context.IsParameterTrue("u"))
					{
						uninstall = true;
						both = true;
					}
					if(context.IsParameterTrue("install") ||
					   context.IsParameterTrue("i"))
					{
						if(both)
						{
						#if !CONFIG_SMALL_CONSOLE
							Console.Error.WriteLine
								("{0}: cannot specify both `--install' and " +
								 "`--uninstall'", program);
						#else
							Console.WriteLine
								("{0}: cannot specify both `--install' and " +
								 "`--uninstall'", program);
						#endif
							return 1;
						}
						uninstall = false;
					}

					// Check for the version flag.
					if(context.IsParameterTrue("version") ||
					   context.IsParameterTrue("v"))
					{
						Version();
						return 0;
					}

					// Check for the help flag.
					if(context.IsParameterTrue("help") ||
					   context.IsParameterTrue("h") ||
					   context.IsParameterTrue("?"))
					{
						if(filename == null)
						{
							Usage();
						}
						else
						{
							PrintHelpFor(filename);
						}
						continue;
					}

					// If we don't have a filename, then print the usage.
					if(filename == null)
					{
						Usage();
						return 1;
					}

					// Run the installation/uninstallation process.
					if(uninstall)
					{
						RunUninstall(filename);
					}
					else
					{
						RunInstall(filename);
					}
				}
				return 0;
			}
예제 #6
0
        // Run the installation process.
        private int Install()
        {
            // Scan the command-line options in groups.
            int    posn = 0;
            int    start;
            String arg;
            bool   both;

            uninstall = false;
            if (args.Length == 0)
            {
                Usage();
                return(1);
            }
            while (posn < args.Length)
            {
                // Extract the next group of options.
                start = posn;
                while (posn < args.Length)
                {
                    arg = args[posn];
                    if (arg.Length == 0)
                    {
                        break;
                    }
                    if (arg[0] == '-')
                    {
                        // Option that starts with "-".
                        ++posn;
                        if (arg.Length == 2 && arg[1] == '-')
                        {
                            // We use "--" to terminate the option
                            // list just prior to a filename that
                            // starts with "-" or "/".
                            break;
                        }
                    }
                    else if (arg[0] == '/')
                    {
                        // Compatibility option that starts with "/".
                        ++posn;
                    }
                    else if (arg[0] == '=')
                    {
                        // May be specifying a value for a previous option.
                        ++posn;
                    }
                    else if (posn > start && args[posn - 1].EndsWith("="))
                    {
                        // Specifying a value for a previous option name.
                        ++posn;
                    }
                    else
                    {
                        // This is a filename.
                        break;
                    }
                }

                // Parse the command line options that we just received.
                optionDict = InstallContext.ParseCommandLine
                                 (args, start, posn - start, out options);

                // Extract the filename.
                if (posn < args.Length)
                {
                    filename = args[posn++];
                }
                else
                {
                    filename = null;
                }

                // Create an install context for this option group.
                context = new InstallContext(optionDict);

                // Check for the "uninstall" and "install" flags.
                both = false;
                if (context.IsParameterTrue("uninstall") ||
                    context.IsParameterTrue("u"))
                {
                    uninstall = true;
                    both      = true;
                }
                if (context.IsParameterTrue("install") ||
                    context.IsParameterTrue("i"))
                {
                    if (both)
                    {
                                                #if !CONFIG_SMALL_CONSOLE
                        Console.Error.WriteLine
                            ("{0}: cannot specify both `--install' and " +
                            "`--uninstall'", program);
                                                #else
                        Console.WriteLine
                            ("{0}: cannot specify both `--install' and " +
                            "`--uninstall'", program);
                                                #endif
                        return(1);
                    }
                    uninstall = false;
                }

                // Check for the version flag.
                if (context.IsParameterTrue("version") ||
                    context.IsParameterTrue("v"))
                {
                    Version();
                    return(0);
                }

                // Check for the help flag.
                if (context.IsParameterTrue("help") ||
                    context.IsParameterTrue("h") ||
                    context.IsParameterTrue("?"))
                {
                    if (filename == null)
                    {
                        Usage();
                    }
                    else
                    {
                        PrintHelpFor(filename);
                    }
                    continue;
                }

                // If we don't have a filename, then print the usage.
                if (filename == null)
                {
                    Usage();
                    return(1);
                }

                // Run the installation/uninstallation process.
                if (uninstall)
                {
                    RunUninstall(filename);
                }
                else
                {
                    RunInstall(filename);
                }
            }
            return(0);
        }
	// Load an assembly by name and get the information object for it.
	internal static AssemblyInfo LoadInstallerAssembly
				(String filename, InstallContext logContext)
			{
				String fullName;
				AssemblyInfo info;
				AssemblyInfo[] newAssemblies;
				int index;
				lock(typeof(AssemblyInstaller))
				{
					try
					{
						// See if we have a cached information block,
						// from when we loaded the assembly previously.
						fullName = IO.Path.GetFullPath(filename);
						if(assemblies != null)
						{
							for(index = 0; index < assemblies.Length; ++index)
							{
								info = assemblies[index];
								if(info.filename == fullName)
								{
									if(info.loadException == null)
									{
										return info;
									}
									throw info.loadException;
								}
							}
							newAssemblies = new AssemblyInfo
								[assemblies.Length + 1];
							Array.Copy(assemblies, 0, newAssemblies, 0,
									   assemblies.Length);
							info = new AssemblyInfo();
							newAssemblies[assemblies.Length] = info;
							assemblies = newAssemblies;
						}
						else
						{
							info = new AssemblyInfo();
							assemblies = new AssemblyInfo [] {info};
						}

						// Try to load the assembly into memory.
						info.filename = fullName;
						try
						{
							info.assembly = Assembly.LoadFrom(fullName);
						}
						catch(SystemException e)
						{
							info.loadException = e;
							throw;
						}

						// Wrap the assembly in an installer.
						info.installer = new AssemblyInstaller();
						info.installer.assemblyPath = filename;
						info.installer.info = info;

						// Search for all public installer types.
						LoadInstallers(info);

						// The assembly is ready to go.
						return info;
					}
					catch(SystemException e)
					{
						if(logContext != null)
						{
							if(logContext.IsParameterTrue("ShowCallStack"))
							{
								logContext.LogLine
									("LoadAssembly: " + e.ToString());
							}
							else
							{
								logContext.LogLine
									("LoadAssembly: " + e.Message);
							}
						}
						throw new InvalidOperationException
							(String.Format
								(S._("Installer_CouldNotLoadAssembly"),
								 filename), e);
					}
				}
			}