The Forum Rules and Guidelines
Our forum has Rules and Guidelines. Please, be kind and read them ;).

Sub Addon Directory Reading

Started by Shirakami, July 18, 2017, 04:44:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.



I wrote the code I wanted for many years.

Code to read sub directory in addons directory.

It will make it easier to organize Pak files. line:1019

// loading all paks
dbg->important("Reading object data from %s...", env_t::objfilename.c_str());
obj_reader_t::load(env_t::objfilename.c_str(), translator::translate("Loading paks ...") );
if(  env_t::default_settings.get_with_private_paks()  ) {
  // try to read addons from private directory
  chdir( env_t::user_dir );
  if(!obj_reader_t::load(("addons/" + env_t::objfilename).c_str(), translator::translate("Loading addon paks ..."))) {
    fprintf(stderr, "reading addon object data failed (disabling).\n");
    env_t::default_settings.set_with_private_paks( false );

+   // Search secondary directory
+   searchfolder_t sf;
+   string udn = env_t::user_dir;
+ + "addons/" + (env_t::objfilename).c_str(), "", true);

+   FOR(searchfolder_t, const& i, sf) {
+     char oDirectoryName[1024];
+     strcpy(oDirectoryName, i);
+     strcat(oDirectoryName, "/");
+     obj_reader_t::load(oDirectoryName, translator::translate("Loading addon paks ..."));
+   }

  chdir( env_t::program_dir );

I made a patch file.


Great! If you can, please write it as a recursive function!!! ;)
Then the management of our addons become much easier!!


The code was improved.

* It is possible to Load not only the Addons directory but also the sub directory in the Pak directory.
* I created a binary file.


Please check this old thread: , It was a similar patch, forgotten to be included, all attachments lost.

There was the request to exclude certain directories from automatic loading, which might be unwanted. Could you include something like this in your patch?
Parsley, sage, rosemary, and maggikraut.


This patch adds yet another unsafe string concatenation to simmain. (The other one is shortly after the comment "still nothing to be loaded => search for demo games".) There are a couple of safer examples, using either cbuffer_t or std::string. It is better to do like one of those.


Since the user should never touch the pak directories, like old paks onlz needed to load old games etc. I would advice against including subdirectories in the regulars pak directories.
For addons, one can think of two buttons, addons and "all addons", the latter with subdirectories