Recent

Author Topic: Trying to get My Documents folder  (Read 12710 times)

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3654
  • I like bugs.
Re: Trying to get My Documents folder
« Reply #30 on: July 19, 2017, 11:42:58 am »
I am now not using systoutf8, and the error is still occuring in the IDE, ...
True, the error is not related to string conversions. It is likely a privileges issue.
However you need to understand the strings issues for your future programming. That's why I nagged.  :)

josh

  • Hero Member
  • *****
  • Posts: 754
Re: Trying to get My Documents folder
« Reply #31 on: July 19, 2017, 12:07:04 pm »
@Tried running lazarus as admin, but this is not working as doing so the Documents folder is the administrator's Documents folder, not the Current Users Document Folder.

Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

Thaddy

  • Hero Member
  • *****
  • Posts: 9284
Re: Trying to get My Documents folder
« Reply #32 on: July 19, 2017, 12:22:24 pm »
There's a difference between the "My Documents" and "Documents" folder. Only one of them is current. The other one is a left-over from a re-install of Windows, e.g. after a crash or an update to Windows 10, but choosing "keep my data". The "Documents" folder is usually the real one. "My documents" can sometimes still be accessed with admin rights. Note in any case they are virtual folders, the actual path is different and under users (or under windows.old!). So don't mix up the two. The example code above gives you access to *only* the current documents folder, the correct one.
Note,that since it is a virtual folder, the "My Documents" symlink *may* still exist, but can point to nowhere. The data is not lost, it is still there and accessible under windows.old

It may seem complex but it is easy. If you still do not understand it I will try to re-phrase it.
« Last Edit: July 19, 2017, 12:33:20 pm by Thaddy »
also related to equus asinus.

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Trying to get My Documents folder
« Reply #33 on: July 19, 2017, 12:29:41 pm »
I tried your code with a freshly compiled trunk in Windows 7 64 bit Virtualbox with username UmlautUser-äöüÄ.
It gave me the correct directory: C:\Users\UmlautUser-äöüÄ\Documents\

Did you try the GetWindowsSpecialDir from windirs yet? Or does it also return an empty string in the IDE?

Code: Pascal  [Select]
  1. uses windirs;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. begin
  5.   ShowMessage(GetWindowsSpecialDir(CSIDL_PERSONAL));
  6. end;

josh

  • Hero Member
  • *****
  • Posts: 754
Re: Trying to get My Documents folder
« Reply #34 on: July 19, 2017, 12:31:46 pm »
Hi Thaddy,

I can verify the location of the Documents folder in windows by clicking it, choosing properties and it gives their correct locations. and Each user documents folder is created and has their own My Pic, My Movies etc folders.

With the routine on mine, it displaying path not found only when application is run in the IDE, which is causing a problem.

Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

Thaddy

  • Hero Member
  • *****
  • Posts: 9284
Re: Trying to get My Documents folder
« Reply #35 on: July 19, 2017, 12:34:52 pm »
I adapted my answer with more info. Can you read it and tell me if you understand it and if my answer covers the case I suspect is your issue?
Also note rvk's answer, that will return only the current one...the current symlink...for the current Windows installation...But that is the only correct one...

You need to find out the actual path to the data of the old installation and can not usually use the virtual folder anymore. And you can also not treat the old one as a special folder, you must treat it as a full path and find that out first.
« Last Edit: July 19, 2017, 12:45:04 pm by Thaddy »
also related to equus asinus.

josh

  • Hero Member
  • *****
  • Posts: 754
Re: Trying to get My Documents folder
« Reply #36 on: July 19, 2017, 12:44:49 pm »
@Thaddy, thanks for your explanation, I do understand what you are saying, but this does not cover the issue that running the app in the IDE fails, and running directly it works ok.

@rvk
ShowMessage(GetWindowsSpecialDir(CSIDL_PERSONAL));
Return no information when run in the IDE, but shows correctly when launched directly.

