From 93b266838c21bee9374cdc00b81babd417c6e776 Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 7 Jun 2012 03:41:45 +0000 Subject: [PATCH] Add drag & drop for lua and luases files to main window. Allow multiple lua script drop to console and main window --- BizHawk.MultiClient/MainForm.cs | 22 ++++++- BizHawk.MultiClient/tools/LuaConsole.cs | 84 +++++++++++++------------ 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index c92c3cb8ee..9ade9ae44f 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -851,7 +851,27 @@ namespace BizHawk.MultiClient private void FormDragDrop(object sender, DragEventArgs e) { string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); - if (IsValidMovieExtension(Path.GetExtension(filePaths[0]))) + + bool isLua = false; + foreach (string path in filePaths) + { + if (Path.GetExtension(path).ToUpper() == ".LUA") + { + OpenLuaConsole(); + LuaConsole1.LoadLuaFile(path); + isLua = true; + } + } + if (isLua) + return; + + if (Path.GetExtension(filePaths[0]).ToUpper() == ".LUASES") + { + OpenLuaConsole(); + LuaConsole1.LoadLuaSession(filePaths[0]); + } + + else if (IsValidMovieExtension(Path.GetExtension(filePaths[0]))) { Movie m = new Movie(filePaths[0], MOVIEMODE.PLAY); StartNewMovie(m, false); diff --git a/BizHawk.MultiClient/tools/LuaConsole.cs b/BizHawk.MultiClient/tools/LuaConsole.cs index 4cbbcdaed2..186684bcfc 100644 --- a/BizHawk.MultiClient/tools/LuaConsole.cs +++ b/BizHawk.MultiClient/tools/LuaConsole.cs @@ -173,7 +173,7 @@ namespace BizHawk.MultiClient return file; } - private void LoadLuaFile(string path) + public void LoadLuaFile(string path) { if (LuaAlreadyInSession(path) == false) { @@ -594,18 +594,22 @@ namespace BizHawk.MultiClient string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); try { - if (Path.GetExtension(filePaths[0]) == (".lua") || Path.GetExtension(filePaths[0]) == (".txt")) + foreach (string path in filePaths) { - LoadLuaFile(filePaths[0]); - DisplayLuaList(); - UpdateNumberOfScripts(); - } - else if (Path.GetExtension(filePaths[0]) == (".luases")) - { - LoadLuaSession(filePaths[0]); - RunLuaScripts(); - DisplayLuaList(); - UpdateNumberOfScripts(); + if (Path.GetExtension(path) == (".lua") || Path.GetExtension(path) == (".txt")) + { + LoadLuaFile(path); + DisplayLuaList(); + UpdateNumberOfScripts(); + } + else if (Path.GetExtension(path) == (".luases")) + { + LoadLuaSession(path); + RunLuaScripts(); + DisplayLuaList(); + UpdateNumberOfScripts(); + return; + } } } catch (Exception ex) @@ -746,7 +750,7 @@ namespace BizHawk.MultiClient Global.Sound.StartSound(); } - private bool LoadLuaSession(string path) + public bool LoadLuaSession(string path) { var file = new FileInfo(path); if (file.Exists == false) return false; @@ -760,42 +764,42 @@ namespace BizHawk.MultiClient bool enabled = false; string s = ""; string temp = ""; - LuaFile l; + LuaFile l; while ((s = sr.ReadLine()) != null) { //.luases if (s.Length < 3) continue; - if (s.Substring(0, 3) == "---") - { - l = new LuaFile(true); - l.IsSeparator = true; - } - else - { - temp = s.Substring(0, 1); //Get enabled flag + if (s.Substring(0, 3) == "---") + { + l = new LuaFile(true); + l.IsSeparator = true; + } + else + { + temp = s.Substring(0, 1); //Get enabled flag - try - { - if (int.Parse(temp) == 0) - enabled = false; - else - enabled = true; - } - catch - { - return false; //TODO: report an error? - } + try + { + if (int.Parse(temp) == 0) + enabled = false; + else + enabled = true; + } + catch + { + return false; //TODO: report an error? + } - s = s.Substring(2, s.Length - 2); //Get path + s = s.Substring(2, s.Length - 2); //Get path - l = new LuaFile(s); + l = new LuaFile(s); - if (!Global.Config.DisableLuaScriptsOnLoad) - l.Enabled = enabled; - else - l.Enabled = false; - } + if (!Global.Config.DisableLuaScriptsOnLoad) + l.Enabled = enabled; + else + l.Enabled = false; + } luaList.Add(l); } }