Beispiel #1
0
        /// <summary>
        /// Retrieves a file association for a particular extension
        /// From Ohad Schneider <see cref="!:https://stackoverflow.com/a/17773402"/>
        /// </summary>
        /// <param name="associationFlags">Any flags which need to be set in order to retrieve the association</param>
        /// <param name="associationType">The type of association which should be retrieved</param>
        /// <param name="fileExtension">The file association which we will use to determine the association</param>
        /// <returns></returns>
        private static string GetFileAssociation(AssocF associationFlags, AssocStr associationType, string fileExtension)
        {
            uint bufferSize     = 0;
            uint returnedStatus = FileInvoker.AssocQueryString(associationFlags, associationType, fileExtension, null,
                                                               null, ref bufferSize);

            const int successWithLength = 1;

            if (returnedStatus != successWithLength)
            {
                throw new NoAssociationFoundException(
                          $"Could not determine the required buffer size required for the file association {associationType} and file extension {fileExtension}",
                          fileExtension);
            }

            StringBuilder stringBuilder = new StringBuilder((int)bufferSize);

            returnedStatus = FileInvoker.AssocQueryString(associationFlags, associationType, fileExtension, null,
                                                          stringBuilder, ref bufferSize);

            const int successWithAssociation = 0;

            if (returnedStatus != successWithAssociation)
            {
                throw new NoAssociationFoundException(
                          $"Could not determine a string for the file association {associationType} and file extension {fileExtension}",
                          fileExtension);
            }

            return(stringBuilder.ToString());
        }
Beispiel #2
0
        public string FindExecutable()
        {
            if (!FileInfo.Exists)
            {
                throw new FileNotFoundException(
                          "Cannot open a file which does not exist. Please use the static methods GetAssociatedExecutable or GetAssociatedApp instead.");
            }


            // If we are finding the executable for an executable, return the current file
            if (FileInfo.Extension.Equals(".exe", StringComparison.OrdinalIgnoreCase))
            {
                return(FileInfo.FullName);
            }

            // https://social.msdn.microsoft.com/Forums/vstudio/en-US/af164414-592a-42bb-bb24-47c4fe580123/how-do-i-get-the-value-of-maxpath-under-c
            const int     maxPath     = 260;
            StringBuilder pathBuilder = new StringBuilder(maxPath);
            int           result      = FileInvoker.FindExecutable(FileInfo.Name, FileInfo.DirectoryName, pathBuilder);

            if (result > 32)
            {
                return(pathBuilder.ToString());
            }

            if (result == 2)
            {
                throw new FileNotFoundException($"File was not found at {FileInfo.FullName}");
            }

            if (result == 3)
            {
                throw new InvalidOperationException($"The path ({FileInfo.FullName}) was invalid");
            }

            if (result == 5)
            {
                throw new SecurityException($"The file could not be accessed at {FileInfo.FullName}");
            }

            if (result == 8)
            {
                throw new OutOfMemoryException($"The system is out of memory or resources while finding the executable for {FileInfo.FullName}");
            }

            if (result == 31)
            {
                throw new InvalidOperationException($"There is no association for the specified file type, for {FileInfo.FullName}");
            }

            throw new NoAssociationFoundException($"Could not find the associated executable for {FileInfo.FullName}. The resul {result} was returned which we were not expecting", FileInfo.Extension);
        }
        public PackageExpertViewModel(
            string packagePath,
            IInterProcessCommunicationManager interProcessCommunicationManager,
            ISelfElevationProxyProvider <IAppxPackageQuery> appxPackageQueryProvider,
            ISelfElevationProxyProvider <IAppxVolumeManager> appxVolumeManagerProvider,
            ISelfElevationProxyProvider <ISigningManager> signManager,
            IInteractionService interactionService,
            IAppxFileViewer fileViewer,
            FileInvoker fileInvoker)
        {
            this.interProcessCommunicationManager = interProcessCommunicationManager;
            this.appxPackageQueryProvider         = appxPackageQueryProvider;
            this.appxVolumeManagerProvider        = appxVolumeManagerProvider;
            this.fileViewer  = fileViewer;
            this.fileInvoker = fileInvoker;
            this.packagePath = packagePath;

            this.Trust = new TrustViewModel(packagePath, interactionService, signManager);
        }
        public PackagesManagementCommandHandler(
            IMsixHeroApplication application,
            IInteractionService interactionService,
            IConfigurationService configurationService,
            PrismServices prismServices,
            ISelfElevationProxyProvider <IAppxPackageRunner> packageRunnerProvider,
            ISelfElevationProxyProvider <IAppxPackageInstaller> packageInstallerProvider,
            ISelfElevationProxyProvider <IRegistryManager> registryManagerProvider,
            IBusyManager busyManager)
        {
            this.application              = application;
            this.interactionService       = interactionService;
            this.configurationService     = configurationService;
            this.dialogService            = prismServices.DialogService;
            this.moduleManager            = prismServices.ModuleManager;
            this.packageRunnerProvider    = packageRunnerProvider;
            this.packageInstallerProvider = packageInstallerProvider;
            this.registryManagerProvider  = registryManagerProvider;
            this.busyManager              = busyManager;
            this.fileInvoker              = new FileInvoker(this.interactionService, this.configurationService);

            this.Refresh                       = new DelegateCommand(this.OnRefresh, this.CanRefresh);
            this.AddPackage                    = new DelegateCommand <object>(this.OnAddPackage, this.CanAddPackage);
            this.OpenExplorer                  = new DelegateCommand(this.OnOpenExplorer, this.CanOpenExplorer);
            this.OpenUserExplorer              = new DelegateCommand(this.OnOpenUserExplorer, this.CanOpenUserExplorer);
            this.OpenManifest                  = new DelegateCommand(this.OnOpenManifest, this.CanOpenManifest);
            this.OpenConfigJson                = new DelegateCommand(this.OnOpenConfigJson, this.CanOpenPsfConfig);
            this.OpenStore                     = new DelegateCommand(this.OnOpenStore, this.CanOpenStore);
            this.CheckUpdates                  = new DelegateCommand(this.OnCheckUpdates, this.CanCheckUpdates);
            this.RunTool                       = new DelegateCommand <object>(this.OnRunTool, this.CanRunTool);
            this.RemovePackage                 = new DelegateCommand(this.OnRemovePackage, this.CanRemovePackage);
            this.Copy                          = new DelegateCommand <object>(this.OnCopy, this.CanCopy);
            this.ViewDependencies              = new DelegateCommand(this.OnViewDependencies, this.CanViewDependencies);
            this.ChangeVolume                  = new DelegateCommand(this.OnChangeVolume, this.CanChangeVolume);
            this.ShowAppInstallerDialog        = new DelegateCommand <object>(this.OnShowAppInstallerDialog);
            this.ShowModificationPackageDialog = new DelegateCommand <object>(this.OnShowModificationPackageDialog);
            this.ShowWingetDialog              = new DelegateCommand <object>(this.OnShowWingetDialog);
            this.MountRegistry                 = new DelegateCommand(this.OnMountRegistry, this.CanMountRegistry);
            this.DismountRegistry              = new DelegateCommand(this.OnDismountRegistry, this.CanDismountRegistry);
            this.StartApp                      = new DelegateCommand <object>(this.OnStartApp, this.CanStartApp);
            this.StopApp                       = new DelegateCommand(this.OnStopApp, this.CanStopApp);
            this.Settings                      = new DelegateCommand(this.OnSettings);
        }
        public AppxFilesViewModel(
            string packageFile,
            IAppxFileViewer fileViewer,
            FileInvoker fileInvoker) : base(packageFile)
        {
            this.fileViewer  = fileViewer;
            this.fileInvoker = fileInvoker;
            var rootContainersTask = this.GetRootContainers();
            var nodesCollection    = new ObservableCollection <AppxFileViewModel>();

            this.Nodes = nodesCollection;
            this.View  = new DelegateCommand(this.OnView);

            var containers = new AsyncProperty <IList <AppxDirectoryViewModel> >();

            this.Containers = containers;
#pragma warning disable 4014
            containers.Loaded += this.OnContainersLoaded;
            containers.Load(rootContainersTask);
#pragma warning restore 4014
        }
        static void Main(string[] args)
        {
            var fileSystemReceiver = FileSystemReceiverUtil.GetFileSystemReceiver();

            var openFileCommand = new OpenFileCommand(fileSystemReceiver);

            var closeFileCommand = new CloseFileCommand(fileSystemReceiver);

            var readFileCommand = new ReadFileCommand(fileSystemReceiver);

            var writeFileCommand = new WriteFileCommand(fileSystemReceiver);

            var invoker = new FileInvoker();

            invoker.Execute(openFileCommand);

            invoker.Execute(closeFileCommand);

            invoker.Execute(new ICommand[] { openFileCommand, readFileCommand, writeFileCommand, closeFileCommand });

            Console.Read();
        }
