예제 #1
0
        // 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);
        }
예제 #2
0
 public void TestBuild()
 {
     var serializer = new PsfConfigSerializer();
     var json       = File.ReadAllText(@"E:\temp\msix-psf\fixed-rayeval\config.json");
     var config     = serializer.Deserialize(json);
 }
예제 #3
0
        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);
        }