Пример #1
0
        public void CreateShim(FilePath targetExecutablePath, ToolCommandName commandName, IReadOnlyList <FilePath> packagedShims = null)
        {
            if (string.IsNullOrEmpty(targetExecutablePath.Value))
            {
                throw new ShellShimException(CommonLocalizableStrings.CannotCreateShimForEmptyExecutablePath);
            }

            if (ShimExists(commandName))
            {
                throw new ShellShimException(
                          string.Format(
                              CommonLocalizableStrings.ShellShimConflict,
                              commandName));
            }

            TransactionalAction.Run(
                action: () =>
            {
                try
                {
                    if (!_fileSystem.Directory.Exists(_shimsDirectory.Value))
                    {
                        _fileSystem.Directory.CreateDirectory(_shimsDirectory.Value);
                    }

                    if (TryGetPackagedShim(packagedShims, commandName, out FilePath? packagedShim))
                    {
                        _fileSystem.File.Copy(packagedShim.Value.Value, GetShimPath(commandName).Value);
                        _filePermissionSetter.SetUserExecutionPermission(GetShimPath(commandName).Value);
                    }
                    else
                    {
                        _appHostShellShimMaker.CreateApphostShellShim(
                            targetExecutablePath,
                            GetShimPath(commandName));
                    }
                }
                catch (FilePermissionSettingException ex)
                {
                    throw new ShellShimException(
                        string.Format(CommonLocalizableStrings.FailedSettingShimPermissions, ex.Message));
                }
                catch (Exception ex) when(ex is UnauthorizedAccessException || ex is IOException)
                {
                    throw new ShellShimException(
                        string.Format(
                            CommonLocalizableStrings.FailedToCreateShellShim,
                            commandName,
                            ex.Message
                            ),
                        ex);
                }
            },
                rollback: () => {
                foreach (var file in GetShimFiles(commandName).Where(f => _fileSystem.File.Exists(f.Value)))
                {
                    File.Delete(file.Value);
                }
            });
        }
Пример #2
0
        public void CreateApphostShellShim(FilePath entryPoint, FilePath shimPath)
        {
            string appHostSourcePath;

            if (OperatingSystem.IsWindows())
            {
                appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension + ".exe");
            }
            else
            {
                appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension);
            }

            var    appHostDestinationFilePath = Path.GetFullPath(shimPath.Value);
            string entryPointFullPath         = Path.GetFullPath(entryPoint.Value);
            var    appBinaryFilePath          = Path.GetRelativePath(Path.GetDirectoryName(appHostDestinationFilePath), entryPointFullPath);


            if (ResourceUpdater.IsSupportedOS())
            {
                var windowsGraphicalUserInterfaceBit = PEUtils.GetWindowsGraphicalUserInterfaceBit(entryPointFullPath);
                HostWriter.CreateAppHost(appHostSourceFilePath: appHostSourcePath,
                                         appHostDestinationFilePath: appHostDestinationFilePath,
                                         appBinaryFilePath: appBinaryFilePath,
                                         windowsGraphicalUserInterface: (windowsGraphicalUserInterfaceBit == WindowsGUISubsystem),
                                         assemblyToCopyResorcesFrom: entryPointFullPath);
            }
            else
            {
                // by passing null to assemblyToCopyResorcesFrom, it will skip copying resources,
                // which is only supported on Windows
                HostWriter.CreateAppHost(appHostSourceFilePath: appHostSourcePath,
                                         appHostDestinationFilePath: appHostDestinationFilePath,
                                         appBinaryFilePath: appBinaryFilePath,
                                         windowsGraphicalUserInterface: false,
                                         assemblyToCopyResorcesFrom: null,
                                         enableMacOSCodeSign: OperatingSystem.IsMacOS());
            }

            _filePermissionSetter.SetUserExecutionPermission(appHostDestinationFilePath);
        }
Пример #3
0
        public void CreateApphostShellShim(FilePath entryPoint, FilePath shimPath)
        {
            string appHostSourcePath;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension + ".exe");
            }
            else
            {
                appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension);
            }

            var appHostDestinationFilePath = shimPath.Value;
            var appBinaryFilePath          = PathUtility.GetRelativePath(appHostDestinationFilePath, entryPoint.Value);

            EmbedAppNameInHost.EmbedAndReturnModifiedAppHostPath(
                appHostSourceFilePath: appHostSourcePath,
                appHostDestinationFilePath: appHostDestinationFilePath,
                appBinaryFilePath: appBinaryFilePath);

            _filePermissionSetter.SetUserExecutionPermission(appHostDestinationFilePath);
        }