tweaks and refactoring
This commit is contained in:
@@ -59,7 +59,9 @@ namespace RatingAddon
|
|||||||
{
|
{
|
||||||
if (args[0] != "rate-file" || ! int.TryParse(args[1], out int rating))
|
if (args[0] != "rate-file" || ! int.TryParse(args[1], out int rating))
|
||||||
return;
|
return;
|
||||||
Dic[mp.get_property_string("path")] = rating;
|
string path = mp.get_property_string("path");
|
||||||
|
if (!File.Exists(path)) return;
|
||||||
|
Dic[path] = rating;
|
||||||
mp.commandv("show-text", $"Rating: {rating}");
|
mp.commandv("show-text", $"Rating: {rating}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,8 @@ namespace mpvnet
|
|||||||
InvokeOnMainThread(new Action(() => {
|
InvokeOnMainThread(new Action(() => {
|
||||||
using (var d = new OpenFileDialog())
|
using (var d = new OpenFileDialog())
|
||||||
{
|
{
|
||||||
d.InitialDirectory = Path.GetDirectoryName(mp.get_property_string("path", false));
|
string path = mp.get_property_string("path");
|
||||||
|
if (File.Exists(path)) d.InitialDirectory = Path.GetDirectoryName(path);
|
||||||
d.Multiselect = true;
|
d.Multiselect = true;
|
||||||
if (d.ShowDialog() == DialogResult.OK)
|
if (d.ShowDialog() == DialogResult.OK)
|
||||||
foreach (string i in d.FileNames)
|
foreach (string i in d.FileNames)
|
||||||
@@ -200,7 +201,9 @@ namespace mpvnet
|
|||||||
InvokeOnMainThread(new Action(() => {
|
InvokeOnMainThread(new Action(() => {
|
||||||
using (var d = new OpenFileDialog())
|
using (var d = new OpenFileDialog())
|
||||||
{
|
{
|
||||||
d.InitialDirectory = Path.GetDirectoryName(mp.get_property_string("path", false));
|
string path = mp.get_property_string("path");
|
||||||
|
if (File.Exists(path))
|
||||||
|
d.InitialDirectory = Path.GetDirectoryName(path);
|
||||||
d.Multiselect = true;
|
d.Multiselect = true;
|
||||||
|
|
||||||
if (d.ShowDialog() == DialogResult.OK)
|
if (d.ShowDialog() == DialogResult.OK)
|
||||||
@@ -212,10 +215,10 @@ namespace mpvnet
|
|||||||
|
|
||||||
public static void CycleAudio()
|
public static void CycleAudio()
|
||||||
{
|
{
|
||||||
string filePath = mp.get_property_string("path", false);
|
string path = mp.get_property_string("path");
|
||||||
if (!File.Exists(filePath)) return;
|
if (!File.Exists(path)) return;
|
||||||
|
|
||||||
using (MediaInfo mi = new MediaInfo(filePath))
|
using (MediaInfo mi = new MediaInfo(path))
|
||||||
{
|
{
|
||||||
MediaTrack[] audTracks = mp.MediaTracks.Where(track => track.Type == "a").ToArray();
|
MediaTrack[] audTracks = mp.MediaTracks.Where(track => track.Type == "a").ToArray();
|
||||||
if (audTracks.Length < 2) return;
|
if (audTracks.Length < 2) return;
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
string filePath = mp.ConfFolder + "\\mpvnet-debug.log";
|
string filePath = mp.ConfFolder + "\\mpvnet-debug.log";
|
||||||
if (File.Exists(filePath)) File.Delete(filePath);
|
if (File.Exists(filePath)) File.Delete(filePath);
|
||||||
Trace.Listeners.Clear();
|
|
||||||
Trace.Listeners.Add(new TextWriterTraceListener(filePath));
|
Trace.Listeners.Add(new TextWriterTraceListener(filePath));
|
||||||
Trace.AutoFlush = true;
|
Trace.AutoFlush = true;
|
||||||
}
|
}
|
||||||
@@ -64,11 +63,6 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Exit()
|
|
||||||
{
|
|
||||||
if (Trace.Listeners.Count > 0) Trace.Listeners[0].Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Dictionary<string, string> _Conf;
|
static Dictionary<string, string> _Conf;
|
||||||
|
|
||||||
public static Dictionary<string, string> Conf {
|
public static Dictionary<string, string> Conf {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace mpvnet
|
namespace mpvnet
|
||||||
{
|
{
|
||||||
@@ -378,7 +379,7 @@ namespace mpvnet
|
|||||||
|
|
||||||
protected override void WndProc(ref Message m)
|
protected override void WndProc(ref Message m)
|
||||||
{
|
{
|
||||||
//System.Diagnostics.Debug.WriteLine(m);
|
//Debug.WriteLine(m);
|
||||||
|
|
||||||
switch (m.Msg)
|
switch (m.Msg)
|
||||||
{
|
{
|
||||||
@@ -549,7 +550,6 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
|
|
||||||
RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray());
|
RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray());
|
||||||
App.Exit();
|
|
||||||
mp.commandv("quit");
|
mp.commandv("quit");
|
||||||
mp.ShutdownAutoResetEvent.WaitOne(3000);
|
mp.ShutdownAutoResetEvent.WaitOne(3000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -410,16 +410,14 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
if (Handle == IntPtr.Zero) return;
|
if (Handle == IntPtr.Zero) return;
|
||||||
int err = mpv_command_string(Handle, command);
|
int err = mpv_command_string(Handle, command);
|
||||||
if (err < 0 && throwException)
|
if (err < 0 && throwException) throw new Exception($"{(mpv_error)err}\n\n" + command);
|
||||||
throw new Exception($"{(mpv_error)err}\r\n\r\n" + 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 throwOnException = false)
|
||||||
{
|
{
|
||||||
byte[] bytes = GetUtf8Bytes(value);
|
byte[] bytes = GetUtf8Bytes(value);
|
||||||
int err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
|
int err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
|
||||||
if (err < 0 && throwOnException)
|
if (err < 0 && throwOnException) throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string get_property_string(string name, bool throwOnException = false)
|
public static string get_property_string(string name, bool throwOnException = false)
|
||||||
@@ -427,7 +425,13 @@ namespace mpvnet
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
int err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer);
|
int err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer);
|
||||||
if (err < 0 && throwOnException) throw new Exception($"{name}: {(mpv_error)err}");
|
|
||||||
|
if (err < 0)
|
||||||
|
{
|
||||||
|
if (throwOnException) throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
string ret = StringFromNativeUtf8(lpBuffer);
|
string ret = StringFromNativeUtf8(lpBuffer);
|
||||||
mpv_free(lpBuffer);
|
mpv_free(lpBuffer);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -443,9 +447,12 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
int err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer);
|
int err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer);
|
||||||
|
|
||||||
if (err < 0 && throwOnException)
|
if (err < 0)
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
{
|
||||||
else
|
if (throwOnException) throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return lpBuffer.ToInt32();
|
return lpBuffer.ToInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,9 +461,12 @@ namespace mpvnet
|
|||||||
double val = 0;
|
double val = 0;
|
||||||
int err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val);
|
int err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val);
|
||||||
|
|
||||||
if (err < 0 && throwOnException)
|
if (err < 0)
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
{
|
||||||
else
|
if (throwOnException) throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,9 +484,7 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
Int64 val = value;
|
Int64 val = value;
|
||||||
int err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
|
int err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
|
||||||
|
if (err < 0 && throwOnException) throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
if (err < 0 && throwOnException)
|
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void observe_property_int(string name, Action<int> action)
|
public static void observe_property_int(string name, Action<int> action)
|
||||||
@@ -642,8 +650,9 @@ namespace mpvnet
|
|||||||
static string LastHistoryPath;
|
static string LastHistoryPath;
|
||||||
static DateTime LastHistoryStartDateTime;
|
static DateTime LastHistoryStartDateTime;
|
||||||
|
|
||||||
static void WriteHistory(string filePath)
|
static void WriteHistory(string path)
|
||||||
{
|
{
|
||||||
|
if (!File.Exists(path)) return;
|
||||||
int totalMinutes = Convert.ToInt32((DateTime.Now - LastHistoryStartDateTime).TotalMinutes);
|
int totalMinutes = Convert.ToInt32((DateTime.Now - LastHistoryStartDateTime).TotalMinutes);
|
||||||
|
|
||||||
if (File.Exists(LastHistoryPath) && totalMinutes > 1)
|
if (File.Exists(LastHistoryPath) && totalMinutes > 1)
|
||||||
@@ -655,7 +664,7 @@ namespace mpvnet
|
|||||||
Path.GetFileNameWithoutExtension(LastHistoryPath) + "\r\n");
|
Path.GetFileNameWithoutExtension(LastHistoryPath) + "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
LastHistoryPath = filePath;
|
LastHistoryPath = path;
|
||||||
LastHistoryStartDateTime = DateTime.Now;
|
LastHistoryStartDateTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -690,7 +699,11 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
MediaTracks.Clear();
|
MediaTracks.Clear();
|
||||||
|
|
||||||
using (MediaInfo mi = new MediaInfo(get_property_string("path")))
|
string path = get_property_string("path");
|
||||||
|
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
using (MediaInfo mi = new MediaInfo(path))
|
||||||
{
|
{
|
||||||
int count = mi.GetCount(MediaInfoStreamKind.Video);
|
int count = mi.GetCount(MediaInfoStreamKind.Video);
|
||||||
|
|
||||||
@@ -767,6 +780,8 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
lock (Chapters)
|
lock (Chapters)
|
||||||
{
|
{
|
||||||
Chapters.Clear();
|
Chapters.Clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user