I have just created a new user with administrator rights, and this also is doing the same, test system win 7 64 ultimate, lazarus 32 bit, creating 32 bit application.
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

Thaddy

  • Hero Member
  • *****
  • Posts: 9284
Re: Trying to get My Documents folder
« Reply #37 on: July 19, 2017, 12:49:47 pm »
@Thaddy, thanks for your explanation, I do understand what you are saying, but this does not cover the issue that running the app in the IDE fails, and running directly it works ok.
That means that the IDE might not handle virtual folders very well under Windows. I suspect a low-level IO is used instead of the shell api routines. The latter api is the only one that can handle virtual folders under windows transparently. Today I am stuck on arm, but I think this can be easily confirmed by someone else. Worst case scenario is that some idiot hooked the IO API in the Lazarus IDE. In that case: that's an idiot.
« Last Edit: July 19, 2017, 12:53:08 pm by Thaddy »
also related to equus asinus.

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Trying to get My Documents folder
« Reply #38 on: July 19, 2017, 12:57:41 pm »
That means that the IDE might not handle virtual folders very well under Windows. I suspect a low-level IO is used instead of the shell api routines.
Thaddy, the call is already directly to the WinApi with SHGetSpecialFolderPathW. And it seems SHGetFolderPathW (which is called from windirs) also fails in that situation. No virtual directories are used or called.

I have freshly compiled trunk and can't reproduce this issue.
So it's not something from default trunk installation.

Maybe some component might catch or hook it.
So my suggestion would be to checkout a fresh trunk version and try it again without any extra components.

I also don't see why it would fail in the IDE and not outside it.

josh

  • Hero Member
  • *****
  • Posts: 754
Re: Trying to get My Documents folder
« Reply #39 on: July 19, 2017, 12:59:38 pm »
@Thaddy, maybe? What is odd is this only happens when user has utf8 characters in it,  I have just created  a new user with standard ascii characters only; and I have no such problem with the IDE.
So it may be just a odd combination of situations that are causing the problem.
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Trying to get My Documents folder
« Reply #40 on: July 19, 2017, 01:00:29 pm »
So it may be just a odd combination of situations that are causing the problem.
PS. also disable ANY antivirusscanner you might have running !!!

That's the only cause I think sits between the WinApi and Lazarus.

josh

  • Hero Member
  • *****
  • Posts: 754
Re: Trying to get My Documents folder
« Reply #41 on: July 19, 2017, 01:06:11 pm »
@rvk, I have just tried -deactivating my AV completely and still suffering the same issue.
I will try a complete separate installation of trunk in separate folder, it will take some time so will be an hour or so before I can report back on results of that.
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

Thaddy

  • Hero Member
  • *****
  • Posts: 9284
Re: Trying to get My Documents folder
« Reply #42 on: July 19, 2017, 01:11:57 pm »
@rvk, I have just tried -deactivating my AV completely and still suffering the same issue.
I will try a complete separate installation of trunk in separate folder, it will take some time so will be an hour or so before I can report back on results of that.
Well I can't test on windows today before 20:00 ECT, but what about declaring all strings in the routine as unicodestring? FPC will convert a UTF8 to UTF16 automatically..
Usually (although not rare, rvk may be right) Virus scanners are not *that* dumb anymore...
also related to equus asinus.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3654
  • I like bugs.
Re: Trying to get My Documents folder
« Reply #43 on: July 19, 2017, 01:25:57 pm »
What is odd is this only happens when user has utf8 characters in it, ...
Actually on Windows they are UTF-16. Anyway, the user name has Unicode characters outside the 7-bit ASCII range.
Still a mystery...

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Trying to get My Documents folder
« Reply #44 on: July 19, 2017, 01:35:56 pm »
I have just tried -deactivating my AV completely and still suffering the same issue.
Maybe deactivating isn't enough in this case. It might still be sitting in between.
(although it's a longshot but I can't think of anything else at the moment)
(and it would also be weird it worked in an earlier version of the IDE)

Which virusscanner is it?