// ReSharper disable once MemberCanBeMadeStatic.Local private async Task <PsfContentViewModel> LoadPsf(IAppxFileReader source, AppxPackage manifest) { var paths = manifest.Applications.Where(a => PackageTypeConverter.GetPackageTypeFrom(a.EntryPoint, a.Executable, a.StartPage, manifest.IsFramework) == MsixPackageType.BridgePsf).Select(a => a.Executable).Where(a => a != null).Select(Path.GetDirectoryName).Where(a => !string.IsNullOrEmpty(a)).Distinct().ToList(); paths.Add(string.Empty); foreach (var items in paths) { var configJsonPath = string.IsNullOrWhiteSpace(items) ? "config.json" : Path.Combine(items, "config.json"); if (!source.FileExists(configJsonPath)) { continue; } using (var s = source.GetFile(configJsonPath)) { using var stringReader = new StreamReader(s); var all = await stringReader.ReadToEndAsync().ConfigureAwait(false); var psfSerializer = new PsfConfigSerializer(); var configJson = psfSerializer.Deserialize(all); return(new PsfContentViewModel(configJson)); } } return(null); }
public void TestBuild() { var serializer = new PsfConfigSerializer(); var json = File.ReadAllText(@"E:\temp\msix-psf\fixed-rayeval\config.json"); var config = serializer.Deserialize(json); }
public void TestDeserialization() { var jsonString = @"{""applications"": [ { ""id"": ""App"", ""executable"": ""ClearbyteMSIXSample/ClearbyteMSIXSample.exe"", ""workingDirectory"": ""ClearbyteMSIXSample/"" } ], ""processes"": [ { ""executable"": ""ClearbyteMSIXSample"", ""fixups"": [ { ""dll"": ""FileRedirectionFixup32.dll"", ""config"": { ""redirectedPaths"": { ""packageRelative"": [ { ""base"": ""logs"", ""patterns"": [ "".*\\.log"" ] } ], ""packageDriveRelative"": [ { ""base"": ""temp"", ""patterns"": [ "".*"" ] } ], ""knownFolders"": [ { ""id"": ""ProgramFilesX64"", ""relativePaths"": [ { ""base"": ""Contoso\\config"", ""patterns"": [ "".*"" ] } ] }, { ""id"": "" {FDD39AD0-238F-46AF-ADB4-6C85480369C7}"", ""relativePaths"": [ { ""base"": ""MyApplication"", ""patterns"": [ "".*"" ] } ] } ] } } } ] } ] }"; var obj = new PsfConfigSerializer().Deserialize(jsonString); }
public void TestScripts() { var configJson = @"{ ""applications"": [ { ""id"": ""Sample"", ""executable"": ""Sample.exe"", ""workingDirectory"": """", ""stopOnScriptError"": false, ""startScript"": { ""scriptPath"": ""RunMePlease.ps1"", ""scriptArguments"": ""\""First argument\"" secondArgument"", ""runInVirtualEnvironment"": true, ""showWindow"": true, ""waitForScriptToFinish"": false }, ""endScript"": { ""scriptPath"": ""RunMeAfter.ps1"", ""scriptArguments"": ""ThisIsMe.txt"" } }, { ""id"": ""CPPSample"", ""executable"": ""CPPSample.exe"", ""workingDirectory"": """", ""startScript"": { ""scriptPath"": ""CPPStart.ps1"", ""scriptArguments"": ""ThisIsMe.txt"", ""runInVirtualEnvironment"": true }, ""endScript"": { ""scriptPath"": ""CPPEnd.ps1"", ""scriptArguments"": ""ThisIsMe.txt"", ""runOnce"": false } } ], ""processes"": [ ] }"; var obj = new PsfConfigSerializer().Deserialize(configJson); Assert.AreEqual(2, obj.Applications.Count); var sample = obj.Applications[0]; Assert.NotNull(sample.StartScript); Assert.AreEqual("RunMePlease.ps1", sample.StartScript.ScriptPath); Assert.AreEqual("\"First argument\" secondArgument", sample.StartScript.ScriptArguments); Assert.IsTrue(sample.StartScript.RunInVirtualEnvironment); Assert.IsTrue(sample.StartScript.ShowWindow); Assert.IsFalse(sample.StartScript.WaitForScriptToFinish); Assert.NotNull(sample.EndScript); Assert.AreEqual("RunMeAfter.ps1", sample.EndScript.ScriptPath); Assert.AreEqual("ThisIsMe.txt", sample.EndScript.ScriptArguments); var cppSample = obj.Applications[1]; }
private PsfApplicationDescriptor Read(string applicationId, string originalEntryPoint, TextReader configJson) { var jsonSerializer = new PsfConfigSerializer(); var config = jsonSerializer.Deserialize(configJson.ReadToEnd()); string executable = null; string workingDirectory = null; string arguments = null; var scripts = new List <PsfScriptDescriptor>(); foreach (var item in config.Applications ?? Enumerable.Empty <PsfApplication>()) { var id = item.Id; if (id != applicationId) { continue; } executable = item.Executable; workingDirectory = item.WorkingDirectory; arguments = item.Arguments; if (item.StartScript != null) { scripts.Add(new PsfScriptDescriptor(item.StartScript, PsfScriptDescriptorTiming.Start)); } if (item.EndScript != null) { scripts.Add(new PsfScriptDescriptor(item.EndScript, PsfScriptDescriptorTiming.Finish)); } break; } if (executable == null) { return(null); } var psfDef = new PsfApplicationDescriptor { Executable = executable, Arguments = arguments, WorkingDirectory = workingDirectory, OtherFixups = new List <string>(), FileRedirections = new List <PsfFolderRedirectionDescriptor>(), Tracing = null, Scripts = scripts }; foreach (var p in config.Processes ?? Enumerable.Empty <PsfProcess>()) { var exe = p.Executable; if (string.IsNullOrEmpty(exe)) { continue; } Regex regex; try { regex = new Regex(exe); } catch (Exception) { continue; } var indexOf = executable.LastIndexOfAny(new[] { '\\', '/' }); if (indexOf != -1) { executable = executable.Substring(indexOf + 1); } if (!regex.IsMatch(executable)) { executable = Path.GetFileNameWithoutExtension(executable); if (!regex.IsMatch(executable)) { continue; } } foreach (var fixup in p.Fixups ?? Enumerable.Empty <PsfFixup>()) { var dll = fixup.Dll; if (dll == null) { continue; } switch (dll.ToLower()) { case "tracefixup64.dll": { if (fixup.Config is PsfTraceFixupConfig psfFixupConfig) { psfDef.Tracing = new PsfTracingRedirectionDescriptor(psfFixupConfig ?? new PsfTraceFixupConfig(), PsfBitness.x64); } break; } case "electronfixup.dll": { psfDef.Electron = new PsfElectronDescriptor(); break; } case "tracefixup32.dll": { if (fixup.Config is PsfTraceFixupConfig psfFixupConfig) { psfDef.Tracing = new PsfTracingRedirectionDescriptor(psfFixupConfig ?? new PsfTraceFixupConfig(), PsfBitness.x86); } break; } case "tracefixup.dll": { if (fixup.Config is PsfTraceFixupConfig psfFixupConfig) { psfDef.Tracing = new PsfTracingRedirectionDescriptor(psfFixupConfig ?? new PsfTraceFixupConfig(), PsfBitness.x64); } break; } case "fileredirectionfixup64.dll": case "fileredirectionfixup32.dll": case "fileredirectionfixup.dll": var redirs = this.GetFolderRedirections(fixup); if (redirs != null) { psfDef.FileRedirections.AddRange(redirs); } break; default: psfDef.OtherFixups.Add(dll); break; } } } return(psfDef); }