minor changes

This commit is contained in:
Frank Skare
2020-03-16 03:31:26 +01:00
parent 97ce08c4c7
commit 067bdd20d7
6 changed files with 65 additions and 58 deletions

View File

@@ -4,7 +4,9 @@
- new: menu item 'View > Show Progress' (p key) to show progress bar - new: menu item 'View > Show Progress' (p key) to show progress bar
- new: `script-message mpv.net playlist-first`, unlike mpv does not - new: `script-message mpv.net playlist-first`, unlike mpv does not
restart if the first file is already active restart if the first file is already active
- new: if mpv.net is started from the terminal and an error happens
then the error is printed to the terminal instead of shown
with a message box
- fix: update routine did only work when mpv.net was located in 'Program Files' - fix: update routine did only work when mpv.net was located in 'Program Files'
- fix: errors were just ignored and only seen printed in the terminal in case mpv.net - fix: errors were just ignored and only seen printed in the terminal in case mpv.net
was started from the terminal, now for every error a message box is shown was started from the terminal, now for every error a message box is shown

View File

@@ -2,15 +2,15 @@
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
$desktopDir = [Environment]::GetFolderPath('Desktop') $desktopDir = [Environment]::GetFolderPath('Desktop')
$exePath = (Get-Location).Path + '\mpv.net\bin\x64\mpvnet.exe' $exePath = $PSScriptRoot + '\mpv.net\bin\x64\mpvnet.exe'
$version = [Reflection.Assembly]::LoadFile($exePath).GetName().Version $version = [Reflection.Assembly]::LoadFile($exePath).GetName().Version
$msbuild = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe' $msbuild = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe'
$iscc = 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe' $inno = 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe'
$7z = 'C:\Program Files\7-Zip\7z.exe' $7z = 'C:\Program Files\7-Zip\7z.exe'
if ($version.Revision -ne 0) if ($version.Revision -ne 0)
{ {
& $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x64 & $msbuild mpv.net.sln -t:Rebuild -p:Configuration=Debug -p:Platform=x64
if ($LastExitCode) { throw $LastExitCode } if ($LastExitCode) { throw $LastExitCode }
$targetDir = "$desktopDir\mpv.net-portable-x64-$version-beta" $targetDir = "$desktopDir\mpv.net-portable-x64-$version-beta"
@@ -38,10 +38,10 @@ else
& $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x86 & $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x86
if ($LastExitCode) { throw $LastExitCode } if ($LastExitCode) { throw $LastExitCode }
& $iscc /Darch=x64 setup.iss & $inno /Darch=x64 setup.iss
if ($LastExitCode) { throw $LastExitCode } if ($LastExitCode) { throw $LastExitCode }
& $iscc /Darch=x86 setup.iss & $inno /Darch=x86 setup.iss
if ($LastExitCode) { throw $LastExitCode } if ($LastExitCode) { throw $LastExitCode }
$targetDir = $desktopDir + "\mpv.net-portable-x64-$version" $targetDir = $desktopDir + "\mpv.net-portable-x64-$version"

View File

@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using UI; using UI;
using static libmpv;
namespace mpvnet namespace mpvnet
{ {
@@ -86,7 +87,11 @@ namespace mpvnet
mp.LogMessage += LogMessage; mp.LogMessage += LogMessage;
} }
private static void LogMessage(string msg) => Msg.ShowError(msg); private static void LogMessage(mpv_log_level level, string msg)
{
if (!App.IsStartedFromTerminal && level == mpv_log_level.MPV_LOG_LEVEL_FATAL)
Msg.ShowError(msg);
}
private static void Initialized() private static void Initialized()
{ {

View File

@@ -278,7 +278,9 @@ namespace mpvnet
public static void CycleAudio() public static void CycleAudio()
{ {
string path = mp.get_property_string("path"); string path = mp.get_property_string("path");
if (!File.Exists(path)) return;
if (!File.Exists(path))
return;
using (MediaInfo mi = new MediaInfo(path)) using (MediaInfo mi = new MediaInfo(path))
{ {

View File

@@ -7,8 +7,8 @@ class ConsoleHelp
public static void WriteError(object obj) public static void WriteError(object obj)
{ {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(obj); Console.WriteLine("[mpvnet] " + obj);
Console.ResetColor(); Console.ResetColor();
Trace.WriteLine(obj); Trace.WriteLine(obj);
} }
} }

View File

@@ -28,8 +28,8 @@ namespace mpvnet
// Lua/JS event libmpv event // Lua/JS event libmpv event
// MPV_EVENT_NONE // MPV_EVENT_NONE
public static event Action <mpv_log_level, string>LogMessage; // log-message MPV_EVENT_LOG_MESSAGE
public static event Action Shutdown; // shutdown MPV_EVENT_SHUTDOWN public static event Action Shutdown; // shutdown MPV_EVENT_SHUTDOWN
public static event Action <string>LogMessage; // log-message MPV_EVENT_LOG_MESSAGE
public static event Action GetPropertyReply; // get-property-reply MPV_EVENT_GET_PROPERTY_REPLY public static event Action GetPropertyReply; // get-property-reply MPV_EVENT_GET_PROPERTY_REPLY
public static event Action SetPropertyReply; // set-property-reply MPV_EVENT_SET_PROPERTY_REPLY public static event Action SetPropertyReply; // set-property-reply MPV_EVENT_SET_PROPERTY_REPLY
public static event Action CommandReply; // command-reply MPV_EVENT_COMMAND_REPLY public static event Action CommandReply; // command-reply MPV_EVENT_COMMAND_REPLY
@@ -97,7 +97,7 @@ namespace mpvnet
if (Handle == IntPtr.Zero) if (Handle == IntPtr.Zero)
throw new Exception("error mpv_create"); throw new Exception("error mpv_create");
mpv_request_log_messages(Handle, "fatal"); mpv_request_log_messages(Handle, "info");
Task.Run(() => EventLoop()); Task.Run(() => EventLoop());
if (App.IsStartedFromTerminal) if (App.IsStartedFromTerminal)
@@ -306,7 +306,7 @@ namespace mpvnet
case mpv_event_id.MPV_EVENT_LOG_MESSAGE: case mpv_event_id.MPV_EVENT_LOG_MESSAGE:
{ {
var data = (mpv_event_log_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_log_message)); var data = (mpv_event_log_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_log_message));
LogMessage?.Invoke($"[{data.prefix}] {data.text}"); LogMessage?.Invoke(data.log_level, $"[{data.prefix}] {data.text}");
} }
break; break;
case mpv_event_id.MPV_EVENT_GET_PROPERTY_REPLY: case mpv_event_id.MPV_EVENT_GET_PROPERTY_REPLY:
@@ -343,8 +343,10 @@ namespace mpvnet
VideoSizeAutoResetEvent.Set(); VideoSizeAutoResetEvent.Set();
Task.Run(new Action(() => ReadMetaData())); Task.Run(new Action(() => ReadMetaData()));
string path = mp.get_property_string("path"); string path = mp.get_property_string("path");
if (path.Contains("://")) if (path.Contains("://"))
path = mp.get_property_string("media-title"); path = mp.get_property_string("media-title");
WriteHistory(path); WriteHistory(path);
FileLoaded?.Invoke(); FileLoaded?.Invoke();
} }
@@ -504,90 +506,71 @@ namespace mpvnet
Marshal.FreeHGlobal(mainPtr); Marshal.FreeHGlobal(mainPtr);
if (err < 0) if (err < 0)
throw new Exception("error executing command:\n\n" + HandleError(err, true, "error executing command:", string.Join("\n", args));
string.Join("\n", args) + "\r\n\r\n" + GetError(err));
} }
public static void command(string command, bool throwException = false) public static void command(string command, bool throwException = false)
{ {
mpv_error err = mpv_command_string(Handle, command); mpv_error err = mpv_command_string(Handle, command);
if (err < 0 && throwException) if (err < 0)
throw new Exception("error executing command:\n\n" + command + "\r\n\r\n" + GetError(err)); HandleError(err, throwException, "error executing command:", command);
} }
public static void set_property_string(string name, string value, bool throwOnException = false) public static void set_property_string(string name, string value, bool throwException = false)
{ {
byte[] bytes = GetUtf8Bytes(value); byte[] bytes = GetUtf8Bytes(value);
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes); mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
if (err < 0 && throwOnException) if (err < 0)
throw new Exception($"error setting property: {name} = " + value + "\r\n\r\n" + GetError(err)); HandleError(err, throwException, $"error setting property: {name} = " + value);
} }
public static string get_property_string(string name, bool throwOnException = false) public static string get_property_string(string name, bool throwException = false)
{ {
try mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer);
if (err == 0)
{ {
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer);
if (err < 0)
{
if (throwOnException)
throw new Exception($"error getting property: {name}\n\n" + GetError(err));
return "";
}
string ret = ConvertFromUtf8(lpBuffer); string ret = ConvertFromUtf8(lpBuffer);
mpv_free(lpBuffer); mpv_free(lpBuffer);
return ret; return ret;
} }
catch (Exception e)
{ HandleError(err, throwException, $"error getting property: {name}");
if (throwOnException) return "";
throw e;
return "";
}
} }
public static int get_property_int(string name, bool throwOnException = false) public static int get_property_int(string name, bool throwException = false)
{ {
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer); mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer);
if (err < 0) if (err < 0)
{ HandleError(err, throwException, $"error getting property: {name}");
if (throwOnException)
throw new Exception($"error getting property: {name}\n\n" + GetError(err));
return 0;
}
return lpBuffer.ToInt32(); return lpBuffer.ToInt32();
} }
public static double get_property_number(string name, bool throwOnException = false) public static double get_property_number(string name, bool throwException = false)
{ {
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_DOUBLE, out double value); mpv_format.MPV_FORMAT_DOUBLE, out double value);
if (err < 0) if (err < 0)
{ HandleError(err, throwException, $"error getting property: {name}");
if (throwOnException)
throw new Exception($"error getting property: {name}\n\n" + GetError(err));
return 0;
}
return value; return value;
} }
public static void set_property_int(string name, int value, bool throwOnException = false) public static void set_property_int(string name, int value, bool throwException = false)
{ {
Int64 val = value; Int64 val = value;
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val); mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
if (err < 0 && throwOnException) if (err < 0)
throw new Exception($"error setting property: {name} = {value}\n\n" + GetError(err)); HandleError(err, throwException, $"error setting property: {name} = {value}");
} }
public static void observe_property_int(string name, Action<int> action) public static void observe_property_int(string name, Action<int> action)
@@ -596,7 +579,7 @@ namespace mpvnet
name, mpv_format.MPV_FORMAT_INT64); name, mpv_format.MPV_FORMAT_INT64);
if (err < 0) if (err < 0)
throw new Exception($"error observing property: {name}\n\n" + GetError(err)); HandleError(err, true, $"error observing property: {name}");
else else
lock (IntPropChangeActions) lock (IntPropChangeActions)
IntPropChangeActions.Add(new KeyValuePair<string, Action<int>>(name, action)); IntPropChangeActions.Add(new KeyValuePair<string, Action<int>>(name, action));
@@ -608,7 +591,7 @@ namespace mpvnet
name, mpv_format.MPV_FORMAT_DOUBLE); name, mpv_format.MPV_FORMAT_DOUBLE);
if (err < 0) if (err < 0)
throw new Exception($"error observing property: {name}\n\n" + GetError(err)); HandleError(err, true, $"error observing property: {name}");
else else
lock (DoublePropChangeActions) lock (DoublePropChangeActions)
DoublePropChangeActions.Add(new KeyValuePair<string, Action<double>>(name, action)); DoublePropChangeActions.Add(new KeyValuePair<string, Action<double>>(name, action));
@@ -620,7 +603,7 @@ namespace mpvnet
name, mpv_format.MPV_FORMAT_FLAG); name, mpv_format.MPV_FORMAT_FLAG);
if (err < 0) if (err < 0)
throw new Exception($"error observing property: {name}\n\n" + GetError(err)); HandleError(err, true, $"error observing property: {name}");
else else
lock (BoolPropChangeActions) lock (BoolPropChangeActions)
BoolPropChangeActions.Add(new KeyValuePair<string, Action<bool>>(name, action)); BoolPropChangeActions.Add(new KeyValuePair<string, Action<bool>>(name, action));
@@ -632,12 +615,24 @@ namespace mpvnet
name, mpv_format.MPV_FORMAT_STRING); name, mpv_format.MPV_FORMAT_STRING);
if (err < 0) if (err < 0)
throw new Exception($"error observing property: {name}\n\n" + GetError(err)); HandleError(err, true, $"error observing property: {name}");
else else
lock (StringPropChangeActions) lock (StringPropChangeActions)
StringPropChangeActions.Add(new KeyValuePair<string, Action<string>>(name, action)); StringPropChangeActions.Add(new KeyValuePair<string, Action<string>>(name, action));
} }
public static void HandleError(mpv_error err, bool throwException, params string[] messages)
{
if (throwException)
{
foreach (string msg in messages)
ConsoleHelp.WriteError(msg);
ConsoleHelp.WriteError(GetError(err));
throw new Exception(string.Join("\r\r", messages) + "\r\r"+ GetError(err));
}
}
public static void ProcessCommandLine(bool preInit) public static void ProcessCommandLine(bool preInit)
{ {
var args = Environment.GetCommandLineArgs().Skip(1); var args = Environment.GetCommandLineArgs().Skip(1);
@@ -666,6 +661,7 @@ namespace mpvnet
if (preInit && preInitProperties.Contains(left)) if (preInit && preInitProperties.Contains(left))
{ {
mp.ProcessProperty(left, right); mp.ProcessProperty(left, right);
if (!App.ProcessProperty(left, right)) if (!App.ProcessProperty(left, right))
set_property_string(left, right, true); set_property_string(left, right, true);
} }
@@ -674,6 +670,7 @@ namespace mpvnet
if (!PrintCommandLineArgument(arg)) if (!PrintCommandLineArgument(arg))
{ {
mp.ProcessProperty(left, right); mp.ProcessProperty(left, right);
if (!App.ProcessProperty(left, right)) if (!App.ProcessProperty(left, right))
set_property_string(left, right, true); set_property_string(left, right, true);
} }
@@ -681,7 +678,8 @@ namespace mpvnet
} }
catch (Exception e) catch (Exception e)
{ {
Msg.ShowException(e); if (!App.IsStartedFromTerminal)
Msg.ShowException(e);
} }
} }
} }