Empyrion: Galactic Survival Wiki
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Index: GameAPI

Standard: Using variable path, when exposing files for user

Basic

When using a configuration file, and having part of these expose 'other files' (for instance, if you are refering to a list with a lot of deathmessages), allow for variable pathing (../) in the entries. This allows for better mod-cooperation, so that you for instance can have a 'reputation list', 'whitelist', 'vip-list' (..) shared between several mods.

Proposed implementation

Read for ../, ..\, and interpretate them as 'go up a level, from the current location' (where the mod is executed from) For instance, if string is ../config.yaml, and the mod is in "D:\APPS\steamapps\common\Empyrion - Dedicated Server\Content\Mods\SpotGuard", you would look for the file in "D:\APPS\steamapps\common\Empyrion - Dedicated Server\Content\Mods\" (etc)

Pre-req

  • Exposing the 'link' to another file, in a config file.

Code sample

       public string getSource(string source, string helper = null)
       {
           if (helper is null || helper == "")
           {
               //modpath to 'this mod' 
               helper = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
           }
           //If string contains '../', go 'up a level'
           int ss = source.IndexOf("../");
           int sd = source.IndexOf("..\\");
           while (ss >= 0 || sd >= 0)
           {
               ss = source.IndexOf("../");
               sd = source.IndexOf("..\\");
               if (ss >= 0 || sd >= 0)
               {
                   if (ss >= 0)
                   {
                       source = source.Remove(ss, 3);
                   }
                   else
                   {
                       source = source.Remove(sd, 3);
                   }
                   var pattern = @"(\\[\w\s-]*)\\$";
                   helper = Regex.Replace(helper, pattern, "\\");
               }
           }
           //If last entry is a backslash, don't append, else append a backslash, before including name
           if (helper.Length - 1 == helper.LastIndexOf("\\"))
           {
               return helper + "" + source;
           }
           else
           {
               return helper + "\\" + source;
           }
       }

Used with:

var source = "config.yaml";
getSource(source)

('source' string should be loaded from said configuration file)

File-standards

Refer to this article

Advertisement