Jump to content
LaunchBox Community Forums

Getting settings via Plugin API


Recommended Posts

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: image.thumb.png.0e429316900530fee88d438777a8034b.png image.png.262f9f7d92953db6fcdfea0a9b3533ae.png

Link to comment
Share on other sites

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 by Fry
fixed some formatting
Link to comment
Share on other sites

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 ;)) .

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

@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)

 

  • Thanks 1
Link to comment
Share on other sites

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));

 

  • Thanks 1
Link to comment
Share on other sites

  

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

image.thumb.png.2eb86a6f19385d8aa55b3182dee97818.pngThanks again for your help!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 years later...

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 by stigzler
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...