Recent

Author Topic: Folders unit for Linux, OS X and windows  (Read 49325 times)

wotanica

  • Guest
Folders unit for Linux, OS X and windows
« on: October 03, 2010, 06:57:48 pm »
Hope it's helps, this unit should be included as standard:

http://delphimax.wordpress.com/2010/10/03/folder-locations-on-windows-linux-and-os-x/

wotanica

  • Guest
Re: Folders unit for Linux, OS X and windows
« Reply #1 on: October 04, 2010, 01:36:40 pm »
I altered the functions to use Widestring, also added a "GetTempFolder" function. The widestring alteration solves two problems:
  • International support for filenames (I.e Asian)
  • A small inconsistency when displaying filenames in Lazarus

Filenames that are used in controls should be formated using AnsiToUTF8 .. but OS X have widestring by default (thus not needing the AnsiToUTF8). You would only need to use this on windows (and possibly linux). Or SysToUTF8 I learned today. However, these changes fixed this problem on my Mac and Windows. So they work the same way on both systems. Linux users -- please post a comment on my blog if you experience any problems.
« Last Edit: October 04, 2010, 04:59:44 pm by wotanica »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12711
  • FPC developer.
Re: Folders unit for Linux, OS X and windows
« Reply #2 on: October 04, 2010, 02:13:19 pm »
Hope it's helps, this unit should be included as standard:

http://delphimax.wordpress.com/2010/10/03/folder-locations-on-windows-linux-and-os-x/

Not likely, very, very messy code. Some reasons (but not even complete)

1. it drags in the VCL just to access environment variables via the application object.
2. It fails for everything but Linux, Darwin and Windows derivatives.  Both FPC and Lazarus support more.
      See last table in http://www.freepascal.org/docs-html/prog/progap7.html#x329-331000G
   2a. should use UNIX for Unix (solaris, FreebSD, Beos Darwin or Linux or or or )
   2b.  Should use windows for win32/64+ wince
3. Partially duplicates badly, what is already system provided:
    3a. http://www.freepascal.org/docs-html/rtl/sysutils/gettempdir.html
    3b. http://www.freepascal.org/docs-html/rtl/sysutils/gettempfilename.html
    3c. http://www.freepascal.org/docs-html/rtl/sysutils/getuserdir.html

4. The remaining ones (documents, pictures etc) are not standarized on *nix. Some
    distros and desktop environments emulate windows behaviour, but this is not proper, and often
   these directories are localised in the person's own language, and not hardcoded english.



wotanica

  • Guest
Re: Folders unit for Linux, OS X and windows
« Reply #3 on: October 04, 2010, 04:31:12 pm »
First, I tested this on Fedora linux and it worked fine. I was going to test it for OpenSuse and UBuntu - but Lazarus crash on the first compile (cant find the unit Interfaces.. its the same story every time) so that sort of cripples my testing process.  I was sort of hoping people would add the req. code for their distros of preference.

I also tested it on OS X (which has aliases for all system folder names btw) - so it does not care if you write "pictures" or "bilder" (norwegian). Just try it yourself on the mac. You can use the alt+mac+G shortcut from finder, then type in a path. It works in both english and norwegian on my machine. I also tested the binaries with a friend and they work there too.

Secondly, yes i did realize that I could use $UNIX as a compilerswitch afterwards. The compiler switching is actually taken from the shellcontrols unit that ships with lazarus.. ahem..

Third, it's a start :)

You wrote: "1. it drags in the VCL just to access environment variables via the application object."

Well most visual application ends up using those units anyways. But i see your point and it can be easily changed. This is a sidekick unit for my filebrowser component. Concidering that I have little or no documentation, and that lazarus crashes on all platforms in some way or another - i think i did a pretty good job having used lazarus for roughly 2 weeks. I also noted earlier when i posted this, that if anyone could contribute to the unit then please do so.

Also: "It fails for everything but Linux, Darwin and Windows derivatives.  Both FPC and Lazarus support more.". Eh.. thats sort of the point. I will write for two platforms (mac & windows), and since its my unit -- well.. im dont really care about Amiga or win-CE. But someone might, and im sure they can add the needed code for that.

