Mercurial > vim
comparison src/sound.c @ 33710:385aaea67d33 v9.0.2089
patch 9.0.2089: sound_playfile() fails when using powershell
Commit: https://github.com/vim/vim/commit/15d270019e88a8ba67618adf5efe1aaa81ce354b
Author: GuyBrush <miguel.barro@live.com>
Date: Sat Nov 4 09:48:53 2023 +0100
patch 9.0.2089: sound_playfile() fails when using powershell
Problem: sound_playfile() fails when using powershell
Solution: quote filename using doublequotes, don't escape filename,
because it doesn't use the shell
Avoiding powershell escaping because mci open command doesn't support
single quoted filenames: open 'C:\whatever\sound.wav' is not valid.
closes: #13471
Signed-off-by: GuyBrush <miguel.barro@live.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 04 Nov 2023 10:00:05 +0100 |
parents | def9fc5c92d1 |
children |
comparison
equal
deleted
inserted
replaced
33709:4285faa7a4fb | 33710:385aaea67d33 |
---|---|
320 { | 320 { |
321 char buf[32]; | 321 char buf[32]; |
322 | 322 |
323 vim_snprintf(buf, sizeof(buf), "close sound%06ld", | 323 vim_snprintf(buf, sizeof(buf), "close sound%06ld", |
324 p->snd_id); | 324 p->snd_id); |
325 mciSendString(buf, NULL, 0, 0); | 325 mciSendStringA(buf, NULL, 0, 0); |
326 | 326 |
327 long result = wParam == MCI_NOTIFY_SUCCESSFUL ? 0 | 327 long result = wParam == MCI_NOTIFY_SUCCESSFUL ? 0 |
328 : wParam == MCI_NOTIFY_ABORTED ? 1 : 2; | 328 : wParam == MCI_NOTIFY_ABORTED ? 1 : 2; |
329 call_sound_callback(p, p->snd_id, result); | 329 call_sound_callback(p, p->snd_id, result); |
330 | 330 |
374 void | 374 void |
375 f_sound_playfile(typval_T *argvars, typval_T *rettv) | 375 f_sound_playfile(typval_T *argvars, typval_T *rettv) |
376 { | 376 { |
377 long newid = sound_id + 1; | 377 long newid = sound_id + 1; |
378 size_t len; | 378 size_t len; |
379 char_u *p, *esc; | 379 char_u *p, *filename; |
380 WCHAR *wp; | 380 WCHAR *wp; |
381 soundcb_T *soundcb; | 381 soundcb_T *soundcb; |
382 char buf[32]; | 382 char buf[32]; |
383 MCIERROR err; | 383 MCIERROR err; |
384 | 384 |
385 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) | 385 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
386 return; | 386 return; |
387 | 387 |
388 esc = vim_strsave_shellescape(tv_get_string(&argvars[0]), FALSE, FALSE); | 388 filename = tv_get_string(&argvars[0]); |
389 | 389 |
390 len = STRLEN(esc) + 5 + 18 + 1; | 390 len = STRLEN(filename) + 5 + 18 + 2 + 1; |
391 p = alloc(len); | 391 p = alloc(len); |
392 if (p == NULL) | 392 if (p == NULL) |
393 { | 393 { |
394 free(esc); | 394 return; |
395 return; | 395 } |
396 } | 396 vim_snprintf((char *)p, len, "open \"%s\" alias sound%06ld", filename, newid); |
397 vim_snprintf((char *)p, len, "open %s alias sound%06ld", esc, newid); | |
398 free(esc); | |
399 | 397 |
400 wp = enc_to_utf16((char_u *)p, NULL); | 398 wp = enc_to_utf16((char_u *)p, NULL); |
401 free(p); | 399 free(p); |
402 if (wp == NULL) | 400 if (wp == NULL) |
403 return; | 401 return; |
406 free(wp); | 404 free(wp); |
407 if (err != 0) | 405 if (err != 0) |
408 return; | 406 return; |
409 | 407 |
410 vim_snprintf(buf, sizeof(buf), "play sound%06ld notify", newid); | 408 vim_snprintf(buf, sizeof(buf), "play sound%06ld notify", newid); |
411 err = mciSendString(buf, NULL, 0, sound_window()); | 409 err = mciSendStringA(buf, NULL, 0, sound_window()); |
412 if (err != 0) | 410 if (err != 0) |
413 goto failure; | 411 goto failure; |
414 | 412 |
415 sound_id = newid; | 413 sound_id = newid; |
416 rettv->vval.v_number = sound_id; | 414 rettv->vval.v_number = sound_id; |
424 } | 422 } |
425 return; | 423 return; |
426 | 424 |
427 failure: | 425 failure: |
428 vim_snprintf(buf, sizeof(buf), "close sound%06ld", newid); | 426 vim_snprintf(buf, sizeof(buf), "close sound%06ld", newid); |
429 mciSendString(buf, NULL, 0, NULL); | 427 mciSendStringA(buf, NULL, 0, NULL); |
430 } | 428 } |
431 | 429 |
432 void | 430 void |
433 f_sound_stop(typval_T *argvars, typval_T *rettv UNUSED) | 431 f_sound_stop(typval_T *argvars, typval_T *rettv UNUSED) |
434 { | 432 { |
438 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) | 436 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) |
439 return; | 437 return; |
440 | 438 |
441 id = tv_get_number(&argvars[0]); | 439 id = tv_get_number(&argvars[0]); |
442 vim_snprintf(buf, sizeof(buf), "stop sound%06ld", id); | 440 vim_snprintf(buf, sizeof(buf), "stop sound%06ld", id); |
443 mciSendString(buf, NULL, 0, NULL); | 441 mciSendStringA(buf, NULL, 0, NULL); |
444 } | 442 } |
445 | 443 |
446 void | 444 void |
447 f_sound_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) | 445 f_sound_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
448 { | 446 { |
449 PlaySoundW(NULL, NULL, 0); | 447 PlaySoundW(NULL, NULL, 0); |
450 mciSendString("close all", NULL, 0, NULL); | 448 mciSendStringA("close all", NULL, 0, NULL); |
451 } | 449 } |
452 | 450 |
453 # if defined(EXITFREE) | 451 # if defined(EXITFREE) |
454 void | 452 void |
455 sound_free(void) | 453 sound_free(void) |