コード例 #1
0
ファイル: AppAlias.cs プロジェクト: 0install/0install-dotnet
    /// <summary>
    /// Creates an application alias in the current system.
    /// </summary>
    /// <param name="target">The application being integrated.</param>
    /// <param name="command">The command within <paramref name="target"/> the alias shall point to; can be <c>null</c>.</param>
    /// <param name="aliasName">The name of the alias to be created.</param>
    /// <param name="machineWide">Create the alias machine-wide instead of just for the current user.</param>
    /// <param name="iconStore">Stores icon files downloaded from the web as local files.</param>
    /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
    /// <exception cref="IOException">A problem occurred while writing to the filesystem or registry.</exception>
    /// <exception cref="WebException">A problem occurred while downloading additional data (such as icons).</exception>
    /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception>
    public static void Create(FeedTarget target, string?command, string aliasName, IIconStore iconStore, bool machineWide)
    {
        #region Sanity checks
        if (string.IsNullOrEmpty(aliasName))
        {
            throw new ArgumentNullException(nameof(aliasName));
        }
        if (iconStore == null)
        {
            throw new ArgumentNullException(nameof(iconStore));
        }
        #endregion

#if NETFRAMEWORK
        string stubDirPath = GetStubDir(machineWide);
        PathEnv.AddDir(stubDirPath, machineWide);

        string stubFilePath = Path.Combine(stubDirPath, aliasName + ".exe");
        new StubBuilder(iconStore).BuildRunStub(stubFilePath, target, command);

        if (machineWide || WindowsUtils.IsWindows7)
        {
            var hive = machineWide ? Registry.LocalMachine : Registry.CurrentUser;
            using var appPathsKey = hive.CreateSubKeyChecked(RegKeyAppPaths);
            using var exeKey      = appPathsKey.CreateSubKeyChecked(aliasName + ".exe");
            exeKey.SetValue("", stubFilePath);
        }
#else
        throw new PlatformNotSupportedException("Generating Windows aliases is not supported by the .NET Core version of Zero Install.");
#endif
    }
コード例 #2
0
        private void DesktopIntegrationApply()
        {
            if (WindowsUtils.IsWindows)
            {
                Handler.RunTask(new SimpleTask(Resources.DesktopIntegrationApply, () =>
                {
                    Shortcut.Create(
                        path: Shortcut.GetStartMenuPath("", "Zero Install", MachineWide),
                        targetPath: Path.Combine(TargetDir, "ZeroInstall.exe"));

                    PathEnv.AddDir(TargetDir, MachineWide);
                }));
            }
        }
コード例 #3
0
    private void DesktopIntegrationApply(long size)
    {
        Handler.RunTask(new SimpleTask(Resources.DesktopIntegrationApply, () =>
        {
            UninstallEntry.Register(
                UninstallID,
                new[] { Path.Combine(TargetDir, "0install-win.exe"), Self.Name, Self.Remove.Name },
                "Zero Install",
                new("https://0install.net/"),
                iconPath: Path.Combine(TargetDir, "ZeroInstall.exe"),
                AppInfo.Current.Version,
                size,
                MachineWide);

            RegistryUtils.SetSoftwareString(@"Microsoft\PackageManagement", "ZeroInstall", Path.Combine(TargetDir, "ZeroInstall.OneGet.dll"), MachineWide);

            PathEnv.AddDir(TargetDir, MachineWide);

            Shortcut.Create(
                path: Shortcut.GetStartMenuPath("", "Zero Install", MachineWide),
                targetPath: Path.Combine(TargetDir, "ZeroInstall.exe"),
                appId: "ZeroInstall");
        }));