Skip to content
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

Generate <classname>.cfg/userconfig.cfg files at runtime if they don't exist #88

Merged
merged 2 commits into from Dec 15, 2014

Conversation

Projects
None yet
2 participants
@squeek502
Copy link
Member

commented Dec 8, 2014

@squeek502 squeek502 self-assigned this Dec 8, 2014

@squeek502 squeek502 force-pushed the features/default-cfgs branch from e26ac62 to ea856ba Dec 8, 2014

@squeek502 squeek502 added needs review and removed in progress labels Dec 8, 2014

void CFFClient::PopulateMissingConfigs()
{
// populate class configs
if (filesystem->FileExists(CLASSCFG_DEFAULT_PATH, "MOD"))

This comment has been minimized.

Copy link
@AfterShockFF

AfterShockFF Dec 10, 2014

Member

whats MOD here?

This comment has been minimized.

Copy link
@squeek502

squeek502 Dec 10, 2014

Author Member

"MOD" is a weird constant for telling the filesystem which search paths to check (options seem to be "MOD" and "GAME"). I can't really find much documentation about it, but I did find this in dlls/navfile.cpp:

    bool navIsInBsp = false;
    FileHandle_t file = filesystem->Open( filename, "rb", "MOD" );  // this ignores .nav files embedded in the .bsp ...
    if ( !file )
    {
        navIsInBsp = true;
        file = filesystem->Open( filename, "rb", "GAME" );  // ... and this looks for one if it's the only one around.
    }

We pretty much always use "MOD" in FF files.

This comment has been minimized.

Copy link
@squeek502

squeek502 Dec 10, 2014

Author Member

Did some more research about search paths. They are defined in FileSystem_Steam.dll and set based on gameinfo.txt. Although we can't access the implementation in that dll, there is an analog (which seems to be accurate) in public/filesystem_init.cpp that's used to compile demoinfo.exe.

Fortress Forever's current search paths:

NULL pathID search paths:
c:\program files (x86)\steam\steamapps\common\fortress forever\platform\
c:\program files (x86)\steam\steamapps\common\fortress forever\fortressforever\
c:\program files (x86)\steam\steamapps\common\fortress forever\hl2\
c:\program files (x86)\steam\steamapps\common\fortress forever\platform\config\

GAME search paths:
c:\program files (x86)\steam\steamapps\common\fortress forever\fortressforever\
c:\program files (x86)\steam\steamapps\common\fortress forever\hl2\

MOD search paths:
c:\program files (x86)\steam\steamapps\common\fortress forever\fortressforever\

GAMEBIN search paths:
c:\program files (x86)\steam\steamapps\common\fortress forever\fortressforever\bin\
c:\program files (x86)\steam\steamapps\common\fortress forever\hl2\bin\

PLATFORM search paths:
c:\program files (x86)\steam\steamapps\common\fortress forever\platform\

DEFAULT_WRITE_PATH search paths:
c:\program files (x86)\steam\steamapps\common\fortress forever\fortressforever\

The 2013 engine uses search paths to allow customizations to not overwrite files, and instead they'd get loaded from <gamedir>/custom. We can sort of do the same thing, but 2013 has a new filesystem_init.cpp implementation that allows it to be less intrusive (we'd have to set fortressforever/custom as the first mod/game path, but then various temp/cfg/etc files get written to it instead of where they should be; 2013 defines /custom/ as a special case using a new wildcard thingy).

This probably isn't the right place to post this, but oh well.

{
if (!bIsBufferPopulated)
{
FileHandle_t f = filesystem->Open(CLASSCFG_DEFAULT_PATH, "rb");

This comment has been minimized.

Copy link
@AfterShockFF

AfterShockFF Dec 10, 2014

Member

whats "rb"?

This comment has been minimized.

Copy link
@squeek502

squeek502 Dec 10, 2014

Author Member

Seems like it takes the same mode flags as fopen (including the 't' flag). So, 'read in binary mode', basically.

bIsBufferPopulated = true;
}

filesystem->WriteFile(szConfigPath, "MOD", buf);

This comment has been minimized.

Copy link
@AfterShockFF

AfterShockFF Dec 10, 2014

Member

This whole loop could do with a bit more readability help. Hungarian prefixes hurt when it gets to szBlah and we have a buf(0,0,false) (i have no idea what those zeros are, or what the false means). we have a variable called "f", and a couple of magic strings "MOD" and "rb".

{
Q_snprintf(szConfigPath, sizeof(szConfigPath), CLASSCFG_PATH, Class_IntToString(iClass));

if (!filesystem->FileExists(szConfigPath))

This comment has been minimized.

Copy link
@AfterShockFF

AfterShockFF Dec 10, 2014

Member

I think you can invert this "if" statement and just return early if the file doesnt exist, reduces nesting

CUtlBuffer buf(0,0,false);
FileHandle_t f = filesystem->Open(USERCONFIG_DEFAULT_PATH, "rb");

if ( f != FILESYSTEM_INVALID_HANDLE )

This comment has been minimized.

Copy link
@AfterShockFF

AfterShockFF Dec 10, 2014

Member

Again you could return early here and invert the if statement, reduces nesting

@AfterShockFF

This comment has been minimized.

Copy link
Member

commented Dec 10, 2014

This is generally a good idea. The code could do with a slight cleanup but otherwise all good 👍

Review: Clean up/improve class/userconfig population code
 * Split the logic into two functions
 * Made it generate blank files if the defaults don't exist or can't be read
 * Added comments, removed nesting, improved variable names, etc

squeek502 added a commit that referenced this pull request Dec 15, 2014

Merge pull request #88 from fortressforever/features/default-cfgs
Generate <classname>.cfg/userconfig.cfg files at runtime if they don't exist

@squeek502 squeek502 merged commit 2ea366a into beta Dec 15, 2014

@squeek502 squeek502 removed the needs review label Dec 15, 2014

@squeek502 squeek502 deleted the features/default-cfgs branch Dec 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.