Fry Posted October 4, 2020 Share Posted October 4, 2020 Is it possible to get big box settings via the plug-in API? I looked around and couldn't find anything but I wanted to make sure. I'm looking to identify which monitor big box is set to run on from my plug-in. I can query it out of LaunchBox\Data\BigBoxSettings.xml file but wanted to see if I was missing anything like this in the API before doing that since going directly to the file could lead to problems if underlying implementations change. I'm looking to get this setting: Quote Link to comment Share on other sites More sharing options...
Fry Posted October 5, 2020 Author Share Posted October 5, 2020 (edited) public static class Helpers { public static string ApplicationPath = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); public static string BigBoxSettingsFile = $"{ApplicationPath}\\Data\\BigBoxSettings.xml"; public static string GetMonitorIndex() { // get the index from the big box xml file var bigBoxSettingsXmlDocument = XDocument.Load(Helpers.BigBoxSettingsFile); var setting = from xmlElement in bigBoxSettingsXmlDocument.Root.Descendants("BigBoxSettings") select xmlElement.Element("PrimaryMonitorIndex").Value; return setting.FirstOrDefault(); } } I'm doing this for now. I'm not sure if there's a better alternative way to handle it. Edited October 5, 2020 by Fry fixed some formatting Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted October 5, 2020 Share Posted October 5, 2020 Does that string ApplicationPath get you to the LaunchBox root directory? [Maybe .MainModule helps. (would have to read up on it)] An issue I had with one of my plugins was, with the change to .NET Core, the code I was using (would have to look it up to see exactly what I used) returned ../LaunchBox/Core/. I ended up just putting .GetParent(... in front of it which took me back to ../LaunchBox/ (ya, maybe a little cheesy. lol) I haven't noticed anything in the API regarding BB settings, but my guess is your method isn't any less efficient then an API call. (As in it'd end up doing the same thing ) . Quote Link to comment Share on other sites More sharing options...
Fry Posted October 5, 2020 Author Share Posted October 5, 2020 I had some trouble with the update to .net core so I’m still running on 11.2 until I can iron those problems out. On 11.2, this gives me the directory with the BigBox executable. Quote Link to comment Share on other sites More sharing options...
Fry Posted October 5, 2020 Author Share Posted October 5, 2020 13 hours ago, JoeViking245 said: I haven't noticed anything in the API regarding BB settings, but my guess is your method isn't any less efficient then an API call. (As in it'd end up doing the same thing ) . I think you’re right that there is no API for this and that if there was one, it’d probably do the same thing but the difference in using an approved API is that I don’t have to care how they get the value. They can change the underlying folder structure, XML file structure, or any other change all they want and it won’t break plugins using the API. Quote Link to comment Share on other sites More sharing options...
C-Beats Posted October 5, 2020 Share Posted October 5, 2020 @Fry I've not tested it but in theory the following should be able to get you what Screen Big Box is on. Though I'm not REAL sure why you want or need the screen index in the first place. System.Windows.Forms.Screen.FromHandle(System.Windows.Diagnostics.Process.GetCurrentProcess().MainWindowHandle) 1 Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted October 5, 2020 Share Posted October 5, 2020 14 minutes ago, Fry said: had some trouble with the update to .net core I'm pretty confident that it's going to be in the folder structure. Here's what I ended up doing.. string LBApplicationPath; // LB absolute (root) path (ver 11.3+) LBApplicationPath = Directory.GetParent(Path.GetDirectoryName(Application.ExecutablePath)); 1 Quote Link to comment Share on other sites More sharing options...
Fry Posted October 5, 2020 Author Share Posted October 5, 2020 15 minutes ago, C-Beats said: System.Windows.Forms.Screen.FromHandle(System.Windows.Diagnostics.Process.GetCurrentProcess().MainWindowHandle) Thanks, I'll give this a shot! 15 minutes ago, C-Beats said: Though I'm not REAL sure why you want or need the screen index in the first place. The short answer is that I want the dimensions of the monitor where my theme will be running so I can prescale box front images to improve the performance of moving around in my plugin/theme. The long answer is that I am creating a theme that is entirely run by a plug-in. My theme shows game box front images in a row, all scaled to the same height so they fit neatly. I wish I had your game wheel code (haha) because my game wheels were performing pretty poorly. I tried a lot of things but nothing got my wheel performing very well until I found that if I pre-scaled the images to the size that they will ultimately display then WPF doesn't incur the performance hit of scaling them at runtime. So when my plugin starts up, it duplicates all of the box front images that do not exist in my plug-in images folder and scale them to the right height based on the monitor height. Basically, my list of box front images is set to stretch uniformly into a row that takes up 5/18 of the screen so I can use the monitor height to determine the desired image size and then pre-scale the images properly on startup. The result is something like this and should work on any size screen Thanks again for your help! Quote Link to comment Share on other sites More sharing options...
Fry Posted October 5, 2020 Author Share Posted October 5, 2020 That works great and helped me avoid checking the big box settings XML file. Thanks again, @C-Beats! Quote Link to comment Share on other sites More sharing options...
C-Beats Posted October 5, 2020 Share Posted October 5, 2020 Glad it worked for ya. Theme looks pretty interesting. Be fun to see what comes of it. When ya ready to test it out with other users send me a PM. Love to look through it, always enjoy seeing what the community does to customize their set up. 1 Quote Link to comment Share on other sites More sharing options...
Fry Posted October 5, 2020 Author Share Posted October 5, 2020 Will do, it's getting close on 11.2. I have some work to do to get the voice recognition working in 11.3 and later due to the .net speech recognition changing to an azure function in .net core. It's an online paid service and I'd like to keep it offline and free so I'm going to have to look into some hacky approaches to calling .net framework from .net core. Quote Link to comment Share on other sites More sharing options...
stigzler Posted July 12, 2023 Share Posted July 12, 2023 (edited) For those of you looking for a down-n-dirty helper class: public class SettingsManager { public FileSystemWatcher GeneralSettingsFileWatcher = new FileSystemWatcher(); public XDocument SettingsXDoc; public XDocument BigBoxSettingsXDoc; private static string ApplicationPath = Path.GetDirectoryName(new DirectoryInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName).Parent.FullName); private static string SettingsFile = $"{ApplicationPath}\\Data\\Settings.xml"; private static string BigBoxSettingsFile = $"{ApplicationPath}\\Data\\BigBoxSettings.xml"; public SettingsManager() { GeneralSettingsFileWatcher.Path = Path.GetDirectoryName(SettingsFile); GeneralSettingsFileWatcher.Filter = Path.GetFileName(SettingsFile); GeneralSettingsFileWatcher.NotifyFilter = NotifyFilters.LastWrite; GeneralSettingsFileWatcher.Changed += GeneralSettingsFileChanged; GeneralSettingsFileWatcher.EnableRaisingEvents = true; ReloadSettingsXDocs(); } private void ReloadSettingsXDocs() { SettingsXDoc = XDocument.Load(SettingsFile); BigBoxSettingsXDoc = XDocument.Load(BigBoxSettingsFile); } private void GeneralSettingsFileChanged(object sender, FileSystemEventArgs e) { try { GeneralSettingsFileWatcher.EnableRaisingEvents = false; // this controls for double firing // Ensures XDocs are always up to date ReloadSettingsXDocs(); } finally { GeneralSettingsFileWatcher.EnableRaisingEvents = true; } } public string GetSettingsStringValue(string key, SettingsType settingsType) { IEnumerable<string> returnValue = null; switch (settingsType) { case SettingsType.General: returnValue = from xmlElement in SettingsXDoc.Root.Descendants("Settings") select xmlElement.Element(key).Value.ToString(); break; case SettingsType.BigBox: break; default: break; } if (returnValue != null) { return returnValue.FirstOrDefault().ToString(); } else { return null; } } public enum SettingsType { General = 0, BigBox = 1 } } Unfinished, but will give you something to work from. Edited July 12, 2023 by stigzler 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.