News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

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.

Shirakami

Hello!

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.


simmain.cc 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;
+   sf.search(udn + "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 );
}


P.S.
I made a patch file.


Phystam

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

Shirakami

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.
https://www.dropbox.com/s/x9hmr639wolx9xc/subdirectory.zip?dl=0

Dwachs

Please check this old thread: http://forum.simutrans.com/index.php?topic=1917.0 , 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.

Ters

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.

prissi

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