Skip to content

Commit

Permalink
player/main: Add install/uninstall options for Windows
Browse files Browse the repository at this point in the history
On Linux, we have `mpv.desktop`, and on macOS, we have `osxbundle`, both
of which handle file associations and protocol registration in the
system environment.

On Windows, this information is stored in the registry, so this commit
adds support for it.

It registers the application, supported file types, and supported
protocols, and adds an uninstall entry so users can remove all
registrations via the control panel. Note that this does not remove the
binary itself.

The implementation is fully portable. There are no external installers,
as mpv handles everything automatically. This should improve usability
when moving binaries and so on.

- `mpv --install` registers mpv (see verbose output for a list of actions).
- `mpv --uninstall` reverts all changes made during installation.
- `mpv --install-rpath <string>` allows specifying a string to be
  prepended to `PATH` before running mpv. This is useful when using
external dependencies that shouldn't be added globally to `PATH`.
  • Loading branch information
kasper93 committed Feb 18, 2025
1 parent 9d0c2ed commit 059d866
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 8 deletions.
38 changes: 38 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7941,3 +7941,41 @@ Miscellaneous
On Wayland, this option only has effect on the ``wayland`` backend, and
not for the ``vo`` backend. See ``current-clipboard-backend`` property for
more details.

``--install``
(Windows only)

Registers mpv as a media player on Windows. This includes adding registry
entries to associate mpv with media files and protocols, as well as enabling
autoplay handlers for Blu-ray, DVD, and CD-Audio.

When using this option, mpv will exit after completing the process.
To see a detailed list of operations, run mpv with the ``-v`` option.

By default, mpv will be registered for the current user. To register it for
all users, run mpv as an administrator with this option. However, this is
not recommended, as installing it per user is generally preferable.

You can uninstall mpv from the Windows Settings or by running mpv with the
``--uninstall`` option.

``--install-rpath=<string>``
(Windows only)

When installing with ``--install``, this option allows you to specify a
string that will be prepended to the runtime path whenever mpv.exe is executed.

This is useful for setting up paths to external libraries required by mpv
without adding them to the global PATH environment variable.

The format of the string follows the same structure as the PATH environment
variable, a semicolon-separated list of paths.

``--uninstall``
(Windows only)

Unregisters mpv as a media player on Windows, undoing all changes made by
the ``--install`` option.

If mpv was previously installed for all users, run this command as an
administrator to remove it properly.
3 changes: 3 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ extern const struct m_sub_options egl_conf;

extern const struct m_sub_options mp_sub_filter_opts;

extern const struct m_sub_options w32_install_conf;

static const struct m_sub_options screenshot_conf = {
.opts = image_writer_opts,
.size = sizeof(struct image_writer_opts),
Expand Down Expand Up @@ -514,6 +516,7 @@ static const m_option_t mp_opts[] = {
{"msg-module", OPT_BOOL(msg_module), .flags = UPDATE_TERM},
{"msg-time", OPT_BOOL(msg_time), .flags = UPDATE_TERM},
#if HAVE_WIN32_DESKTOP
{"", OPT_SUBSTRUCT(w32_install_opts, w32_install_conf)},
{"priority", OPT_CHOICE(w32_priority,
{"no", 0},
{"realtime", REALTIME_PRIORITY_CLASS},
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ typedef struct MPOpts {
char **playlist_exts;
bool osd_bar_visible;

struct w32_install_opts *w32_install_opts;
int w32_priority;
bool media_controls;

Expand Down
Loading

0 comments on commit 059d866

Please sign in to comment.