The International Simutrans Forum

 

Author Topic: [patch] load pak-files from subdirectories  (Read 10856 times)

0 Members and 1 Guest are viewing this topic.

Offline gerw

  • Coder/patcher
  • *
  • Posts: 618
[patch] load pak-files from subdirectories
« on: April 14, 2009, 09:06:26 PM »
The request was posted by VS (http://forum.simutrans.com/index.php?topic=1557.msg19729#msg19729).

The _MSC_VER version is fully untested ;)

Patch can be found in a later post.
« Last Edit: April 15, 2009, 05:07:21 PM by gerw »

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #1 on: April 14, 2009, 09:30:49 PM »
Wow, that was fast :o

Offline Frank

  • Inactive/Retired
  • *
  • Posts: 1431
  • Languages: DE
Re: [patch] load pak-files from subdirectories
« Reply #2 on: April 15, 2009, 01:58:32 AM »
load pak files from subdirectory

Waht is compatibility folder from pak128? Old pak files load all then?

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #3 on: April 15, 2009, 07:31:49 AM »
Good catch. I think there should be a safeguard against browsing folder - probably some file like nofollow.txt so that people can create it easily.

That is, skip folders that have this file in them.

Offline z9999

  • Devotees (Inactive)
  • *
  • Posts: 848
Re: [patch] load pak-files from subdirectories
« Reply #4 on: April 15, 2009, 08:07:32 AM »
Is the way that folder name start with "~" => ignore insufficient ?
This way is used with many software like Photoshop to read extension.

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #5 on: April 15, 2009, 08:30:32 AM »
That is an option, too.

Offline gerw

  • Coder/patcher
  • *
  • Posts: 618
Re: [patch] load pak-files from subdirectories
« Reply #6 on: April 15, 2009, 09:13:35 AM »
Now, folders starting with '~' are ignored. Can anyone test the _MSC_VER version?
« Last Edit: April 15, 2009, 05:06:44 PM by gerw »

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #7 on: April 15, 2009, 10:04:36 AM »
Around 17:00 I'll be back and test that.

Thanks a lot!

Offline whoami

  • Devotees (Inactive)
  • *
  • Posts: 693
Re: [patch] load pak-files from subdirectories
« Reply #8 on: April 15, 2009, 02:25:18 PM »
Now, folders starting with '~' are ignored.
This character can have a special meaning (in bash, it has).
Instead, I suggest to not include subdirectories by default, but allow them to be configured in simuconf.tab (both pak and user location), with relative and absolute path.

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #9 on: April 15, 2009, 03:47:49 PM »
gerw - sorry, it does not work. I'll test some more.

whoami - Allow me to disagree with your suggestion (config file). In my view, that defeats the whole beauty of "just add another folder and it still works". Including configuration in folder name avoids many problems and is a very simple rule.

I looked at bash documents and ~ appears a) in operator and b) for variable expansion in paths - which means problems only when in console, not for actual folders already existing on disk. Would another character instead of ~ work? Which one, then? It seems pretty much anything sane that can be typed casually (~@$!) is already some operator in bash :-\ That's not to say this is something to simply forget - your point about compatibility is important!

Note: I have zero problems using ~ in commands.

