This commit is contained in:
Frank Skare
2019-05-09 12:28:17 +02:00
parent 08a23430c7
commit b37272db8b
4 changed files with 81 additions and 76 deletions

View File

@@ -193,6 +193,9 @@ mpv.net bugs and requests: <https://github.com/stax76/mpv.net/issues>
- when the main windows gets activated and the clipboard content starts with http - when the main windows gets activated and the clipboard content starts with http
mpv.net will ask to play the URL, previously this was restricted to YouTube URLs mpv.net will ask to play the URL, previously this was restricted to YouTube URLs
- Python script errors show line and column whenever it is supported by IronPython - Python script errors show line and column whenever it is supported by IronPython
- if conf files exist in the startup directory mpv.net will use the startup
directory as config directory instead of creating default conf files in appdata
- renamed commands are handled now by migration code instead of being broken
### 3.4 (2019-05-03) ### 3.4 (2019-05-03)

View File

@@ -307,55 +307,32 @@ namespace mpvnet
public void BuildMenu() public void BuildMenu()
{ {
string content = File.ReadAllText(mp.InputConfPath); string content = File.ReadAllText(mp.InputConfPath);
List<string> lines = null; var items = CommandItem.GetItems(content);
Dictionary<string, string> commandInputDic = new Dictionary<string, string>();
if (content.Contains("#menu:")) if (!content.Contains("#menu:"))
lines = content.Split('\r', '\n').ToList();
else
{ {
lines = Properties.Resources.inputConf.Split('\r', '\n').ToList(); var defaultItems = CommandItem.GetItems(Properties.Resources.inputConf);
foreach (CommandItem item in items)
foreach (string i in content.Split('\r', '\n')) foreach (CommandItem defaultItem in defaultItems)
{ if (item.Command == defaultItem.Command)
string line = i.Trim(); defaultItem.Input = item.Input;
if (line.StartsWith("#") || !line.Contains(" ")) continue; items = defaultItems;
string input = line.Substring(0, line.IndexOf(" ")).Trim();
string command = line.Substring(line.IndexOf(" ") + 1).Trim();
commandInputDic[command] = input;
}
} }
foreach (string line in lines) foreach (CommandItem item in items)
{ {
if (!line.Contains("#menu:")) continue; if (string.IsNullOrEmpty(item.Path))
string left = line.Substring(0, line.IndexOf("#menu:")).Trim(); continue;
if (left.StartsWith("#")) continue; string path = item.Path.Replace("&", "&&");
string command = left.Substring(left.IndexOf(" ") + 1).Trim();
string menu = line.Substring(line.IndexOf("#menu:") + "#menu:".Length).Trim();
string input = left.Substring(0, left.IndexOf(" "));
if (input == "_") input = "";
if (menu.Contains(";")) input = menu.Substring(0, menu.IndexOf(";")).Trim();
string path = menu.Substring(menu.IndexOf(";") + 1).Trim().Replace("&", "&&");
if (path == "" || command == "") continue;
if (commandInputDic.Count > 0)
if (commandInputDic.ContainsKey(command))
input = commandInputDic[command];
else
input = "";
MenuItem menuItem = ContextMenu.Add(path, () => { MenuItem menuItem = ContextMenu.Add(path, () => {
try { try {
mp.command_string(command); mp.command_string(item.Command);
} } catch (Exception ex) {
catch (Exception ex) {
Msg.ShowException(ex); Msg.ShowException(ex);
} }
}); });
if (menuItem != null) if (menuItem != null)
menuItem.ShortcutKeyDisplayString = input + " "; menuItem.ShortcutKeyDisplayString = item.Input + " ";
} }
} }

View File

