示例#1
0
        private static void UpdatePluginConfiguration(Component component, string destination, CommandLineSwitches switches)
        {
            foreach (var componentLibrary in component.Libraries)
            {
                ActConfigurationHelper.AddPlugin(Path.Combine(destination, componentLibrary));
            }

            if (component.Configurations == null)
            {
                return;
            }

            bool?result = null;

            foreach (var componentConfiguration in component.Configurations)
            {
                var url             = componentConfiguration.Key;
                var confDestination = componentConfiguration.Value;

                ActConfigurationHelper.SaveConfiguration(url, confDestination, onDuplicatd: _ =>
                {
                    if (result.HasValue)
                    {
                        return(result != null && result.Value);
                    }

                    return(Iterate(__ =>
                    {
                        result = YesOrNoIteration();
                        return result != null && result.Value;
                    }, switches, $"##### Do you want to overwrite the existing configuration for {component.Name}? [Y/n] ",
                                   DefaultIterationErrorMessage));
                });
            }
        }
示例#2
0
        private static void Main(string[] args)
        {
            var cmdResult      = CommandLineParametersHelper.EvaluateArgs(args);
            var hasInstallPath = !string.IsNullOrWhiteSpace(cmdResult.InstallPath);
            var switches       = cmdResult.Switch;

            var version      = Assembly.GetExecutingAssembly().GetName().Version;
            var downloadPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "download");

            var installPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ACT");

            if (hasInstallPath && SystemInteractions.IsValidPath(cmdResult.InstallPath))
            {
                installPath = cmdResult.InstallPath;
            }

            Console.WriteLine($"##### ~ ActorConsole v{version}");
            Console.WriteLine($"##### Going to install ACT in '{installPath}'");

            if (switches == CommandLineSwitches.UserInput)
            {
                if (Iterate(_ => YesOrNoIteration("n"), CommandLineSwitches.UserInput, "##### Would you like to change it?' [y/N] ", DefaultIterationErrorMessage))
                {
                    Iterate(__ =>
                    {
                        installPath = Console.ReadLine();
                        return(SystemInteractions.IsValidPath(installPath));
                    }, CommandLineSwitches.UserInput, "##### Write the path you prefer: ", "##### The path inserted is not valid...");
                }
            }

            ActConfigurationHelper.UpdateActInstallPath(installPath);

            Console.WriteLine("##### To ensure that ACT works correctly you should first install:");
            Console.WriteLine("#####   1. Microsoft Visual C++ Redistributable");
            Console.WriteLine("#####   2. Microsoft .NET Framework 4.7");
            Console.WriteLine("#####   3. Win10Pcap");
            Console.WriteLine("##### If you have already installed then you can skip this step.");

            if (!Directory.Exists(downloadPath))
            {
                Directory.CreateDirectory(downloadPath);
            }

            var systemInteractions = new SystemInteractions();
            var webInteractions    = new WebInteractions();

            systemInteractions.KillProcess("Advanced Combat Tracker");

            var components = webInteractions.LoadConfiguration(() =>
            {
                Console.WriteLine("##### An error occurred when reading the configuration file.\nThe program will be terminated!\n");
                Console.ReadLine();
                Environment.Exit(1);
            });

            if (Iterate(_ => YesOrNoIteration(), switches, "##### Do you want to install the prerequisites? [Y/n] ", DefaultIterationErrorMessage))
            {
                foreach (var component in components.Where(x => x.IsPrerequisite).OrderBy(x => x.InstallOrder))
                {
                    Handle(webInteractions, systemInteractions, component, switches, downloadPath);
                }
            }

            Console.Clear();
            Console.WriteLine($"##### ~ Actor v{version}");

            foreach (var component in components.Where(x => !x.IsPrerequisite).OrderBy(x => x.InstallOrder))
            {
                Handle(webInteractions, systemInteractions, component, switches, downloadPath, installPath);
            }

            Console.WriteLine("##### Clearing Download folder...");
            Directory.Delete(downloadPath, true);

            var actComponent     = components.First(x => x.InstallOrder == 3);
            var actConfiguration = actComponent.Configurations.First();

            ActConfigurationHelper.SaveConfiguration(actConfiguration.Key, actConfiguration.Value, true, _ =>
            {
                if (switches != CommandLineSwitches.UserInput)
                {
                    return(true);
                }

                return(Iterate(__ =>
                {
                    var result = YesOrNoIteration();
                    return result.HasValue && result.Value;
                }, CommandLineSwitches.UserInput,
                               $"##### Do you want to overwrite the existing configuration for {actComponent.Name}? [Y/n] ",
                               DefaultIterationErrorMessage));
            });

            var firewallHelper = FirewallHelper.Instance;
            var actExePath     = Path.Combine(installPath, actComponent.Name + ".exe");

            if (firewallHelper.IsFirewallInstalled && firewallHelper.IsFirewallEnabled)
            {
                if (Iterate(_ => YesOrNoIteration(), switches, $"##### Would you like to add {actComponent.Name} to the Firewall Exceptions? [Y/n] ", DefaultIterationErrorMessage))
                {
                    var actPath = actExePath;
                    try
                    {
                        firewallHelper.GrantAuthorization(actPath, actComponent.Name);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }

            SystemInteractions.ApplyCompatibilityChanges(actExePath, CompatibilityMode.RUNASADMIN, CompatibilityMode.GDIDPISCALING, CompatibilityMode.DPIUNAWARE);

            if (Iterate(_ => YesOrNoIteration(), switches, $"##### Do you want to run {actComponent.Name}? [Y/n] ", DefaultIterationErrorMessage))
            {
                systemInteractions.CreateProcess(actExePath).Start();
            }

            Console.WriteLine("##### Finally we are done!");
            Console.WriteLine("##### Press any key to close this windows...");
            Console.ReadLine();
        }