vladimir@hroch:~$ ls
aaa  Dokumenty  Examples  Plocha  simu_code  simu_128  simu_64  Šablony  Veřejné
vladimir@hroch:~$ mv aaa  ~aaa
vladimir@hroch:~$ ls
~aaa Dokumenty  Examples  Plocha  simu_code  simu_128  simu_64  Šablony  Veřejné
vladimir@hroch:~$ mv  ~aaa aaa
vladimir@hroch:~$ ls
aaa  Dokumenty  Examples  Plocha  simu_code  simu_128  simu_64  Šablony  Veřejné
vladimir@hroch:~$ rename
Usage: rename [-v] [-n] [-f] perlexpr [filenames]
vladimir@hroch:~$ rename s/aaa/~aaa/ aaa
vladimir@hroch:~$ ls
~aaa  Dokumenty  Examples  Plocha  simu_code  simu_128  simu_64  Šablony  Veřejné
vladimir@hroch:~$ cd /tmp/
vladimir@hroch:/tmp$ mkdir aaa
vladimir@hroch:/tmp$ ls
aaa             orbit-vladimir  seahorse-NLim2K        virtual-vladimir.zDJF7E
keyring-KR3yK6  pulse-vladimir  Tracker-vladimir.4994
vladimir@hroch:/tmp$ mv aaa ~aaa
vladimir@hroch:/tmp$ ls
~aaa            orbit-vladimir  seahorse-NLim2K        virtual-vladimir.zDJF7E
keyring-KR3yK6  pulse-vladimir  Tracker-vladimir.4994
vladimir@hroch:/tmp$ mv ~aaa abc
vladimir@hroch:/tmp$ ls
abc             orbit-vladimir  seahorse-NLim2K        virtual-vladimir.zDJF7E
keyring-KR3yK6  pulse-vladimir  Tracker-vladimir.4994
vladimir@hroch:/tmp$
« Last Edit: April 15, 2009, 04:08:37 PM by VS »

Offline Michael 'Cruzer'

  • Devotee
  • *
  • Posts: 206
  • Founder of pak192.comic
    • Marktplatz für Parkplätze
  • Languages: DE, EN
Re: [patch] load pak-files from subdirectories
« Reply #10 on: April 15, 2009, 04:00:28 PM »
It's seems not to work at MS Windows.
(Compiled with .NET-Framework)

Is there anything special to do? Like set a parameter in simuconf.tab, or anything else?
I only have created a subfolder in the pak-directory an add some paks.
« Last Edit: April 15, 2009, 04:23:06 PM by Cruzer »

Offline gerw

  • Coder/patcher
  • *
  • Posts: 618
Re: [patch] load pak-files from subdirectories
« Reply #11 on: April 15, 2009, 04:47:35 PM »
Maybe the '_' is a good choice.

@_MSC_VER: Can somebody, who compiles with Windows, have a look at this patch?

@VS: Maybe you will have some trouble with "rm ~vladimir". Don't try this at home! The '~vladimir' will expand to your home directory.

Edit: New patch file. Now it skips folders starting with '_'.
« Last Edit: April 15, 2009, 05:06:26 PM by gerw »

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #12 on: April 15, 2009, 05:08:02 PM »
I have only a virtual machine, so thanks for concern, but I do know what I am playing with :)

By the way, I am on windows...
« Last Edit: April 15, 2009, 05:25:22 PM by VS »

Offline Isaac Eiland-Hall

  • Benevolent Dictator
  • Administrator
  • *
  • Posts: 3917
  • Providing hosting for Simutrans projects
    • pc2.io
  • Languages: EN
Re: [patch] load pak-files from subdirectories
« Reply #13 on: April 15, 2009, 05:34:28 PM »
well, for testing, one might test with 'ls' rather than 'rm' for dangerous commands... lol

Also, '_' seems like a good character. It's a pity that Windows doesn't allow filenames beginning with a period, because that would be a good natural possibility. :)

Offline gerw

  • Coder/patcher
  • *
  • Posts: 618
Re: [patch] load pak-files from subdirectories
« Reply #14 on: April 15, 2009, 07:01:37 PM »
A new try of mine without nested findfirst, findnext. But it also doesn't work. Can someone with a Visual C compiler make it work?

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #15 on: April 15, 2009, 07:29:29 PM »
I will... try ;D

update: it does not even compile.

Am I supposed to work only on part ifdefed for _MSC_VER and nothing outside that?
« Last Edit: April 15, 2009, 08:45:29 PM by VS »

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10663
  • Languages: De,EN,JP
Re: [patch] load pak-files from subdirectories
« Reply #16 on: April 15, 2009, 08:46:41 PM »
Actually it is planned to have all addons in ~simutrans/pak64 tho seperate it. I am not too keen on subdirectories, since this breaks a lot of the assumption where translations or sounds are and so on.

I fail to see the advantage of subdirectories a bit.

