question

Brent Batas (Lisk) avatar image
Brent Batas (Lisk) asked

How to get the path to excutable in a Custom Game Server?

As I understand it, a Custom Game Server executable is run in a subfolder.

How can I get the path to this subfolder? So that my exe can know where to look for configuration files.

Custom Game Servers
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

All the files in your Zip are decompressed in-place to one folder, so that all the files are exactly where you put them. So if you have config files in the same folder with the exe, you can just reference them via ".\config.file". Alternately, depending on your implementation language, you could use Application.ExecutablePath.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Brent Batas (Lisk) avatar image Brent Batas (Lisk) commented ·

Currently my exe uses an App.config file with a line: <probing privatePath="Lib;Plugins" />

This lets my exe search in the Lib/ and Plugins/ folders for dlls.

Would I just want to add a ".\" before the paths? That would be a bit annoying having a different config file for the server vs. local, but if it has to be done, it has to be done.

Edit: Also, how can I get the exe to load the Server.exe.config XML file in the first place?

0 Likes 0 ·
brendan avatar image brendan Brent Batas (Lisk) commented ·

Actually, all I meant was that you cannot use an absolute path in your code for those, since you don't have any way to guarantee what folder your Zip is decompressed into - it could change, potentially. Most libraries that use external configuration files, DLLs, etc. use relative paths to get to them, which would work fine. The only absolute paths you should be using are the ones passed into the server in the command line. In fact, if your server were using an absolute path for either Lib or Plugins in your example, adding ".\" in front of it wouldn't help - the resultant path would be incorrect.

0 Likes 0 ·
Brent Batas (Lisk) avatar image Brent Batas (Lisk) brendan commented ·

Thanks - I ended up just doing two things to hopefully solve this.

1) using Costura.Fody to embed the dlls into the exe directly, so I don't require any config files

2) using Directory.SetCurrentDirectory() to set the current directory to one-directory-up ("..\") and using Directory.GetCurrentDirectory() in the server code to infer the relative paths of the dlls.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.