fix issue with startup folder and config folder beeing identical
This commit is contained in:
@@ -15,6 +15,11 @@
|
|||||||
environment variable and the OS default apps settings can be opened (Win 10 only)
|
environment variable and the OS default apps settings can be opened (Win 10 only)
|
||||||
- Error messages are shown when unknown scripts and extensions are found in the startup folder
|
- Error messages are shown when unknown scripts and extensions are found in the startup folder
|
||||||
because user scripts and extensions are supposed to be located in the config folder instead
|
because user scripts and extensions are supposed to be located in the config folder instead
|
||||||
|
- when the config folder and the startup folder were identical then extensions were loaded
|
||||||
|
twice and script were loaded four times because the script host is an extension, there is
|
||||||
|
now a check to ensure extensions and scripts are only loaded once. On first start there
|
||||||
|
is no longer an option to select the startup folder as config folder, it's still possible
|
||||||
|
using a custom folder but discouraged
|
||||||
|
|
||||||
### 5.0
|
### 5.0
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using System;
|
|||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
using mpvnet;
|
using mpvnet;
|
||||||
using CSScriptLibrary;
|
using CSScriptLibrary;
|
||||||
@@ -29,8 +28,8 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten
|
|||||||
if (Directory.Exists(mp.ConfigFolder + "scripts"))
|
if (Directory.Exists(mp.ConfigFolder + "scripts"))
|
||||||
scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs"));
|
scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs"));
|
||||||
|
|
||||||
if (Directory.Exists(Application.StartupPath + "\\scripts"))
|
if (Directory.Exists(PathHelp.StartupPath + "scripts") && mp.ConfigFolder != PathHelp.StartupPath)
|
||||||
foreach (string file in Directory.GetFiles(Application.StartupPath + "\\scripts", "*.cs"))
|
foreach (string file in Directory.GetFiles(PathHelp.StartupPath + "scripts", "*.cs"))
|
||||||
App.UnknownModule(file);
|
App.UnknownModule(file);
|
||||||
|
|
||||||
if (scriptFiles.Count == 0) return;
|
if (scriptFiles.Count == 0) return;
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
fileSize = new FileInfo(path).Length;
|
fileSize = new FileInfo(path).Length;
|
||||||
|
|
||||||
if (App.AudioTypes.Contains(Path.GetExtension(path).ToLower().TrimStart('.')))
|
if (App.AudioTypes.Contains(PathHelp.GetShortExtension(path)))
|
||||||
{
|
{
|
||||||
using (MediaInfo mediaInfo = new MediaInfo(path))
|
using (MediaInfo mediaInfo = new MediaInfo(path))
|
||||||
{
|
{
|
||||||
@@ -111,13 +111,13 @@ namespace mpvnet
|
|||||||
if (date != "") text += "Year: " + date + "\n";
|
if (date != "") text += "Year: " + date + "\n";
|
||||||
if (duration != "") text += "Length: " + duration + "\n";
|
if (duration != "") text += "Length: " + duration + "\n";
|
||||||
text += "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n";
|
text += "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n";
|
||||||
text += "Type: " + Path.GetExtension(path).ToUpper().TrimStart('.');
|
text += "Type: " + PathHelp.GetShortExtension(path).ToUpper();
|
||||||
|
|
||||||
mp.commandv("show-text", text, "5000");
|
mp.commandv("show-text", text, "5000");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (App.ImageTypes.Contains(Path.GetExtension(path).ToLower().TrimStart('.')))
|
else if (App.ImageTypes.Contains(PathHelp.GetShortExtension(path)))
|
||||||
{
|
{
|
||||||
using (MediaInfo mediaInfo = new MediaInfo(path))
|
using (MediaInfo mediaInfo = new MediaInfo(path))
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,7 @@ namespace mpvnet
|
|||||||
"Width: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Width") + "\n" +
|
"Width: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Width") + "\n" +
|
||||||
"Height: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Height") + "\n" +
|
"Height: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Height") + "\n" +
|
||||||
"Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n" +
|
"Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n" +
|
||||||
"Type: " + Path.GetExtension(path).ToUpper().TrimStart('.');
|
"Type: " + PathHelp.GetShortExtension(path).ToUpper();
|
||||||
|
|
||||||
mp.commandv("show-text", text, "5000");
|
mp.commandv("show-text", text, "5000");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.ComponentModel.Composition.Hosting;
|
using System.ComponentModel.Composition.Hosting;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace mpvnet
|
namespace mpvnet
|
||||||
@@ -20,7 +19,7 @@ namespace mpvnet
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
AggregateCatalog catalog = new AggregateCatalog();
|
AggregateCatalog catalog = new AggregateCatalog();
|
||||||
string dir = Application.StartupPath + "\\Extensions";
|
string dir = PathHelp.StartupPath + "Extensions";
|
||||||
|
|
||||||
if (Directory.Exists(dir))
|
if (Directory.Exists(dir))
|
||||||
{
|
{
|
||||||
@@ -35,9 +34,9 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = mp.ConfigFolder + "\\Extensions";
|
dir = mp.ConfigFolder + "Extensions";
|
||||||
|
|
||||||
if (Directory.Exists(dir))
|
if (Directory.Exists(dir) && mp.ConfigFolder != PathHelp.StartupPath)
|
||||||
foreach (string i in Directory.GetDirectories(dir))
|
foreach (string i in Directory.GetDirectories(dir))
|
||||||
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Extension.dll"));
|
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Extension.dll"));
|
||||||
|
|
||||||
|
|||||||
@@ -388,6 +388,8 @@ namespace mpvnet
|
|||||||
|
|
||||||
public class PathHelp
|
public class PathHelp
|
||||||
{
|
{
|
||||||
|
public static string StartupPath { get; } = Application.StartupPath + "\\";
|
||||||
|
|
||||||
public static string GetFileName(string path)
|
public static string GetFileName(string path)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path)) return "";
|
if (string.IsNullOrEmpty(path)) return "";
|
||||||
@@ -397,5 +399,10 @@ namespace mpvnet
|
|||||||
if (index > -1) return path.Substring(index + 1);
|
if (index > -1) return path.Substring(index + 1);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetShortExtension(string path)
|
||||||
|
{
|
||||||
|
return Path.GetExtension(path).ToLower().TrimStart('.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -140,7 +139,7 @@ namespace mpvnet
|
|||||||
for (i = 0; i < Everything_GetNumResults(); i++)
|
for (i = 0; i < Everything_GetNumResults(); i++)
|
||||||
{
|
{
|
||||||
Everything_GetResultFullPathName(i, buf, bufsize);
|
Everything_GetResultFullPathName(i, buf, bufsize);
|
||||||
string ext = Path.GetExtension(buf.ToString()).TrimStart('.').ToLower();
|
string ext = PathHelp.GetShortExtension(buf.ToString());
|
||||||
|
|
||||||
if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext) ||
|
if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext) ||
|
||||||
App.ImageTypes.Contains(ext))
|
App.ImageTypes.Contains(ext))
|
||||||
|
|||||||
@@ -138,17 +138,16 @@ namespace mpvnet
|
|||||||
get {
|
get {
|
||||||
if (_ConfigFolder == null)
|
if (_ConfigFolder == null)
|
||||||
{
|
{
|
||||||
_ConfigFolder = Application.StartupPath + "\\portable_config\\";
|
_ConfigFolder = PathHelp.StartupPath + "portable_config\\";
|
||||||
|
|
||||||
if (!Directory.Exists(_ConfigFolder))
|
if (!Directory.Exists(_ConfigFolder))
|
||||||
_ConfigFolder = RegHelp.GetString(App.RegPath, "ConfigFolder");
|
_ConfigFolder = RegHelp.GetString(App.RegPath, "ConfigFolder");
|
||||||
|
|
||||||
if (!Directory.Exists(_ConfigFolder))
|
if (!Directory.Exists(_ConfigFolder))
|
||||||
{
|
{
|
||||||
string portableFolder = Application.StartupPath + "\\portable_config\\";
|
string portableFolder = PathHelp.StartupPath + "portable_config\\";
|
||||||
string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv.net\\";
|
string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv.net\\";
|
||||||
string appdataFolderMpv = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\";
|
string appdataFolderMpv = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\";
|
||||||
string startupFolder = Application.StartupPath + "\\";
|
|
||||||
|
|
||||||
using (TaskDialog<string> td = new TaskDialog<string>())
|
using (TaskDialog<string> td = new TaskDialog<string>())
|
||||||
{
|
{
|
||||||
@@ -215,7 +214,7 @@ namespace mpvnet
|
|||||||
|
|
||||||
public static void LoadMpvScripts()
|
public static void LoadMpvScripts()
|
||||||
{
|
{
|
||||||
string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");
|
string[] startupScripts = Directory.GetFiles(PathHelp.StartupPath + "Scripts");
|
||||||
|
|
||||||
foreach (string path in startupScripts)
|
foreach (string path in startupScripts)
|
||||||
if (path.EndsWith(".lua") || path.EndsWith(".js"))
|
if (path.EndsWith(".lua") || path.EndsWith(".js"))
|
||||||
@@ -229,9 +228,9 @@ namespace mpvnet
|
|||||||
|
|
||||||
public static void LoadScripts()
|
public static void LoadScripts()
|
||||||
{
|
{
|
||||||
if (Directory.Exists(Application.StartupPath + "\\Scripts"))
|
if (Directory.Exists(PathHelp.StartupPath + "Scripts"))
|
||||||
{
|
{
|
||||||
foreach (string path in Directory.GetFiles(Application.StartupPath + "\\Scripts"))
|
foreach (string path in Directory.GetFiles(PathHelp.StartupPath + "Scripts"))
|
||||||
{
|
{
|
||||||
if (KnownScripts.Contains(Path.GetFileName(path)))
|
if (KnownScripts.Contains(Path.GetFileName(path)))
|
||||||
{
|
{
|
||||||
@@ -615,7 +614,7 @@ namespace mpvnet
|
|||||||
LastLoad = DateTime.Now;
|
LastLoad = DateTime.Now;
|
||||||
|
|
||||||
for (int i = 0; i < files.Length; i++)
|
for (int i = 0; i < files.Length; i++)
|
||||||
if (App.SubtitleTypes.Contains(Path.GetExtension(files[i]).TrimStart('.').ToLower()))
|
if (App.SubtitleTypes.Contains(PathHelp.GetShortExtension(files[i])))
|
||||||
commandv("sub-add", files[i]);
|
commandv("sub-add", files[i]);
|
||||||
else
|
else
|
||||||
if (i == 0 && !append)
|
if (i == 0 && !append)
|
||||||
@@ -636,9 +635,9 @@ namespace mpvnet
|
|||||||
if (!File.Exists(path) || get_property_int("playlist-count") != 1) return;
|
if (!File.Exists(path) || get_property_int("playlist-count") != 1) return;
|
||||||
List<string> files = Directory.GetFiles(Path.GetDirectoryName(path)).ToList();
|
List<string> files = Directory.GetFiles(Path.GetDirectoryName(path)).ToList();
|
||||||
files = files.Where((file) =>
|
files = files.Where((file) =>
|
||||||
App.VideoTypes.Contains(Path.GetExtension(file).TrimStart('.').ToLower()) ||
|
App.VideoTypes.Contains(PathHelp.GetShortExtension(file)) ||
|
||||||
App.AudioTypes.Contains(Path.GetExtension(file).TrimStart('.').ToLower()) ||
|
App.AudioTypes.Contains(PathHelp.GetShortExtension(file)) ||
|
||||||
App.ImageTypes.Contains(Path.GetExtension(file).TrimStart('.').ToLower())).ToList();
|
App.ImageTypes.Contains(PathHelp.GetShortExtension(file))).ToList();
|
||||||
files.Sort(new StringLogicalComparer());
|
files.Sort(new StringLogicalComparer());
|
||||||
int index = files.IndexOf(path);
|
int index = files.IndexOf(path);
|
||||||
files.Remove(path);
|
files.Remove(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user