public ITempFolder Create(bool deleteAfter = true, bool throwIfUnsuccessfulDisposal = true) { return(TempFolder.Factory( deleteAfter: deleteAfter, throwIfUnsuccessfulDisposal: throwIfUnsuccessfulDisposal, fileSystem: _fileSystem)); }
public async Task Setup() { // Load Settings System.Console.WriteLine("Running in directory: " + Directory.GetCurrentDirectory()); FilePath settingsPath = "../../../../TestingSettings.xml"; System.Console.WriteLine("Settings path: " + settingsPath); Settings = JsonConvert.DeserializeObject <TestingSettings>(File.ReadAllText(settingsPath.Path)); System.Console.WriteLine("Target settings: " + Settings.ToString()); // Setup folders and paths ModKey = new ModKey("Oblivion", ModType.Master); TempFolder = TempFolder.Factory(deleteAfter: true); DataPath = Path.Combine(Settings.DataFolderLocations.Oblivion, "Oblivion.esm"); BinaryPath = Path.Combine(TempFolder.Dir.Path, "Oblivion.esm"); OneTimeXmlFolder = new DirectoryPath(Path.Combine(TempFolder.Dir.Path, "OneTimeFolder")); OneTimeXmlFolder.Create(); // Setup Mod = OblivionMod.CreateFromBinary(new ModPath(ModKey, DataPath)); }
static async Task DoWork( string? mutagenVersion, string? synthesisVersion, CancellationToken cancel) { using var temp = TempFolder.Factory(); var failedDeps = new List<Dependent>(); var projResults = new List<(Dependent, string, ErrorResponse)>(); mutagenVersion ??= Versions.MutagenVersion; synthesisVersion ??= Versions.SynthesisVersion; System.Console.WriteLine($"Mutagen: {mutagenVersion}"); System.Console.WriteLine($"Synthesis: {synthesisVersion}"); var deps = await GitHubDependents.GitHubDependents.GetDependents( user: RegistryConstants.GithubUser, repository: RegistryConstants.GithubRepoName, packageID: RegistryConstants.PackageId, pages: byte.MaxValue) .ToArrayAsync(); await Task.WhenAll(deps.GroupBy(x => x.User).Select(group => Task.Run(async () => { cancel.ThrowIfCancellationRequested(); if (group.Key == null) return; await Task.WhenAll(group.Select(dependency => Task.Run(async () => { cancel.ThrowIfCancellationRequested(); try { if (dependency.User.IsNullOrWhitespace() || dependency.Repository.IsNullOrWhitespace()) return; var repoDir = Directory.CreateDirectory(Path.Combine(temp.Dir.Path, group.Key, dependency.Repository)); var clonePath = $"https://github.com/{dependency.User}/{dependency.Repository}"; try { Repository.Clone(clonePath, repoDir.FullName); } catch (Exception ex) { System.Console.Error.WriteLine($"Failed to clone {clonePath}"); System.Console.Error.WriteLine(ex); failedDeps.Add(dependency); return; } cancel.ThrowIfCancellationRequested(); using var repo = new Repository(repoDir.FullName); var slnPath = GitPatcherRun.GetPathToSolution(repo.Info.WorkingDirectory); if (slnPath == null) { System.Console.Error.WriteLine($"Could not get path to solution {clonePath}"); failedDeps.Add(dependency); return; } GitPatcherRun.SwapInDesiredVersionsForSolution( solutionPath: slnPath, drivingProjSubPath: string.Empty, mutagenVersion: mutagenVersion, out var _, synthesisVersion: synthesisVersion, out var _); foreach (var proj in SolutionPatcherRun.AvailableProjectSubpaths(slnPath)) { System.Console.WriteLine($"Checking {group.Key}/{dependency.Repository}:{proj}"); cancel.ThrowIfCancellationRequested(); var path = Path.Combine(repoDir.FullName, proj); var compile = await DotNetCommands.Compile(path, cancel, null); if (compile.Failed) { System.Console.WriteLine("Failed compilation"); } projResults.Add((dependency, proj, compile)); } } catch (Exception ex) { System.Console.Error.WriteLine($"Failed to check {dependency}"); System.Console.Error.WriteLine(ex); return; } }))); }))); cancel.ThrowIfCancellationRequested(); System.Console.WriteLine(); System.Console.WriteLine(); System.Console.WriteLine(); System.Console.WriteLine("-------------------------------"); System.Console.WriteLine(); System.Console.WriteLine(); System.Console.WriteLine(); if (failedDeps.Count > 0) { System.Console.WriteLine("Failed repos:"); foreach (var f in failedDeps .OrderBy(d => d.User) .CreateOrderedEnumerable(d => d.Repository, null, true)) { System.Console.WriteLine($" {f}"); } } var failed = projResults.Where(p => p.Item3.Failed).ToList(); if (failed.Count > 0) { System.Console.WriteLine("Failed projects:"); foreach (var f in failed.OrderBy(f => f.Item1.User) .CreateOrderedEnumerable(d => d.Item1.Repository, null, true) .CreateOrderedEnumerable(d => d.Item2, null, true)) { System.Console.WriteLine($"{f.Item1}: {f.Item2}"); System.Console.WriteLine(); } } }
protected IPersistentFormKeyAllocator_Tests() { tempFolder = new(() => TempFolder.Factory()); tempFile = new(() => new TempFile(extraDirectoryPaths: Utility.TempFolderPath)); }
public static void Align( ModPath inputPath, FilePath outputPath, GameRelease release, AlignmentRules alignmentRules, TempFolder?temp = null) { var interest = new RecordInterest(alignmentRules.Alignments.Keys) { EmptyMeansInterested = false }; var constants = GameConstants.Get(release); var parsingBundle = new ParsingBundle(constants, MasterReferenceReader.FromPath(inputPath, release)); var fileLocs = RecordLocator.GetFileLocations(inputPath.Path, release, interest); temp ??= TempFolder.Factory(); using (temp) { var alignedMajorRecordsFile = Path.Combine(temp.Dir.Path, "alignedRules"); using (var inputStream = new MutagenBinaryReadStream(inputPath.Path, parsingBundle)) { using var writer = new MutagenWriter(new FileStream(alignedMajorRecordsFile, FileMode.Create), release); AlignMajorRecordsByRules(inputStream, writer, alignmentRules, fileLocs); } var alignedGroupsFile = Path.Combine(temp.Dir.Path, "alignedGroups"); using (var inputStream = new MutagenBinaryReadStream(alignedMajorRecordsFile, parsingBundle)) { using var writer = new MutagenWriter(new FileStream(alignedGroupsFile, FileMode.Create), release); AlignGroupsByRules(inputStream, writer, alignmentRules, fileLocs); } fileLocs = RecordLocator.GetFileLocations(alignedGroupsFile, release, interest); var alignedCellsFile = Path.Combine(temp.Dir.Path, "alignedCells"); using (var mutaReader = new BinaryReadStream(alignedGroupsFile)) { using var writer = new MutagenWriter(alignedCellsFile, release); foreach (var grup in fileLocs.GrupLocations) { if (grup <= mutaReader.Position) { continue; } var noRecordLength = grup - mutaReader.Position; mutaReader.WriteTo(writer.BaseStream, (int)noRecordLength); // If complete overall, return if (mutaReader.Complete) { break; } mutaReader.WriteTo(writer.BaseStream, 12); var grupType = mutaReader.ReadUInt32(); writer.Write((int)grupType); if (grupType == constants.GroupConstants.Cell.TopGroupType) { AlignCellChildren(mutaReader, writer); } } mutaReader.WriteTo(writer.BaseStream, checked ((int)mutaReader.Remaining)); } fileLocs = RecordLocator.GetFileLocations(alignedCellsFile, release, interest); using (var mutaReader = new MutagenBinaryReadStream(alignedCellsFile, parsingBundle)) { using var writer = new MutagenWriter(outputPath.Path, GameConstants.Get(release)); foreach (var grup in fileLocs.GrupLocations) { if (grup <= mutaReader.Position) { continue; } var noRecordLength = grup - mutaReader.Position; mutaReader.WriteTo(writer.BaseStream, (int)noRecordLength); // If complete overall, return if (mutaReader.Complete) { break; } mutaReader.WriteTo(writer.BaseStream, 12); var grupType = mutaReader.ReadUInt32(); writer.Write((int)grupType); if (grupType == constants.GroupConstants.World.TopGroupType) { AlignWorldChildren(mutaReader, writer); } } mutaReader.WriteTo(writer.BaseStream, checked ((int)mutaReader.Remaining)); } } }