Esempio n. 1
0
        public Compiler(ZipArchive projectArchive, Installation installation)
        {
            ProjectArchive = projectArchive;
            Installation   = installation;

            var entry = projectArchive.Entries.FirstOrDefault(e => e.Name == "NLog.EFT.Trainer.csproj");

            if (entry == null)
            {
                return;
            }

            using var stream = entry.Open();
            using var reader = new StreamReader(stream);
            ProjectContent   = reader.ReadToEnd();
        }
Esempio n. 2
0
        public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
        {
            try
            {
                AnsiConsole.MarkupLine("-=[[ [cyan]EscapeFromTarkov-Trainer Universal Installer[/] - [blue]https://github.com/sailro [/]]]=-");
                AnsiConsole.WriteLine();

                var installation = Installation.GetTargetInstallation(settings.Path, "Please select from where to uninstall the trainer");
                if (installation == null)
                {
                    return((int)ExitCode.NoInstallationFound);
                }

                AnsiConsole.MarkupLine($"Target [green]EscapeFromTarkov ({installation.Version})[/] in [blue]{installation.Location.EscapeMarkup()}[/].");

                if (!RemoveFile(Path.Combine(installation.Managed, "NLog.EFT.Trainer.dll")))
                {
                    return((int)ExitCode.RemoveDllFailed);
                }

                // MonoMod.RuntimeDetour is a dependency used by the non-ilmerged 0Harmony.dll used by legacy spt-aki. In this case we are not handling the removal
                if (!File.Exists(Path.Combine(installation.Managed, "MonoMod.RuntimeDetour.dll")))
                {
                    if (!RemoveFile(Path.Combine(installation.Managed, "0Harmony.dll")))
                    {
                        return((int)ExitCode.RemoveHarmonyDllFailed);
                    }
                }

                if (!RemoveFile(Path.Combine(installation.Data, "outline")))
                {
                    return((int)ExitCode.RemoveOutlineFailed);
                }

                RemoveOrPatchConfiguration(installation);
            }
            catch (Exception ex)
            {
                AnsiConsole.MarkupLine($"[red]Error: {ex.Message.EscapeMarkup()}. Please file an issue here : https://github.com/sailro/EscapeFromTarkov-Trainer/issues [/]");
                return((int)ExitCode.Failure);
            }

            return((int)ExitCode.Success);
        }
        public static Installation?GetTargetInstallation(string?path, string promptTitle)
        {
            var installations = new List <Installation>();

            AnsiConsole
            .Status()
            .Start("Discovering [green]Escape From Tarkov[/] installations...", _ =>
            {
                installations = Installation
                                .DiscoverInstallations()
                                .Distinct()
                                .ToList();
            });

            if (path is not null && Installation.TryDiscoverInstallation(path, out var installation))
            {
                installations.Add(installation);
            }

            installations = installations
                            .Distinct()
                            .OrderBy(i => i.Location)
                            .ToList();

            switch (installations.Count)
            {
            case 0:
                AnsiConsole.MarkupLine("[yellow]No [green]EscapeFromTarkov[/] installation found, please re-run this installer, passing the installation path as argument.[/]");
                return(null);

            case 1:
                var first = installations.First();
                return(AnsiConsole.Confirm($"Continue with [green]EscapeFromTarkov ({first.Version})[/] in [blue]{first.Location}[/] ?") ? first : null);

            default:
                var prompt = new SelectionPrompt <Installation>
                {
                    Converter = i => i.Location,
                    Title     = promptTitle
                };
                prompt.AddChoices(installations);
                return(AnsiConsole.Prompt(prompt));
            }
        }
        private static Installation?GetTargetInstallation(Settings settings)
        {
            var installations = new List <Installation>();

            AnsiConsole
            .Status()
            .Start("Discovering [green]Escape From Tarkov[/] installations...", _ =>
            {
                installations = Installation
                                .DiscoverInstallations()
                                .Distinct()
                                .ToList();
            });

            if (settings.Path is not null && Installation.TryDiscoverInstallation(settings.Path, out var installation))
            {
                installations.Add(installation);
            }

            installations = installations
                            .Distinct()
                            .OrderBy(i => i.Location)
                            .ToList();

            switch (installations.Count)
            {
            case 0:
                AnsiConsole.MarkupLine("[yellow]No [green]EscapeFromTarkov[/] installation found, please re-run this installer, passing the installation path as argument.[/]");
                return(null);

            case 1:
                return(installations.First());

            default:
                var prompt = new SelectionPrompt <Installation>
                {
                    Converter = i => i.Location,
                    Title     = "Please select where to install the trainer"
                };
                prompt.AddChoices(installations);
                return(AnsiConsole.Prompt(prompt));
            }
        }
        private void BtnSoftwareInstallation_Click(object sender, EventArgs e)
        {
            try
            {
                // This part enables IIS features on the system.
                TxtBxLog.AppendText("در حال نصب..." + "\r\n\r\n");
                Task.Run(() =>
                {
                    Installation installation = new Installation(this);
                    if (CheckBxIIS.Checked)
                    {
                        installation.InstallIISAndLog();
                        IISInstalled = true;
                    }
                    if (CheckBxKeyA.Checked)
                    {
                        installation.InstallKeyAAndLog();
                    }
                    if (CheckBxKasraPrintService.Checked)
                    {
                        installation.InstallKasraPrintServiceAndLog();
                    }
                    if (CheckBxFlashPlayer.Checked)
                    {
                        installation.InstallFlashPlayerAndLog();
                    }

                    // Save the log in a physical path. Method 'SaveLog' is static.
                    string logFileName = "PrerequisitesLog";
                    string storagePath = PublishPath + @"\App";
                    string log         = TxtBxLog.Text;
                    FileManager.SaveLog(logFileName, storagePath, log);
                    DisableBtnSoftwareInstallation = false;
                    MessageBox.Show("." + "فرایند نصب با موفقیت کامل شد");
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 6
0
        public override async Task <int> ExecuteAsync(CommandContext context, Settings settings)
        {
            try
            {
                AnsiConsole.MarkupLine("[cyan]-=[[ EscapeFromTarkov-Trainer Universal Installer ]]=-[/]");
                AnsiConsole.WriteLine();

                var installation = Installation.GetTargetInstallation(settings.Path, "Please select where to install the trainer");
                if (installation == null)
                {
                    return((int)ExitCode.NoInstallationFound);
                }

                AnsiConsole.MarkupLine($"Target [green]EscapeFromTarkov ({installation.Version})[/] in [blue]{installation.Location}[/].");

                var(compilation, archive) = await GetCompilationAsync(installation, "master");

                if (compilation == null)
                {
                    var branch = settings.Branch ?? installation.Version.ToString();
                    if (!branch.StartsWith("dev-"))
                    {
                        branch = "dev-" + branch;
                    }

                    (compilation, archive) = await GetCompilationAsync(installation, branch);
                }

                if (compilation == null)
                {
                    AnsiConsole.MarkupLine($"[red]Unable to compile trainer for version {installation.Version}. Please file an issue here : https://github.com/sailro/EscapeFromTarkov-Trainer/issues [/]");
                    return((int)ExitCode.CompilationFailed);
                }

                if (installation.UsingSptAki)
                {
                    AnsiConsole.MarkupLine("[yellow]SPT-AKI detected. Please make sure you have run the game at least once before installing the trainer.[/]");
                    AnsiConsole.MarkupLine("[yellow]SPT-AKI is patching binaries during the first run, and we [underline]need[/] to compile against those patched binaries.[/]");
                    AnsiConsole.MarkupLine("[yellow]If you install this trainer on stock binaries, the game will freeze at the startup screen.[/]");

                    if (!AnsiConsole.Confirm("Continue installation (yes I have run the game at least once) ?"))
                    {
                        return((int)ExitCode.Canceled);
                    }
                }

                if (!CreateDll(installation, compilation))
                {
                    return((int)ExitCode.CreateDllFailed);
                }

                if (!CreateOutline(installation, archive !))
                {
                    return((int)ExitCode.CreateOutlineFailed);
                }

                CreateOrPatchConfiguration(installation);
            }
            catch (Exception ex)
            {
                AnsiConsole.MarkupLine($"[red]Error: {ex.Message}. Please file an issue here : https://github.com/sailro/EscapeFromTarkov-Trainer/issues [/]");
                return((int)ExitCode.Failure);
            }

            return((int)ExitCode.Success);
        }
Esempio n. 7
0
        private static async Task <(CSharpCompilation?, ZipArchive?)> GetCompilationAsync(Installation installation, string branch)
        {
            var archive = await GetSnapshotAsync(branch);

            if (archive == null)
            {
                return(null, null);
            }

            CSharpCompilation?compilation = null;

            AnsiConsole
            .Status()
            .Start("Compiling trainer", _ =>
            {
                var compiler = new Compiler(archive, installation);
                compilation  = compiler.Compile();
                var errors   = compilation
                               .GetDiagnostics()
                               .Where(d => d.Severity == DiagnosticSeverity.Error)
                               .ToList();

                if (errors.Any())
                {
                    AnsiConsole.MarkupLine($"[yellow]Compilation failed for {branch} branch.[/]");
                    compilation = null;
                }
                else
                {
                    AnsiConsole.MarkupLine($"Compilation [green]succeed[/] for [blue]{branch}[/] branch.");
                }
            });

            return(compilation, archive);
        }
Esempio n. 8
0
        public override async Task <int> ExecuteAsync(CommandContext context, Settings settings)
        {
            try
            {
                AnsiConsole.MarkupLine("-=[[ [cyan]EscapeFromTarkov-Trainer Universal Installer[/] - [blue]https://github.com/sailro [/]]]=-");
                AnsiConsole.WriteLine();

                var installation = Installation.GetTargetInstallation(settings.Path, "Please select where to install the trainer");
                if (installation == null)
                {
                    return((int)ExitCode.NoInstallationFound);
                }

                AnsiConsole.MarkupLine($"Target [green]EscapeFromTarkov ({installation.Version})[/] in [blue]{installation.Location.EscapeMarkup()}[/].");

                // Try first to compile against master
                var @try = 0;
                var(compilation, archive, errors) = await GetCompilationAsync(++@try, installation, "master");

                var files = errors
                            .Select(d => d.Location.SourceTree?.FilePath)
                            .Where(s => s is not null)
                            .Distinct()
                            .ToArray();

                if (compilation == null)
                {
                    // Failure, so try with a dedicated branch if exists
                    var branch = settings.Branch ?? installation.Version.ToString();
                    if (!branch.StartsWith("dev-"))
                    {
                        branch = "dev-" + branch;
                    }

                    (compilation, archive, _) = await GetCompilationAsync(++@try, installation, branch);
                }

                if (compilation == null && files.Any() && files.All(f => f !.StartsWith("Features")))
                {
                    // Failure, retry by removing faulting features if possible
                    AnsiConsole.MarkupLine($"[yellow]Trying to disable faulting feature(s): [red]{string.Join(", ", files.Select(Path.GetFileNameWithoutExtension))}[/].[/]");
                    (compilation, archive, errors) = await GetCompilationAsync(++@try, installation, "master", files !);

                    if (!errors.Any())
                    {
                        AnsiConsole.MarkupLine("[yellow]We found a fallback! But please file an issue here : https://github.com/sailro/EscapeFromTarkov-Trainer/issues [/]");
                    }
                }

                if (compilation == null)
                {
                    // Failure
                    AnsiConsole.MarkupLine($"[red]Unable to compile trainer for version {installation.Version}. Please file an issue here : https://github.com/sailro/EscapeFromTarkov-Trainer/issues [/]");
                    return((int)ExitCode.CompilationFailed);
                }

                if (installation.UsingSptAki)
                {
                    AnsiConsole.MarkupLine("[yellow]SPT-AKI detected. Please make sure you have run the game at least once before installing the trainer.[/]");
                    AnsiConsole.MarkupLine("[yellow]SPT-AKI is patching binaries during the first run, and we [underline]need[/] to compile against those patched binaries.[/]");
                    AnsiConsole.MarkupLine("[yellow]If you install this trainer on stock binaries, the game will freeze at the startup screen.[/]");

                    if (!AnsiConsole.Confirm("Continue installation (yes I have run the game at least once) ?"))
                    {
                        return((int)ExitCode.Canceled);
                    }
                }

                if (!CreateDll(installation, "NLog.EFT.Trainer.dll", (dllPath) => compilation.Emit(dllPath)))
                {
                    return((int)ExitCode.CreateDllFailed);
                }

                if (!CreateDll(installation, "0Harmony.dll", (dllPath) => File.WriteAllBytes(dllPath, Resources._0Harmony), false))
                {
                    return((int)ExitCode.CreateHarmonyDllFailed);
                }

                if (!CreateOutline(installation, archive !))
                {
                    return((int)ExitCode.CreateOutlineFailed);
                }

                CreateOrPatchConfiguration(installation);
            }
            catch (Exception ex)
            {
                AnsiConsole.MarkupLine($"[red]Error: {ex.Message.EscapeMarkup()}. Please file an issue here : https://github.com/sailro/EscapeFromTarkov-Trainer/issues [/]");
                return((int)ExitCode.Failure);
            }

            return((int)ExitCode.Success);
        }
Esempio n. 9
0
        private static async Task <(CSharpCompilation?, ZipArchive?, Diagnostic[])> GetCompilationAsync(int @try, Installation installation, string branch, params string[] exclude)
        {
            var errors = Array.Empty <Diagnostic>();

            var archive = await GetSnapshotAsync(@try, branch);

            if (archive == null)
            {
                return(null, null, errors);
            }

            CSharpCompilation?compilation = null;

            AnsiConsole
            .Status()
            .Start("Compiling trainer", _ =>
            {
                var compiler = new Compiler(archive, installation, exclude);
                compilation  = compiler.Compile();
                errors       = compilation
                               .GetDiagnostics()
                               .Where(d => d.Severity == DiagnosticSeverity.Error)
                               .ToArray();

#if DEBUG
                foreach (var error in errors)
                {
                    AnsiConsole.MarkupLine($">> {error.Id} [[{error.Location.SourceTree?.FilePath}]]: {error.GetMessage()}");
                }
#endif

                if (errors.Any())
                {
                    AnsiConsole.MarkupLine($">> [blue]Try #{@try}[/] [yellow]Compilation failed for {branch.EscapeMarkup()} branch.[/]");
                    compilation = null;
                }
                else
                {
                    AnsiConsole.MarkupLine($">> [blue]Try #{@try}[/] Compilation [green]succeed[/] for [blue]{branch.EscapeMarkup()}[/] branch.");
                }
            });

            return(compilation, archive, errors);
        }