Fix #421 crash choosing Matroska edition in the menu.

This commit is contained in:
stax76
2022-05-20 14:29:21 +02:00
parent bc0fc2a29d
commit 3e499befbc
5 changed files with 161 additions and 202 deletions

View File

@@ -1,4 +1,5 @@
- Fix crash choosing Matroska edition in the menu.
- Fix auto-play not working with user scripts.
- When input.conf is created on the very first start and a
script-opts folder does not exist, a script-opts folder

View File

@@ -25,7 +25,7 @@ namespace mpvnet
static void Execute(string file)
{
string code = File.ReadAllText(file);
string filename = Path.GetFileNameWithoutExtension(file) + " " + StringHelp.GetMD5Hash(code) + ".dll";
string filename = Path.GetFileNameWithoutExtension(file) + " " + StringHelp.GetMD5Hash(code) + "-v5.dll";
string outputFile = Path.Combine(Path.GetTempPath(), filename);
if (!File.Exists(outputFile))

View File

@@ -164,8 +164,6 @@ namespace mpvnet
}
public static void ShowInfo()
{
try
{
string performer, title, album, genre, date, duration, text = "";
long fileSize = 0;
@@ -232,11 +230,6 @@ namespace mpvnet
Core.CommandV("show-text", text, "5000");
}
catch (Exception e)
{
App.ShowException(e);
}
}
static string FormatTime(double value) => ((int)value).ToString("00");

View File