@@ -198,46 +198,67 @@ namespace mpvnet
} }
} }
public static ObservableCollection<CommandItem> GetItems(string content)
{
var items = new ObservableCollection<CommandItem>();
if (!string.IsNullOrEmpty(content))
{
foreach (string line in content.Split('\r', '\n'))
{
string val = line.Trim();
if (val.StartsWith("#")) continue;
if (!val.Contains(" ")) continue;
CommandItem item = new CommandItem();
item.Input = val.Substring(0, val.IndexOf(" ")).Replace("_", "");
val = val.Substring(val.IndexOf(" ") + 1);
if (val.Contains("#menu:"))
{
item.Path = val.Substring(val.IndexOf("#menu:") + 6).Trim();
val = val.Substring(0, val.IndexOf("#menu:"));
if (item.Path.Contains(";"))
item.Path = item.Path.Substring(item.Path.IndexOf(";") + 1).Trim();
}
item.Command = val.Trim();
if (item.Command == "")
continue;
if (item.Command.ToLower() == "ignore")
item.Command = "";
MigrateCommands(item);
items.Add(item);
}
}
return items;
}
private static ObservableCollection<CommandItem> _Items; private static ObservableCollection<CommandItem> _Items;
public static ObservableCollection<CommandItem> Items { public static ObservableCollection<CommandItem> Items {
get { get {
if (_Items is null) if (_Items is null)
{ _Items = GetItems(File.ReadAllText(mp.InputConfPath));
_Items = new ObservableCollection<CommandItem>();
if (File.Exists(mp.InputConfPath))
{
foreach (string line in File.ReadAllLines(mp.InputConfPath))
{
string val = line.Trim();
if (val.StartsWith("#")) continue;
if (!val.Contains(" ")) continue;
CommandItem item = new CommandItem();
item.Input = val.Substring(0, val.IndexOf(" ")).Replace("_", "");
val = val.Substring(val.IndexOf(" ") + 1);
if (val.Contains("#menu:"))
{
item.Path = val.Substring(val.IndexOf("#menu:") + 6).Trim();
val = val.Substring(0, val.IndexOf("#menu:"));
if (item.Path.Contains(";"))
item.Path = item.Path.Substring(item.Path.IndexOf(";") + 1).Trim();
}
item.Command = val.Trim();
if (item.Command == "")
continue;
if (item.Command.ToLower() == "ignore")
item.Command = "";
_Items.Add(item);
}
}
}
return _Items; return _Items;
} }
} }
public static void MigrateCommands(CommandItem item)
{
switch (item.Command)
{
case "script-message mpv.net show-prefs":
item.Command = "script-message mpv.net show-conf-editor";
break;
case "script-message mpv.net show-keys":
item.Command = "script-message mpv.net show-input-editor";
break;
case "script-message mpv.net history":
item.Command = "script-message mpv.net show-history";
break;
}
}
} }
public class CursorHelp public class CursorHelp

View File

@@ -74,9 +74,11 @@ namespace mpvnet
{ {
string portableFolder = Application.StartupPath + "\\portable_config\\"; string portableFolder = Application.StartupPath + "\\portable_config\\";
string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\"; string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\";
string startupFolder = Application.StartupPath + "\\";
if (!Directory.Exists(appdataFolder) && !Directory.Exists(portableFolder) && if (!Directory.Exists(appdataFolder) && !Directory.Exists(portableFolder) &&
Sys.IsDirectoryWritable(Application.StartupPath)) Sys.IsDirectoryWritable(Application.StartupPath) &&
!File.Exists(startupFolder + "mpv.conf"))
{ {
using (TaskDialog<string> td = new TaskDialog<string>()) using (TaskDialog<string> td = new TaskDialog<string>())
{ {
@@ -84,15 +86,17 @@ namespace mpvnet
td.Content = "[MPV documentation about files on Windows.](https://mpv.io/manual/master/#files-on-windows)"; td.Content = "[MPV documentation about files on Windows.](https://mpv.io/manual/master/#files-on-windows)";
td.AddCommandLink("appdata", appdataFolder, appdataFolder); td.AddCommandLink("appdata", appdataFolder, appdataFolder);
td.AddCommandLink("portable", portableFolder, portableFolder); td.AddCommandLink("portable", portableFolder, portableFolder);
td.AddCommandLink("startup", startupFolder, startupFolder);
td.AllowCancel = false; td.AllowCancel = false;
_MpvConfFolder = td.Show(); _MpvConfFolder = td.Show();
} }
} }
else else if (Directory.Exists(portableFolder))
if (Directory.Exists(portableFolder)) _MpvConfFolder = portableFolder;
_MpvConfFolder = portableFolder; else if (Directory.Exists(appdataFolder))
else _MpvConfFolder = appdataFolder;
_MpvConfFolder = appdataFolder; else if (File.Exists(Application.StartupPath + "\\mpv.conf"))
_MpvConfFolder = Application.StartupPath + "\\";
if (string.IsNullOrEmpty(_MpvConfFolder)) _MpvConfFolder = appdataFolder; if (string.IsNullOrEmpty(_MpvConfFolder)) _MpvConfFolder = appdataFolder;
if (!Directory.Exists(_MpvConfFolder)) Directory.CreateDirectory(_MpvConfFolder); if (!Directory.Exists(_MpvConfFolder)) Directory.CreateDirectory(_MpvConfFolder);