Esempio n. 1
0
        static void Main(string[] args)
        {
            var weAreUACElevated = IsAdmin();
            if (args.Length == 1)
            {
                var log = File.OpenWrite(args[0]);
                var logWriter = new StreamWriter(log);
                Console.SetOut(logWriter);
            }

            var installers = new IInstaller[]
            {
                new InstallVCRedist2010_x86(),
                new InstallVCRedists2012_x86(),
                new InstallVCRedists2013_x86(), 
            };

            var installers64Bit = new IInstaller[]
            {
                new InstallVCRedist2010_x64(),
                new InstallVCRedists2012_x64(),
                new InstallVCRedists2013_x64()
            };

            if (IntPtr.Size == 8)
                installers = installers.Concat(installers64Bit).ToArray();

            try
            {
                foreach (var installer in installers)
                {
                    if (!installer.IsInstalled())
                    {
                        if (!weAreUACElevated)
                        {
                            EvaluateOurself(Path.GetTempFileName());
                            break;
                        }
                        else
                        {
                            installer.Install(true,
                                              new Progress<RedistInstallationProgressEvent>(a =>
                                              {
                                                  Console.WriteLine(a.Percentage);
                                              }));
                        }
                    }
                }
            }
            catch (ExitWithCode e)
            {
                Environment.Exit(e.ExitCode);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                Environment.Exit(1);
            }
            finally
            {
                Console.Out.Flush();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var weAreUACElevated = IsAdmin();

            if (args.Length == 1)
            {
                var log       = File.OpenWrite(args[0]);
                var logWriter = new StreamWriter(log);
                Console.SetOut(logWriter);
            }

            var installers = new IInstaller[]
            {
                new InstallVCRedist2010_x86(),
                new InstallVCRedists2012_x86(),
                new InstallVCRedists2013_x86(),
            };

            var installers64Bit = new IInstaller[]
            {
                new InstallVCRedist2010_x64(),
                new InstallVCRedists2012_x64(),
                new InstallVCRedists2013_x64()
            };

            if (IntPtr.Size == 8)
            {
                installers = installers.Concat(installers64Bit).ToArray();
            }

            try
            {
                foreach (var installer in installers)
                {
                    if (!installer.IsInstalled())
                    {
                        if (!weAreUACElevated)
                        {
                            EvaluateOurself(Path.GetTempFileName());
                            break;
                        }
                        else
                        {
                            installer.Install(true,
                                              new Progress <RedistInstallationProgressEvent>(a =>
                            {
                                Console.WriteLine(a.Percentage);
                            }));
                        }
                    }
                }
            }
            catch (ExitWithCode e)
            {
                Environment.Exit(e.ExitCode);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                Environment.Exit(1);
            }
            finally
            {
                Console.Out.Flush();
            }
        }