Skip to content

Commit

Permalink
meson: add mpv-install and mpv-uninstall helpers on Windows
Browse files Browse the repository at this point in the history
They call `--install` / ``--uninstall` for users who don't want to open
console and do it manually, this is one-click solution.
  • Loading branch information
kasper93 committed Feb 19, 2025
1 parent f97b56f commit 64f22b0
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ jobs:
with:
name: mpv-x86_64-windows-msvc
path: |
build/mpv.???
build/mpv.exe
build/mpv*.com
build/mpv.pdb
build/vulkan-*.dll
!build/mpv.lib
- name: Save Cache
uses: actions/cache/save@v4
Expand Down
4 changes: 2 additions & 2 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7952,7 +7952,7 @@ Miscellaneous
more details.

``--install``
(Windows only)
(Windows only) (available also as mpv-install helper)

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
Expand Down Expand Up @@ -7991,7 +7991,7 @@ Miscellaneous
variable, a semicolon-separated list of paths.

``--uninstall``
(Windows only)
(Windows only) (available also as mpv-uninstall helper)

Unregisters mpv as a media player on Windows, undoing all changes made by
the ``--install`` option. This will not remove mpv binary itself.
Expand Down
2 changes: 1 addition & 1 deletion ci/build-mingw64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ meson compile -C $build
if [ "$2" = pack ]; then
mkdir -p artifact/tmp
echo "Copying:"
cp -pv $build/mpv.com $build/mpv.exe artifact/
cp -pv $build/mpv*.com $build/mpv.exe artifact/
# copy everything we can get our hands on
cp -p "$prefix_dir/bin/"*.dll artifact/tmp/
shopt -s nullglob
Expand Down
2 changes: 1 addition & 1 deletion ci/build-win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,6 @@ meson setup build `
-Drubberband=disabled `
-Dwayland=disabled `
-Dx11=disabled
ninja -C build mpv.exe mpv.com libmpv.a
ninja -C build mpv.exe mpv.com mpv-install.com mpv-uninstall.com libmpv.a
cp ./build/subprojects/vulkan-loader/vulkan.dll ./build/vulkan-1.dll
./build/mpv.com -v --no-config
24 changes: 17 additions & 7 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1813,13 +1813,23 @@ if get_option('cplayer')
mpv = executable('mpv', main_fn_source, objects: libmpv.extract_all_objects(recursive: true), dependencies: dependencies,
win_subsystem: get_option('win32-subsystem'), install: true)

if win32 and get_option('win32-subsystem') != 'console'
wrapper_sources= 'osdep/win32-console-wrapper.c'
executable('mpv', wrapper_sources, c_args: ['-municode', '-fno-asynchronous-unwind-tables'],
link_args: ['-municode', '-nostartfiles', '-nodefaultlibs'],
override_options: ['b_sanitize=none'],
dependencies: cc.find_library('pathcch'),
name_suffix: 'com', install: true)
if win32
wrapper_sources = 'osdep/win32-console-wrapper.c'
wrapper_c_args = ['-municode', '-fno-asynchronous-unwind-tables']
wrapper_kwargs = {
'dependencies': cc.find_library('pathcch'),
'link_args': ['-municode', '-nostartfiles', '-nodefaultlibs'],
'override_options': 'b_sanitize=none',
'name_suffix': 'com',
'install': true,
}
if get_option('win32-subsystem') != 'console'
executable('mpv', wrapper_sources, c_args: wrapper_c_args, kwargs: wrapper_kwargs)
endif
executable('mpv-install', wrapper_sources, c_args: wrapper_c_args + '-DMPV_INSTALL',
kwargs: wrapper_kwargs)
executable('mpv-uninstall', wrapper_sources, c_args: wrapper_c_args + '-DMPV_UNINSTALL',
kwargs: wrapper_kwargs)
endif

if darwin
Expand Down
4 changes: 4 additions & 0 deletions osdep/w32_install.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ static void w32_install(struct MPContext *mpctx)
wchar_t *rpath_w = mp_from_utf8(tmp, rpath);
reg_add_str(log, root, KEY_MPV_APP_PATH(".exe"), L"Path", rpath_w);
reg_add_str(log, root, KEY_MPV_APP_PATH(".com"), L"Path", rpath_w);
reg_add_str(log, root, KEY_MPV_APP_PATH("-install.com"), L"Path", rpath_w);
reg_add_str(log, root, KEY_MPV_APP_PATH("-uninstall.com"), L"Path", rpath_w);
}

// Name of the "Open With" entry in the context menu
Expand Down Expand Up @@ -427,6 +429,8 @@ static void w32_uninstall(struct MPContext *mpctx)

reg_del(log, root, KEY_MPV_APP_PATH(".exe"), NULL);
reg_del(log, root, KEY_MPV_APP_PATH(".com"), NULL);
reg_del(log, root, KEY_MPV_APP_PATH("-install.com"), NULL);
reg_del(log, root, KEY_MPV_APP_PATH("-uninstall.com"), NULL);
reg_del(log, root, KEY_MPV_APP, NULL);
reg_del(log, root, KEY_MPV_CAPABILITIES_APP, NULL);
reg_del(log, root, L"Software\\RegisteredApplications", MPV_NAME);
Expand Down
18 changes: 17 additions & 1 deletion osdep/win32-console-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ static DWORD cr_runproc(wchar_t *name, wchar_t *cmdline)
int mainCRTStartup(void);
int mainCRTStartup(void)
{
wchar_t *cmd = GetCommandLineW();
wchar_t *exe = LocalAlloc(LMEM_FIXED, MP_PATH_MAX * sizeof(wchar_t));
DWORD len = GetModuleFileNameW(NULL, exe, MP_PATH_MAX);
if (len < 4 || len == MP_PATH_MAX)
Expand All @@ -94,9 +93,26 @@ int mainCRTStartup(void)
ExitProcess(1);
}

// cmd has to be modifiable, as the documentation states:
// The Unicode version of this function, CreateProcessW, can modify the
// contents of this string.
#if defined(MPV_INSTALL)
wchar_t cmd[] = L"mpv.exe --install";
#elif defined(MPV_UNINSTALL)
wchar_t cmd[] = L"mpv.exe --no-config --uninstall";
#else
wchar_t *cmd = GetCommandLineW();
#endif

// Set an environment variable so the child process can tell whether it
// was started from this wrapper and attach to the console accordingly
SetEnvironmentVariableW(L"_started_from_console", L"yes");

ExitProcess(cr_runproc(exe, cmd));
}

int WinMainCRTStartup(void);
int WinMainCRTStartup(void)
{
return mainCRTStartup();
}

0 comments on commit 64f22b0

Please sign in to comment.