And "Partially duplicates badly, what is already system provided:". Well, i did not know about those so i didnt duplicate anything by intention. But the true purpose was to get access to the same folders on mac & windows. But now that i do know, i can take a look at the sourcecode and see what can be done to upgrade my own code, or simply replace my code with calls to those you mention. Thanks for the heads up.

As for the messy part.. what exactly is messy? If you remove the compiler switches and replace it with $UNIX like you propose.. it's not even 100 lines long. Messy is writing code like "If something then begin". Standard pascal syntax demans a LF after "then". There is even a book on proper pascal syntax, which very few seems to follow these days.

Your just picking to pick.. (*smile*) No i get your point. It will be updated to meet better req.
« Last Edit: October 04, 2010, 05:12:35 pm by wotanica »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12711
  • FPC developer.
Re: Folders unit for Linux, OS X and windows
« Reply #4 on: October 04, 2010, 06:57:32 pm »
First, I tested this on Fedora linux and it worked fine.

With what locale? My main concern (after the easy fixes like "unix" etc) is that the stuff that works is already in FPC, and the rest is not locale safe. Probably those need to be done via the freedesktop api.

Quote
I also tested it on OS X (which has aliases for all system folder names btw) - so it does not care if you write "pictures" or "bilder" (norwegian). Just try it yourself on the mac. You can use the alt+mac+G shortcut from finder, then type in a path. It works in both english and norwegian on my machine. I also tested the binaries with a friend and they work there too.

The latter part is curious. I know these kind of translations are sometimes done in the shell, but I can't image they magically translate strings in environment values inside applications.

Quote
Secondly, yes i did realize that I could use $UNIX as a compilerswitch afterwards. The compiler switching is actually taken from the shellcontrols unit that ships with lazarus.. ahem..

Shellctrls has no Ifdef linux everywhere. So it is e.g. FreeBSD free.

Quote
You wrote: "1. it drags in the VCL just to access environment variables via the application object."

Well most visual application ends up using those units anyways.

Yes, but this is not a visual unit. Moreover, I can put stuff in FPC, but not in Lazarus.

Quote
Also: "It fails for everything but Linux, Darwin and Windows derivatives.  Both FPC and Lazarus support more.". Eh.. thats sort of the point. I will write for two platforms (mac & windows), and since its my unit -- well.. im dont really care about Amiga or win-CE. But someone might, and im sure they can add the needed code for that.

The point is mainly that you call generic unix api, that works on all unixlikes, but put it under ifdef linux.


Quote
And "Partially duplicates badly, what is already system provided:". Well, i did not know about those so i didnt duplicate anything by intention.

Good intentions don't make the duplication less :-)

Quote
As for the messy part.. what exactly is messy? If you remove the compiler switches and replace it with $UNIX like you propose.

I judged what was there, not what could be there.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Folders unit for Linux, OS X and windows
« Reply #5 on: October 05, 2010, 01:29:15 am »
Using a VCL/LCL unit like Forms in a non-visual unit is just a bad idea. It means you'll have trouble using your unit in:
- console apps
- libraries
- non-LCL visual apps

Note how RTL/FCL has no dependencies on LCL units. That should be your first clue.

In this case it's a small mistake, easily corrected. However, if you're a programmer who puts a lot of non-visual code (business rules, database access, etc.) into your form units, then this is indicative of a larger problem.

Your main mistake is not following through on making your routines truly cross-platform. For example, you correctly used the Win API functions for obtaining system information, but you didn't do that for OS X or Linux. Don't think you can just wing it on those platforms. You'll have to learn something about them to program them effectively.

For example, the right way to get the paths to Music, etc. is to use the API that Apple provides for that purpose (folder manager interface). Familiarize yourself with the MacOSAll.pas unit that FPC provides, which includes the folder manager constants and function declarations. Then you can adapt code like this:

http://www.macosxguru.net/article.php?story=20030728200228312

And be sure to spend some time here:

http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/OSX_Technology_Overview/About/About.html

Same with Linux. If an API is provided, use it, don't wing it.

