-
Notifications
You must be signed in to change notification settings - Fork 7
Fix/openmw-config #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/openmw-config #51
Conversation
… it's actually necessary
…with a path separator
…ta-local directory which doesn't already exist
…directory instead, and make LoadConfiguration recurse onto itself when config keys are encountered to handle layered openmw.cfg configurations
…dle configruation-defined configuration directories
|
Okay, I went ahead and just did the whole thing.
I tested this against my system openmw.cfg and a portable install of 0.48 I have set up. Since @AnyOldName3 already chimed in here, he might as well again. Thanks boss(es?) <3 |
| if (dataDir.StartsWith('"')) | ||
| { | ||
| int lastQuote = dataDir.LastIndexOf('"'); | ||
| if (lastQuote > 0) | ||
| { | ||
| dataDir = dataDir.Substring(0, lastQuote + 1); | ||
| } | ||
| dataDir = UnescapeAmpersands(dataDir.Trim('"')); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right. It stops at the first " without an & before it. Quite a few people have lines that look like data="path/to/mod A" # this is the path to mod A because they thought that they could use comments like that, but it's really just the bit of the path outside the quotes being ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs said:
Everything after the closing quote mark will be ignored.
Which I guess left a little more room for interpretation than I thought the first time I read it. What is the appropriate behavior if a path starts with a quote, but is not deemed to be quoted appropriately, does it just interpret, say, data="./some_dir as "./some_dir ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
71b1763 should address this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it peeks a ", it does istream >> std::quoted(intermediate, '"', '&'). I just checked and that would interpret "path goes here as path goes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Fair. The original would have broken due to this but I think the current impl shouldn't have any problems in this respect.
TES3Merge/Util/Installation.cs
Outdated
| Archives.Add(value); | ||
| break; | ||
| case "data-local": | ||
| if (value == "?data-local?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a token. The default data-local path is ?userdata?/data.
|
There's some muddling with tokens. They can be used at the start of any path, so in principle, someone could have |
…the end of a quoted path instead of the literal last double-quote
I always keep forgetting that tokens can be generically used in this way. This maybe is worth documenting (especially that the token must be at the start, I was halfway through committing an incorrect version before re-reading that). However, your comment also leaves me guessing something that I think should be documented: In the builtin configs, the token is used as So:
EDIT: I decided it didn't really matter all that much what exactly OpenMW does here as long as the paths resolve properly so duplicate separators are always trimmed and data directories never have trailing separators. |
…d a child of the userdata directory
…keys using normal data directory parsing
…interpreted to be a data directory
|
I also keep worrying about this issue of recursion. As I understand it, if you were to do something like: In an openmw.cfg, that would mean that the three content files defined here will be defined before any in the following config. But, say the user does this: Where the userconfig contains: Would the resulting list of content files be: OR ? EDIT: Did some more testing and as of latest commit, it does seem to match up OpenMW's loading: This was the result of maybe ten-plus configuration files running simultaneously: So this should be fine, I think. |
The tokens all have a trailing slash. OpenMW only runs on platforms that permit consecutive redundant path separators, so we don't need to think about this at all unless we're lexically comparing paths, in which case we'd need to normalise them anyway to get rid of things like |
I thought this was fairly clear from the paragraph that says
It can't be higher priority if it ends up half way through the current file. |
| if (dataDir.StartsWith('"')) | ||
| { | ||
| int lastQuote = -1; | ||
| for (int i = dataDir.Length - 1; i > 0; i--) | ||
| { | ||
| if (dataDir[i] == '"') | ||
| { | ||
| int ampCount = 0; | ||
| int j = i - 1; | ||
| while (j >= 0 && dataDir[j] == '&') | ||
| { | ||
| ampCount++; | ||
| j--; | ||
| } | ||
| if (ampCount % 2 == 0) | ||
| { | ||
| lastQuote = i; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if (lastQuote > 0) | ||
| { | ||
| dataDir = dataDir.Substring(0, lastQuote + 1); | ||
| } | ||
| dataDir = UnescapeAmpersands(dataDir.Trim('"')); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks way more complicated than it needs to be. It could be as simple as
if (dataDir.StartsWith('"'))
{
auto original = dataDir;
dataDir = "";
for (int i = 1; i < original.Length; i++)
{
if (original[i] == '&')
i++;
else if (original[i] == '"')
break;
dataDir += original[i];
}
}
}
TES3Merge/Util/Installation.cs
Outdated
| case "config": | ||
| try | ||
| { | ||
| LoadConfiguration(ParseDataDirectory(configDir, value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right - you need to finish processing the rest of the current file before moving onto the next.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this is what that really long-winded comment about sequencing was in reference to. Latest commit should address this new set of comments.
TES3Merge/Util/Installation.cs
Outdated
| Archives.Add(value); | ||
| break; | ||
| case "data-local": | ||
| DataLocalDirectory = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably wants ParseDataDirectory, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, yeah - I just noticed the override config I'm using wasn't writing to the data-local dir assigned for this exact reason. Current commit handles this
…ta-local directory in order to correctly relativize paths
…d to append path separators manually and broke it because we tried


Addresses issues with openmw config parsing discovered by myself and another user in the OpenMW discord that were trying to switch to tes3merge. Notes from #MWSE copied here:
QQ: I have two minor grievances with openmw implementation I would like to change, but idk if you would be okay with this:
It makes more sense to me that TES3Merge.exe would be in the same directory as openmw.cfg, not a child directory. In this manner, you keep tes3merge and its config adjacent to openmw.cfg, OR you simply change directory to one which contains openmw.cfg.
If in an openmw installation is detected, OpenMW proper has its own overwrite directory, referred to as data-local in openmw.cfg. This has default locations you can rely on just like openmw.cfg itself (but it's important to note that it's a child directory of the openmw.cfg dir on Windows and NOT unices). So, it'd be nice if perhaps we could explore using that as the install dir, since... I think that's probably what will end up happening if you run tes3merge under MO2 for a vanilla install, just by wildly different means.
Less important, don't actually care:
The class constructor for OpenMWInstallation never actually appears to use this function which returns the hardcoded system path, so.... I'm not really sure what to do about that but it seems like it's worth removing since it's not really how TES3Merge handles detection anyway.