Offline Zeno

  • ENASSA Designer
  • Devotees (Inactive)
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: [patch] load pak-files from subdirectories
« Reply #17 on: April 15, 2009, 08:58:28 PM »
Well, you can put paks wherever you want inside simutrans/pak64, let's say some addons in a folder called simutrans/pak64/addons, and some german style cool addons in simutrans/pak64/german_addons :)
You can now move/copy/add/delete/list/count/whatever them without getting mad in searching all pak files in the main pak folder. Of course there's no advantage at all if you don't want to mess up inside there.
Btw, what has that to do with translations? Are they related to the pak file path? Sounds are, no doubt, but can't they be addressed by the main folder? e.g. /simutrans/sounds, or whatever folder it is...

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #18 on: April 15, 2009, 09:08:25 PM »
Prissi, that is probably question of taste. I fail to see advantage of thousands of paks in one folder. And all other files are where they are, no? Not everything has to be subfolderized, only the data that come in bulk.

I don't think this is important enough to argue - do as you want :) In the end, it would be only a convenience for some cases. The biggest issue for users are addons, and your plan for them is more logical regardless of outcome of this.



gerw: Got it! You patched only the class but actual call with recursion switched on was left out.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10663
  • Languages: De,EN,JP
Re: [patch] load pak-files from subdirectories
« Reply #19 on: April 15, 2009, 09:40:13 PM »
No I was to seperate paks and addon folder. I would put the addons into the personal folder. Thus you can replace your pak64 as often you like (and for network games make sure, that there are no other objects).

Offline gerw

  • Coder/patcher
  • *
  • Posts: 618
Re: [patch] load pak-files from subdirectories
« Reply #20 on: April 16, 2009, 07:54:12 AM »
@VS:
Ok, I missed the changes in besch/reader/obj_reader.cc. I've done only a "svn diff utils/search_folder.*", since I patched it in a directory, where I also have an other patch applied. Can you post the patch, which is working with MSVC?

@prissi: I think it is useful, to have some more structure in the pak* folders. However, if you place the addons in ~/simutrans/pak*, you have to search all subdirectories there, otherwise the addon directory will mess up.

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #21 on: April 16, 2009, 10:07:44 AM »
prissi: I understand (and understood before, too) :)

gerw: I got it to compile, found why it does not load and then saw it is not accepted. That's where I stopped. I still don't know whether it actually works, only that it compiles, runs and at least loads paks as before.



edit #1: The msvc version of code has some serious logic issues :-/ sprintf(buf, "%s/" buf) seems like a gross copy-paste error.



edit #2: Recursion works all right, but I can't get the cleanup to work.

edit #3: note to self, don't forget to allocate the one byte for trailing zero when working with that not-so-favourite language!



edit #4: So now the msvc version finally works all right. I do have doubts about the *nix version though, it still has that sprintf(fullname, "%s/" fullname) in it.
« Last Edit: April 17, 2009, 02:01:17 PM by VS »

Offline gerw

  • Coder/patcher
  • *
  • Posts: 618
Re: [patch] load pak-files from subdirectories
« Reply #22 on: April 17, 2009, 03:33:29 PM »
Thank you!

About sprints: It works, but of course, strcat is more suitable for this case. I missed also one byte for the "/" ;)

This patch should work on all platforms.

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #23 on: April 17, 2009, 03:41:11 PM »
Thanks!

One minor remark - it doesn't loop in ..././././././... for you? At least on windows, . and .. are regular entries in folder listing. I had enough of that in past, so the stop on [0 ]=="." was reflex, not tested at all...

Offline gerw

  • Coder/patcher
  • *
  • Posts: 618
Re: [patch] load pak-files from subdirectories
« Reply #24 on: April 17, 2009, 03:49:02 PM »
This is blocked in line 128.

Offline VS

  • Senior Plumber (Devotee)
  • Devotees (Inactive)
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: [patch] load pak-files from subdirectories
« Reply #25 on: April 17, 2009, 04:04:02 PM »
Good... so, it's probably done!
« Last Edit: April 17, 2009, 04:47:28 PM by VS »