Beispiel #7
0
        public PackageExpertControl(IEventAggregator eventAggregator,
                                    IInterProcessCommunicationManager ipcManager,
                                    ISelfElevationProxyProvider <IAppxPackageQuery> packageQueryProvider,
                                    ISelfElevationProxyProvider <IAppxVolumeManager> volumeManagerProvider,
                                    ISelfElevationProxyProvider <ISigningManager> signingManagerProvider,
                                    IInteractionService interactionService,
                                    IConfigurationService configurationService,
                                    IAppxFileViewer fileViewer,
                                    FileInvoker fileInvoker
                                    )
        {
            this.context = RegionContext.GetObservableContext(this);
            this.context.PropertyChanged += this.OnPropertyChanged;
            this.ipcManager             = ipcManager;
            this.packageQueryProvider   = packageQueryProvider;
            this.volumeManagerProvider  = volumeManagerProvider;
            this.interactionService     = interactionService;
            this.signingManagerProvider = signingManagerProvider;
            this.configurationService   = configurationService;
            this.fileViewer             = fileViewer;
            this.fileInvoker            = fileInvoker;

            eventAggregator.GetEvent <ToolsChangedEvent>().Subscribe(this.CreateTools, ThreadOption.UIThread);
        }
        static void CommandTest()
        {
            //Creating the receiver object
            IFileSystemReceiver fs = FileSystemReceiverUtil.getUnderlyingFileSystem();

            //creating command and associating with receiver
            OpenFileCommand openFileCommand = new OpenFileCommand(fs);

            //Creating invoker and associating with Command
            FileInvoker file = new FileInvoker(openFileCommand);

            //perform action on invoker object
            file.execute();

            WriteFileCommand writeFileCommand = new WriteFileCommand(fs);

            file = new FileInvoker(writeFileCommand);
            file.execute();

            CloseFileCommand closeFileCommand = new CloseFileCommand(fs);

            file = new FileInvoker(closeFileCommand);
            file.execute();
        }