the log feature was not working

This commit is contained in:
Frank Skare
2019-10-13 04:12:48 +02:00
parent f5e0c92824
commit 0cd769fc0c
8 changed files with 56 additions and 24 deletions

View File

@@ -19,7 +19,7 @@ namespace mpvnet
try
{
AggregateCatalog catalog = new AggregateCatalog();
string dir = PathHelp.StartupPath + "Extensions";
string dir = Folder.Startup + "Extensions";
if (Directory.Exists(dir))
{

View File

@@ -291,8 +291,34 @@ namespace mpvnet
}
}
public class Folder
{
public static string Startup { get; } = Application.StartupPath + "\\";
}
public class PathHelp
{
public static string StartupPath { get; } = Application.StartupPath + "\\";
public static string GetBaseName(string value)
{
if (string.IsNullOrEmpty(value))
return "";
int index = value.IndexOf("/");
if (index > -1)
value = value.Substring(index + 1);
index = value.IndexOf("\\");
if (index > -1)
value = value.Substring(index + 1);
index = value.LastIndexOf(".");
if (index > -1)
value = value.Substring(0, index);
return value;
}
}
}

View File

@@ -7,7 +7,7 @@ public class Native
[DllImport("kernel32.dll")]
public static extern bool AttachConsole(int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
[DllImport("kernel32.dll")]
public static extern bool FreeConsole();
[DllImport("kernel32.dll")]
@@ -22,7 +22,7 @@ public class Native
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
@@ -37,7 +37,7 @@ public class Native
[DllImport("user32.dll")]
public static extern bool AdjustWindowRect(ref RECT lpRect, uint dwStyle, bool bMenu);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
@@ -78,7 +78,7 @@ public class Native
Bottom = bottom;
}
public Rectangle ToRectangle() { return Rectangle.FromLTRB(Left, Top, Right, Bottom); }
public Rectangle ToRectangle() => Rectangle.FromLTRB(Left, Top, Right, Bottom);
public Size Size => new Size(Right - Left, Bottom - Top);
public int Width => Right - Left;
public int Height => Bottom - Top;

View File

@@ -10,7 +10,7 @@ namespace mpvnet
{
InitializeComponent();
Version.Text = $"mpv.net Version {System.Windows.Forms.Application.ProductVersion} ({File.GetLastWriteTime(System.Windows.Forms.Application.ExecutablePath).ToShortDateString()})";
mpvVersion.Text = $"{mp.get_property_string("mpv-version")} ({File.GetLastWriteTime(PathHelp.StartupPath + "mpv-1.dll").ToShortDateString()})";
mpvVersion.Text = $"{mp.get_property_string("mpv-version")} ({File.GetLastWriteTime(Folder.Startup + "mpv-1.dll").ToShortDateString()})";
}
protected override void OnPreviewKeyDown(KeyEventArgs e) => Close();

View File

@@ -134,7 +134,6 @@ namespace mpvnet
StringBuilder buf = new StringBuilder(bufsize);
Everything_SetSearch(searchtext);
Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH);
Everything_SetSort(EVERYTHING_SORT_SIZE_DESCENDING);
Everything_Query(true);
for (i = 0; i < Everything_GetNumResults(); i++)

View File

@@ -148,7 +148,7 @@ namespace mpvnet
get {
if (_ConfigFolder == null)
{
string portableFolder = PathHelp.StartupPath + "portable_config\\";
string portableFolder = Folder.Startup + "portable_config\\";
_ConfigFolder = portableFolder;
if (!Directory.Exists(_ConfigFolder))
@@ -189,7 +189,7 @@ namespace mpvnet
}
}
if (PathHelp.StartupPath == _ConfigFolder)
if (Folder.Startup == _ConfigFolder)
{
Msg.ShowError("Startup folder and config folder cannot be identical, using portable_config instead.");
_ConfigFolder = portableFolder;
@@ -236,9 +236,9 @@ namespace mpvnet
public static void LoadMpvScripts()
{
if (Directory.Exists(PathHelp.StartupPath + "Scripts"))
if (Directory.Exists(Folder.Startup + "Scripts"))
{
string[] startupScripts = Directory.GetFiles(PathHelp.StartupPath + "Scripts");
string[] startupScripts = Directory.GetFiles(Folder.Startup + "Scripts");
foreach (string path in startupScripts)
if ((path.EndsWith(".lua") || path.EndsWith(".js")) && KnownScripts.Contains(Path.GetFileName(path)))
@@ -250,9 +250,9 @@ namespace mpvnet
public static void LoadScripts()
{
if (Directory.Exists(PathHelp.StartupPath + "Scripts"))
if (Directory.Exists(Folder.Startup + "Scripts"))
{
foreach (string scriptPath in Directory.GetFiles(PathHelp.StartupPath + "Scripts"))
foreach (string scriptPath in Directory.GetFiles(Folder.Startup + "Scripts"))
{
if (KnownScripts.Contains(Path.GetFileName(scriptPath)))
{
@@ -329,7 +329,10 @@ namespace mpvnet
}
VideoSizeAutoResetEvent.Set();
Task.Run(new Action(() => ReadMetaData()));
WriteHistory(get_property_string("path"));
string path = mp.get_property_string("path");
if (path.Contains("://"))
path = mp.get_property_string("media-title");
WriteHistory(path);
FileLoaded?.Invoke();
break;
case mpv_event_id.MPV_EVENT_TRACKS_CHANGED:
@@ -750,12 +753,14 @@ namespace mpvnet
static void WriteHistory(string path)
{
if (!File.Exists(ConfigFolder + "history.txt") || !File.Exists(path)) return;
if (!File.Exists(ConfigFolder + "history.txt"))
return;
int totalMinutes = Convert.ToInt32((DateTime.Now - LastHistoryStartDateTime).TotalMinutes);
if (File.Exists(LastHistoryPath) && totalMinutes > 1)
if (PathHelp.GetBaseName(LastHistoryPath) != "" && totalMinutes > 1)
File.AppendAllText(ConfigFolder + "history.txt", DateTime.Now.ToString().Substring(0, 16) +
" " + totalMinutes.ToString().PadLeft(3) + " " + Path.GetFileNameWithoutExtension(LastHistoryPath) + "\r\n");
" " + totalMinutes.ToString().PadLeft(3) + " " + PathHelp.GetBaseName(LastHistoryPath) + "\r\n");
LastHistoryPath = path;
LastHistoryStartDateTime = DateTime.Now;