private static async Task <TempFolder> CreateSetFolder(FilePickerVM vm) { var temp = await TempFolder.Create(); vm.TargetPath = temp.Dir; return(temp); }
public async Task CheckValidInstallPath_ProperOverwrite() { await using var tempDir = await TempFolder.Create(); await using var tmp = tempDir.Dir.Combine(Consts.ModOrganizer2Exe).Create(); Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded); }
public async Task SmallZipNoLongerCrashes() { var src = await DownloadMod(Game.Fallout4, 29596, 120918); await using var tmpFolder = await TempFolder.Create(); await FileExtractor2.ExtractAll(src, tmpFolder.Dir); }
public async Task CheckValidInstallPath_HasModlist() { await using var tempDir = await TempFolder.Create(); await using var mo2 = tempDir.Dir.Combine("ModOrganizer.exe").Create(); await using var molist = tempDir.Dir.Combine(((RelativePath) "modlist")).WithExtension(Consts.ModListExtension).Create(); Assert.False(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded); }
public Storage(ISettings settings) { _settings = settings; PluginsFolder.Create(); DataFolder.Create(); TempFolder.Create(); }
public async Task CheckValidInstallPath_OverwriteFilesInDownloads() { await using var tempDir = await TempFolder.Create(); var downloadsFolder = tempDir.Dir.Combine("downloads"); downloadsFolder.CreateDirectory(); await using var tmp = tempDir.Dir.Combine($"downloads/someFile.txt").Create(); Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: downloadsFolder).Succeeded); }
public async Task CheckValidInstallPath_ImproperOverwrite() { await using var tempDir = await TempFolder.Create(); await tempDir.Dir.DeleteDirectory(); tempDir.Dir.CreateDirectory(); await using var tmp = tempDir.Dir.Combine($"someFile.txt").Create(); Assert.False(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded); }
public override async Task <bool> Download(Archive a, AbsolutePath destination) { try { using var queue = new WorkQueue(); await using var folder = await TempFolder.Create(); folder.Dir.Combine("tracks").CreateDirectory(); var client = new YoutubeClient(Common.Http.ClientFactory.Client); var meta = await client.Videos.GetAsync(Key); var video = await client.Videos.Streams.GetManifestAsync(Key); var stream = video.Streams.OfType <AudioOnlyStreamInfo>().Where(f => f.AudioCodec.StartsWith("mp4a")).OrderByDescending(a => a.Bitrate) .ToArray().First(); var initialDownload = folder.Dir.Combine("initial_download"); var trackFolder = folder.Dir.Combine("tracks"); await using (var fs = await initialDownload.Create()) { await client.Videos.Streams.CopyToAsync(stream, fs, new Progress($"Downloading {a.Name}"), CancellationToken.None); } await Tracks.PMap(queue, async track => { Utils.Status($"Extracting track {track.Name}"); await ExtractTrack(initialDownload, trackFolder, track); }); await using var dest = await destination.Create(); using var ar = new ZipArchive(dest, ZipArchiveMode.Create); foreach (var track in trackFolder.EnumerateFiles().OrderBy(e => e)) { Utils.Status($"Adding {track.FileName} to archive"); var entry = ar.CreateEntry(Path.Combine("Data", "Music", (string)track.RelativeTo(trackFolder)), CompressionLevel.NoCompression); entry.LastWriteTime = meta.UploadDate; await using var es = entry.Open(); await using var ins = await track.OpenRead(); await ins.CopyToAsync(es); } return(true); } catch (VideoUnavailableException) { return(false); } }
[InlineData(Game.SkyrimSpecialEdition, 20035, 130759)] // Lucian public async Task CanAnalyzeMods(Game game, int modid, int fileId) { await using var tmpFolder = await TempFolder.Create(); var path = await FileExtractorTests.DownloadMod(game, modid, fileId); await path.CopyToAsync(path.FileName.RelativeTo(tmpFolder.Dir)); var context = new Context(Queue); await context.AddRoot(tmpFolder.Dir); Assert.True(context.Index.ByFullPath.Count >= 3); }
public void WhenWritingInSamePeriod_DontCreateNewFile(bool async, RollingFilePeriod period, int[] minutesToAdd) { using (var temp = TempFolder.Create()) { WriteLogs(async, temp.FolderPath, period, minutesToAdd); var files = Directory.GetFiles(temp.FolderPath); Assert.Single(files); var contents = File.ReadAllLines(files[0]); Assert.Equal(minutesToAdd.Length, contents.Length); } }
public async Task ExtractModlist() { ExtractedModlistFolder = await TempFolder.Create(); await FileExtractor2.GatheringExtract(new NativeFileStreamFactory(ModListArchive), _ => true, async (path, sfn) => { await using var s = await sfn.GetStream(); var fp = ExtractedModlistFolder.Dir.Combine(path); fp.Parent.CreateDirectory(); await fp.WriteAllAsync(s); return(0); }); }
public async Task CanExtractFOMODFiles() { var tmpFolder = await TempFolder.Create(); var src = await DownloadMod(Game.FalloutNewVegas, 52510); var newName = src.FileName.RelativeTo(tmpFolder.Dir); await src.CopyToAsync(newName); var ctx = new Context(_queue); await ctx.AddRoot(tmpFolder.Dir); Assert.NotEmpty(ctx.Index.ByName.Where(f => f.Key.FileName == (RelativePath)"Alternative Repairing.esp")); }
public void WhenWritingToNewFile_CreateFile() { using (var temp = TempFolder.Create()) { var path = temp.GetLogFilePath(); using (var sink = CreateSink(path)) { sink.Write(GenericLogLevelName.Debug, GenericLogEntries); } var contents = File.ReadAllLines(path); Assert.Equal(GenericLogText, contents[0].Substring(30)); } }
private static async Task <ExtractedFiles> ExtractAllWithOMOD(AbsolutePath source) { var dest = await TempFolder.Create(); Utils.Log($"Extracting {(string)source.FileName}"); Framework.Settings.TempPath = (string)dest.Dir; Framework.Settings.CodeProgress = new OMODProgress(); var omod = new OMOD((string)source); omod.GetDataFiles(); omod.GetPlugins(); return(new ExtractedFiles(dest)); }
public void WhenCreatingFileWithFormat_PatternMatches(RollingFilePeriod period) { using (var tempFolder = TempFolder.Create()) { var date = DateTime.Now; File.Create(Path.Combine(tempFolder.FolderPath, period.GetFileName(date))); var files = Directory.GetFiles(tempFolder.FolderPath); Assert.Single(files); Assert.True(Regex.IsMatch(Path.GetFileName(files[0]), period.FileNamePattern)); var match = Regex.Match(Path.GetFileName(files[0]), period.FileNamePattern); Assert.Equal(date.ToString(period.DateFormat), match.Groups[1].Value); } }
public void WhenWritingInDifferentPeriod_CreateNewFile(bool async, RollingFilePeriod period, int[] minutesToAdd) { using (var temp = TempFolder.Create()) { WriteLogs(async, temp.FolderPath, period, minutesToAdd); foreach (var minutes in minutesToAdd) { var date = BaseDate.AddMinutes(minutes); var contentsFile = File.ReadAllLines(Path.Combine(temp.FolderPath, period.GetFileName(date))); var log = string.Format("{0} [DBG] date={1}", date.ToString(DefaultDateTimeFormat), date.ToString(period.DateFormat)); Assert.Equal(log, contentsFile[0]); } } }
public void WhenWritingToNewFileDeleDirectoryAndWriteAgain_CreateDirectoryAndFile() { using (var temp = TempFolder.Create()) { var path = temp.GetLogFilePath(); using (var sink = CreateSink(path)) { sink.Write(GenericLogLevelName.Debug, GenericLogEntries); var contents = File.ReadAllLines(path); Assert.Equal(GenericLogText, contents[0].Substring(30)); Directory.Delete(temp.FolderPath, true); sink.Write(GenericLogLevelName.Debug, GenericLogEntries); contents = File.ReadAllLines(path); Assert.Equal(GenericLogText, contents[0].Substring(30)); } } }
private static async Task <ExtractedFiles> ExtractAllExe(AbsolutePath source) { var isArchive = await TestWith7z(source); if (isArchive) { return(await ExtractAllWith7Zip(source, null)); } var dest = await TempFolder.Create(); Utils.Log($"Extracting {(string)source.FileName}"); var process = new ProcessHelper { Path = @"Extractors\innounp.exe".RelativeTo(AbsolutePath.EntryPoint), Arguments = new object[] { "-x", "-y", "-b", $"-d\"{dest.Dir}\"", source } }; var result = process.Output.Where(d => d.Type == ProcessHelper.StreamType.Output) .ForEachAsync(p => { var(_, line) = p; if (line == null) { return; } if (line.Length <= 4 || line[3] != '%') { return; } int.TryParse(line.Substring(0, 3), out var percentInt); Utils.Status($"Extracting {source.FileName} - {line.Trim()}", Percent.FactoryPutInRange(percentInt / 100d)); }); await process.Start(); return(new ExtractedFiles(dest)); }
public void AddItemTest() { var collection = new DisposableCollection <TempFolder>(); using (collection) { collection.Add(TempFolder.Create()); collection.Add(TempFolder.Create()); collection.Add(TempFolder.Create()); collection.Add(TempFolder.Create()); collection.Add(TempFolder.Create()); collection.Add(TempFolder.Create()); Assert.IsTrue(collection.Count == 6); foreach (var item in collection) { Assert.IsTrue(Directory.Exists(item.FullName)); } } }
public async Task CheckValidInstallPath_DoesNotExist() { await using var tempDir = await TempFolder.Create(); Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir.Combine("Subfolder"), null, null).Succeeded); }
private static async Task <ExtractedFiles> ExtractAllWith7Zip(AbsolutePath source, IEnumerable <RelativePath> onlyFiles) { TempFile tmpFile = null; var dest = await TempFolder.Create(); Utils.Log(new GenericInfo($"Extracting {(string)source.FileName}", $"The contents of {(string)source.FileName} are being extracted to {(string)source.FileName} using 7zip.exe")); var process = new ProcessHelper { Path = @"Extractors\7z.exe".RelativeTo(AbsolutePath.EntryPoint), }; if (onlyFiles != null) { //It's stupid that we have to do this, but 7zip's file pattern matching isn't very fuzzy IEnumerable <string> AllVariants(string input) { yield return($"\"{input}\""); yield return($"\"\\{input}\""); } tmpFile = new TempFile(); await tmpFile.Path.WriteAllLinesAsync(onlyFiles.SelectMany(f => AllVariants((string)f)).ToArray()); process.Arguments = new object[] { "x", "-bsp1", "-y", $"-o\"{dest.Dir}\"", source, $"@\"{tmpFile.Path}\"", "-mmt=off" }; } else { process.Arguments = new object[] { "x", "-bsp1", "-y", $"-o\"{dest.Dir}\"", source, "-mmt=off" }; } var result = process.Output.Where(d => d.Type == ProcessHelper.StreamType.Output) .ForEachAsync(p => { var(_, line) = p; if (line == null) { return; } if (line.Length <= 4 || line[3] != '%') { return; } int.TryParse(line.Substring(0, 3), out var percentInt); Utils.Status($"Extracting {(string)source.FileName} - {line.Trim()}", Percent.FactoryPutInRange(percentInt / 100d)); }); var exitCode = await process.Start(); if (exitCode != 0) { Utils.Error(new _7zipReturnError(exitCode, source, dest.Dir, "")); } else { Utils.Status($"Extracting {source.FileName} - done", Percent.One, alsoLog: true); } tmpFile?.Dispose(); return(new ExtractedFiles(dest)); }
public async Task ExtractModlist() { ExtractedModlistFolder = await TempFolder.Create(); await FileExtractor2.ExtractAll(Queue, ModListArchive, ExtractedModlistFolder.Dir); }
[InlineData(Game.Fallout4, 43474)] // EM 2 Rifle public async Task BSACompressionRecompression(Game game, int modid) { var filename = await DownloadMod(game, modid); var folder = _bsaFolder.Combine(game.ToString(), modid.ToString()); await folder.DeleteDirectory(); folder.CreateDirectory(); await FileExtractor2.ExtractAll(Queue, filename, folder); foreach (var bsa in folder.EnumerateFiles().Where(f => Consts.SupportedBSAs.Contains(f.Extension))) { TestContext.WriteLine($"From {bsa}"); TestContext.WriteLine("Cleaning Output Dir"); await _tempDir.DeleteDirectory(); _tempDir.CreateDirectory(); TestContext.WriteLine($"Reading {bsa}"); await using var tempFolder = await TempFolder.Create(); var tempFile = tempFolder.Dir.Combine("test.bsa"); var size = bsa.Size; var a = await BSADispatch.OpenRead(bsa); await a.Files.PMap(Queue, async file => { var absName = _tempDir.Combine(file.Path); ViaJson(file.State); absName.Parent.CreateDirectory(); await using (var fs = await absName.Create()) { await file.CopyDataTo(fs); } Assert.Equal(file.Size, absName.Size); }); // Check Files should be case insensitive Assert.Equal(a.Files.Count(), a.Files.Select(f => f.Path).ToHashSet().Count); Assert.Equal(a.Files.Count(), a.Files.Select(f => f.Path.ToString().ToLowerInvariant()).ToHashSet().Count); TestContext.WriteLine($"Building {bsa}"); await using (var w = await ViaJson(a.State).MakeBuilder(size)) { var streams = await a.Files.PMap(Queue, async file => { var absPath = _tempDir.Combine(file.Path); var str = await absPath.OpenRead(); await w.AddFile(ViaJson(file.State), str); return(str); }); await w.Build(tempFile); streams.Do(s => s.Dispose()); } TestContext.WriteLine($"Verifying {bsa}"); var b = await BSADispatch.OpenRead(tempFile); TestContext.WriteLine($"Performing A/B tests on {bsa} and {tempFile}"); Assert.Equal(a.State.ToJson(), b.State.ToJson()); // Check same number of files Assert.Equal(a.Files.Count(), b.Files.Count()); await a.Files.Zip(b.Files, (ai, bi) => (ai, bi)) .PMap(Queue, async pair => { Assert.Equal(pair.ai.State.ToJson(), pair.bi.State.ToJson()); //Console.WriteLine($" - {pair.ai.Path}"); Assert.Equal(pair.ai.Path, pair.bi.Path); //Equal(pair.ai.Compressed, pair.bi.Compressed); Assert.Equal(pair.ai.Size, pair.bi.Size); Utils.Log($"Comparing {pair.ai.Path} to {pair.bi.Path}"); try { Assert.Equal(await GetData(pair.ai), await GetData(pair.bi)); } catch (Exception) { } }); } }
public async Task CheckValidInstallPath_Empty() { await using var tempDir = await TempFolder.Create(); Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, null, null).Succeeded); }