@@ -676,12 +676,10 @@ namespace mpvnet
IsLogoVisible = false;
}
public void Command(string command, bool throwException = false)
public void Command(string command)
{
mpv_error err = mpv_command_string(Handle, command);
if (err < 0)
HandleError(err, throwException, "error executing command:", command);
HandleError(err, "error executing command:", command);
}
public void CommandV(params string[] args)
@@ -705,9 +703,7 @@ namespace mpvnet
Marshal.FreeHGlobal(ptr);
Marshal.FreeHGlobal(rootPtr);
if (err < 0)
HandleError(err, true, "error executing command:", string.Join("\n", args));
HandleError(err, "error executing command:", string.Join("\n", args));
}
public string Expand(string value)
@@ -742,7 +738,7 @@ namespace mpvnet
if (err < 0)
{
HandleError(err, true, "error executing command:", string.Join("\n", args));
HandleError(err, "error executing command:", string.Join("\n", args));
Marshal.FreeHGlobal(resultNodePtr);
return "property expansion error";
}
@@ -754,86 +750,68 @@ namespace mpvnet
return ret;
}
public bool GetPropertyBool(string name, bool throwException = false)
public bool GetPropertyBool(string name)
{
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_FLAG, out IntPtr lpBuffer);
if (err < 0)
HandleError(err, throwException, $"error getting property: {name}");
HandleError(err, $"error getting property: {name}");
return lpBuffer.ToInt32() != 0;
}
public void SetPropertyBool(string name, bool value, bool throwException = false)
public void SetPropertyBool(string name, bool value)
{
long val = value ? 1 : 0;
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_FLAG, ref val);
if (err < 0)
HandleError(err, throwException, $"error setting property: {name} = {value}");
HandleError(err, $"error setting property: {name} = {value}");
}
public int GetPropertyInt(string name, bool throwException = false)
public int GetPropertyInt(string name)
{
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer);
if (err < 0)
HandleError(err, throwException, $"error getting property: {name}");
if (App.DebugMode)
HandleError(err, $"error getting property: {name}");
return lpBuffer.ToInt32();
}
public void SetPropertyInt(string name, int value, bool throwException = false)
public void SetPropertyInt(string name, int value)
{
long val = value;
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
if (err < 0)
HandleError(err, throwException, $"error setting property: {name} = {value}");
HandleError(err, $"error setting property: {name} = {value}");
}
public void SetPropertyLong(string name, long value, bool throwException = false)
public void SetPropertyLong(string name, long value)
{
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref value);
if (err < 0)
HandleError(err, throwException, $"error setting property: {name} = {value}");
HandleError(err, $"error setting property: {name} = {value}");
}
public long GetPropertyLong(string name, bool throwException = false)
public long GetPropertyLong(string name)
{
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer);
if (err < 0)
HandleError(err, throwException, $"error getting property: {name}");
HandleError(err, $"error getting property: {name}");
return lpBuffer.ToInt64();
}
public double GetPropertyDouble(string name, bool throwException = false)
public double GetPropertyDouble(string name)
{
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_DOUBLE, out double value);
if (err < 0)
HandleError(err, throwException, $"error getting property: {name}");
if (App.DebugMode)
HandleError(err, $"error getting property: {name}");
return value;
}
public void SetPropertyDouble(string name, double value, bool throwException = false)
public void SetPropertyDouble(string name, double value)
{
double val = value;
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val);
if (err < 0)
HandleError(err, throwException, $"error setting property: {name} = {value}");
HandleError(err, $"error setting property: {name} = {value}");
}
public string GetPropertyString(string name, bool throwException = false)
public string GetPropertyString(string name)
{
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer);
@@ -845,20 +823,20 @@ namespace mpvnet
return ret;
}
HandleError(err, throwException, $"error getting property: {name}");
if (App.DebugMode)
HandleError(err, $"error getting property: {name}");
return "";
}
public void SetPropertyString(string name, string value, bool throwException = false)
public void SetPropertyString(string name, string value)
{
byte[] bytes = GetUtf8Bytes(value);
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
if (err < 0)
HandleError(err, throwException, $"error setting property: {name} = " + value);
HandleError(err, $"error setting property: {name} = " + value);
}
public string GetPropertyOsdString(string name, bool throwException = false)
public string GetPropertyOsdString(string name)
{
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
mpv_format.MPV_FORMAT_OSD_STRING, out IntPtr lpBuffer);
@@ -870,7 +848,7 @@ namespace mpvnet
return ret;
}
HandleError(err, throwException, $"error getting property: {name}");
HandleError(err, $"error getting property: {name}");
return "";
}
@@ -906,7 +884,7 @@ namespace mpvnet
mpv_error err = mpv_observe_property(Handle, 0, name, mpv_format.MPV_FORMAT_INT64);
if (err < 0)
HandleError(err, true, $"error observing property: {name}");
HandleError(err, $"error observing property: {name}");
else
IntPropChangeActions[name] = new List<Action<int>>();
}
@@ -925,7 +903,7 @@ namespace mpvnet
mpv_error err = mpv_observe_property(Handle, 0, name, mpv_format.MPV_FORMAT_DOUBLE);
if (err < 0)
HandleError(err, true, $"error observing property: {name}");
HandleError(err, $"error observing property: {name}");
else
DoublePropChangeActions[name] = new List<Action<double>>();
}
@@ -944,7 +922,7 @@ namespace mpvnet
mpv_error err = mpv_observe_property(Handle, 0, name, mpv_format.MPV_FORMAT_FLAG);
if (err < 0)
HandleError(err, true, $"error observing property: {name}");
HandleError(err, $"error observing property: {name}");
else
BoolPropChangeActions[name] = new List<Action<bool>>();
}
@@ -963,7 +941,7 @@ namespace mpvnet
mpv_error err = mpv_observe_property(Handle, 0, name, mpv_format.MPV_FORMAT_STRING);
if (err < 0)
HandleError(err, true, $"error observing property: {name}");
HandleError(err, $"error observing property: {name}");
else
StringPropChangeActions[name] = new List<Action<string>>();
}
@@ -982,7 +960,7 @@ namespace mpvnet
mpv_error err = mpv_observe_property(Handle, 0, name, mpv_format.MPV_FORMAT_NONE);
if (err < 0)
HandleError(err, true, $"error observing property: {name}");
HandleError(err, $"error observing property: {name}");
else
PropChangeActions[name] = new List<Action>();
}
@@ -992,15 +970,14 @@ namespace mpvnet
}
}
public void HandleError(mpv_error err, bool throwException, params string[] messages)
public void HandleError(mpv_error err, params string[] messages)
{
if (throwException)
if (err < 0)
{
foreach (string msg in messages)
Terminal.WriteError(msg);
Terminal.WriteError(GetError(err));
throw new Exception(string.Join(BR2, messages) + BR2 + GetError(err) + BR);
}
}
@@ -1018,8 +995,6 @@ namespace mpvnet
string arg = i;
if (arg.StartsWith("-") && arg.Length > 1)
{
try
{
if (!preInit)
{
@@ -1083,7 +1058,7 @@ namespace mpvnet
ProcessProperty(left, right);
if (!App.ProcessProperty(left, right))
SetPropertyString(left, right, true);
SetPropertyString(left, right);
}
else if (!preInit && !preInitProperties.Contains(left))
{
@@ -1091,18 +1066,13 @@ namespace mpvnet
if (!App.ProcessProperty(left, right))
{
SetPropertyString(left, right, true);
SetPropertyString(left, right);
if (left == "shuffle" && right == "yes")
shuffle = true;
}
}
}
catch (Exception e)
{
App.ShowException(e);
}
}
}
if (!preInit)
@@ -1503,8 +1473,11 @@ namespace mpvnet
for (int i = 0; i < editionCount; i++)
{
string title = GetPropertyString($"edition-list/{i}/title");
if (string.IsNullOrEmpty(title))
title = "Edition " + i;
MediaTrack track = new MediaTrack();
track.Text = "E: " + GetPropertyString($"edition-list/{i}/title");
track.Text = "E: " + title;
track.Type = "e";
track.ID = i;
MediaTracks.Add(track);

View File

@@ -90,15 +90,7 @@ namespace mpvnet
if (item.File == "mpv")
{
Core.ProcessProperty(item.Name, item.Value);
try
{
Core.SetPropertyString(item.Name, item.Value, true);
}
catch (Exception ex)
{
App.ShowError(ex.Message);
}
Core.SetPropertyString(item.Name, item.Value);
}
else if (item.File == "mpvnet")
App.ProcessProperty(item.Name, item.Value, true);