Part of cross-platform development means knowing when to generalize something and when not to. For example, how would you go about determining where to store application preferences and how to read and write them with OS X? Well, you could take the easy way out and just do it like they do on Linux, meaning creating a hidden folder in the user's home (the way Lazarus does) and store the preferences in one or more files in whatever format you want (XML in Laz's case). However, this is not the way most apps do it on OS X. Instead, they store preferences in the Preferences folder provided, using the API that Apple provides for reading and writing preferences. With a programming tool, it's probably not fatal to do it the wrong way (or if it's some ancient program like Gimp), but if a modern app does it the wrong way, users will likely reject it (or better yet: they'll use a competing app that does things the way they expect them to be done).

Thanks.

-Phil

wotanica

  • Guest
Re: Folders unit for Linux, OS X and windows
« Reply #6 on: October 05, 2010, 03:34:32 am »
Yeah.. So I've heard. Twice.

You people are fucking unbelievable. You publish code yourself that dont even check points. Lazarus itself crash if you so much as sit wrong on the chair, hardly any Delphi coder takes it serious because of its incessant reputation of crashing.

But then I publish a small beginners unit, just a start (as stated), and you tear at it like vultures.

It works on Mac and it works on windows. And I dont give a crap about be-os or Amiga. I mean, who the heck uses beos today? A hundred? A thousand? Yeah that will put food on the table..

I will remove linux from the list. And you know what? It works perfectly under windows and Mac. And like i said: I will adjust it to better meet those req.

Jez.. give a guy a break..

Whats next? I used to many tabs? Should have had lowercase first character in the names? Just delete this whole post ok - and my account while your at it.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12711
  • FPC developer.
Re: Folders unit for Linux, OS X and windows
« Reply #7 on: October 05, 2010, 11:07:09 am »

You people are fucking unbelievable.

No need for swearing.

Quote
You publish code yourself that dont even check points. Lazarus itself crash if you so much as sit wrong on the chair, hardly any Delphi coder takes it serious because of its incessant reputation of crashing.

Still, that is about millions of lines of code.

Quote
But then I publish a small beginners unit, just a start (as stated), and you tear at it like vultures.

No, read your own first post, you stated it for "standard inclusion" in FPC/Lazarus. That is not beginner.

Quote
It works on Mac and it works on windows. And I dont give a crap about be-os or Amiga. I mean, who the heck uses beos today? A hundred? A thousand? Yeah that will put food on the table..

But we do care. And for inclusion that matters. Moreover, the hardcoding of string  like Downloads, Music etc are doubtful, even on Mac. You decided to ignore that criticism because that was not convenient.

So basically it is only somewhat Ok for windows, and there are heaps of unit on Delphi that do this, since it is base windows functionality

Quote
Whats next? I used to many tabs? Should have had lowercase first character in the names? Just delete this whole post ok - and my account while your at it.

If you can't handle criticism, don't ask for inclusion and don't ask opinions.
« Last Edit: October 06, 2010, 10:24:06 am by marcov »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12711
  • FPC developer.
Re: Folders unit for Linux, OS X and windows
« Reply #8 on: October 05, 2010, 11:20:08 am »
Oh, another point, Free Pascal has a system fillword and filldword procedure (which are optimized). So maybe rename fillcharw to fillword and ifndef fpc it.

captian jaster

  • Guest
Re: Folders unit for Linux, OS X and windows
« Reply #9 on: October 05, 2010, 01:49:08 pm »
Yeah.. So I've heard. Twice.

You people are fucking unbelievable. You publish code yourself that dont even check points. Lazarus itself crash if you so much as sit wrong on the chair, hardly any Delphi coder takes it serious because of its incessant reputation of crashing.

But then I publish a small beginners unit, just a start (as stated), and you tear at it like vultures.

It works on Mac and it works on windows. And I dont give a crap about be-os or Amiga. I mean, who the heck uses beos today? A hundred? A thousand? Yeah that will put food on the table..

I will remove linux from the list. And you know what? It works perfectly under windows and Mac. And like i said: I will adjust it to better meet those req.

Jez.. give a guy a break..

Whats next? I used to many tabs? Should have had lowercase first character in the names? Just delete this whole post ok - and my account while your at it.

First off...
Lazarus doesn't crash with me :)
Second I published a file and folders unit and got the same criticism.. But instead of getting PO'D
I used it and worked on it.. and look at me now... I've grown into a well rounded programmer...
Third..
It isn't about how many people use BEOS or Amiga.. Because some one may... Lazarus is sorta like Delphi for every other OS... many people still use BEOS/Haiku OS because its fast.. and if Lazarus is supported on it. I can port applications and even grow the user's of the OS...

I understand you don't wanna develop for BEOS and you don't have to.. Just learn to take criticism. Mkay? 

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #10 on: October 05, 2010, 03:13:40 pm »
The idea is quite good. It's a pitty that wotanica delete his account, which I suppose means that he doesn't want to discuss the issue further.

The folder location functions (after being improved a lot and merged into a single function instead of many) could be added to Lazarus.

Adding them to Free Pascal could be problematic for some operating systems. Android, for example, is just linux, but it has a completely different folder structure.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12711
  • FPC developer.
Re: Folders unit for Linux, OS X and windows
« Reply #11 on: October 05, 2010, 03:32:01 pm »

The folder location functions (after being improved a lot and merged into a single function instead of many) could be added to Lazarus.


I guess the windows implementations could be added to winutils. The rest is already available or isn't usable because it hardcodes locale specific strings.

jarto

  • Full Member
  • ***
  • Posts: 106
Re: Folders unit for Linux, OS X and windows
« Reply #12 on: October 05, 2010, 07:43:40 pm »

You people are fucking unbelievable.

No need for swearing.


Sorry, but I have to step in and defend wotanica. You should really think twice before greeting a new contributor by calling his code "very, very, messy". Even if his code was not up to par to be included in Lazarus, there's no need to be rude.

When a new person submits code, you should really expect, that the contributor knows very little about cross platform development. Act as a mentor, thank him and make polite requests for changes. After a few revisions it may evolve into something worth including in Lazarus.

This person took time during his weekend to brush up his Delphi skills, write code and to contribute it. It's a pity that he was not greeted in a way that would motivate him to stick around and contribute more in the future.

eny

  • Hero Member
  • *****
  • Posts: 1658
Re: Folders unit for Linux, OS X and windows
« Reply #13 on: October 05, 2010, 08:21:37 pm »
No need for swearing.
I agree, but...

Sorry, but I have to step in and defend wotanica. You should really think twice before greeting a new contributor by calling his code "very, very, messy". Even if his code was not up to par to be included in Lazarus, there's no need to be rude.
I agree with jarto as well.

Just one look at the roadmap and one will see that there's enough things that (currently) solely work for window$ and linux.
« Last Edit: October 05, 2010, 08:27:21 pm by eny »
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

vfclists

  • Hero Member
  • *****
  • Posts: 1165
    • HowTos Considered Harmful?
Re: Folders unit for Linux, OS X and windows
« Reply #14 on: October 05, 2010, 11:07:38 pm »
wotanica is too touchy - ego is one of the most difficult issues in open source projects. Code will be criticised and geeks are not renowned for their tact.

Wotanica is  newcomer to a community, and should be patient and persistent enough to adapt to its ways which are for the long term benefit.

I get frustrated with Lazarus sometimes, actually a lot of times, but I don't lash out in frustration because it is a volunteer project, and many choices have been made which were wrong in hindsight, and some are probably still being made.

Everyone is paying the price for it. There are good reasons for such criticisms and the criticisms made were well reasoned. If he is upset at the tone they were delivered there is no need to respond so angrily.



You people are fucking unbelievable.

No need for swearing.


Sorry, but I have to step in and defend wotanica. You should really think twice before greeting a new contributor by calling his code "very, very, messy". Even if his code was not up to par to be included in Lazarus, there's no need to be rude.

When a new person submits code, you should really expect, that the contributor knows very little about cross platform development. Act as a mentor, thank him and make polite requests for changes. After a few revisions it may evolve into something worth including in Lazarus.

This person took time during his weekend to brush up his Delphi skills, write code and to contribute it. It's a pity that he was not greeted in a way that would motivate him to stick around and contribute more in the future.
Lazarus 3.0/FPC 3.2.2

 

TinyPortal © 2005-2018