Real Software Forums
http://forums.realsoftware.com/

Pathname Encoding Trouble
http://forums.realsoftware.com/viewtopic.php?f=6&t=38208
Page 1 of 1

Author:  pkronen [ Sat Mar 19, 2011 8:46 am ]
Post subject:  Pathname Encoding Trouble

I have an encoding problem and I have no clue what to do next.

A user an a Windows PC has a user name containing German "ä", but when I want to write a file (see below) into his Application Data, these characters suddenly have another encoding (and are 2 bytes long) and I get a Nil Object exception during the open process:

folder = SpecialFolder.ApplicationData
path = convertEncode(folder.AbsolutePath)
#if TargetMacos then path2 = ConvertEncoding(path,Encodings.MacRoman)
#if TargetWin32 then path2 = ConvertEncoding(path,Encodings.WindowsANSI)
name = path2+"Filename")
file = GetFolderItem(name)

Any suggestions? Thanks.

Author:  MonkeybreadSoftware [ Wed Mar 23, 2011 11:50 am ]
Post subject:  Re: Pathname Encoding Trouble

Quote:
folder = SpecialFolder.ApplicationData
file = folder.child(filename)


let Real Studio do the details like encoding and paths.
It's more likely you break something with encoding conversion and absolutepath math than if you do like above.

Greetings
Christian

Author:  pkronen [ Sat Mar 26, 2011 5:27 pm ]
Post subject:  Re: Pathname Encoding Trouble

Well, this does not much help further.
My code is now:

textfile = GetFolderItem(SpecialFolder.ApplicationData.AbsolutePath)
textfile = textfile.child(textfold)
if textfile = nil or not textfile.exists then
textfile = new folderitem(SpecialFolder.ApplicationData)
textfile = textfile.child(textfold)
textfile.CreateAsFolder
end

If the Windows username contains no äöü, it works, if it does, the folder is not being created and later when trying to write a file into it I get a nil object exception!

Author:  pkronen [ Sun Mar 27, 2011 2:16 am ]
Post subject:  Re: Pathname Encoding Trouble

Maybe I have to add:

Always when running the app from the 'äöü' user, this Windows window appears:

Open Files - Security Warning
The publisher could not be verified... (and so on)
From: .PSF
Run / Cancel

Might there be the root cause preventing folders to be created?

Author:  MonkeybreadSoftware [ Sun Mar 27, 2011 3:14 am ]
Post subject:  Re: Pathname Encoding Trouble

Maybe the ApplicationSupportFolder function is broken?

You could try applicationsupportFolderMBS(-32763) from my plugins.

By the way, constructions like this are not good:

textfile = GetFolderItem(SpecialFolder.ApplicationData.AbsolutePath)

You ask for absolutepath and have it parsed right away. What a waste of resources.

textfile = new folderitem(SpecialFolder.ApplicationData)

And here you make a copy of the folderitem?

Greetings
Christian

Author:  pkronen [ Mon Mar 28, 2011 4:06 am ]
Post subject:  Re: Pathname Encoding Trouble

OK, thanks Cristian for the tip.
Wasn't aware of such a big difference between getfolderitem and new folderitem.

Anyway, I have found out more:
It has nothing to do with the Windows warning, nor in general with user nams containg ä ö ü. But:

Creating a folder like this works!:
textfile = new folderitem(SpecialFolder.ApplicationData)
textfile = textfile.child("Folder1").child("Folder2")
msgbox textfile.absolutepath ' -> gives ...useräöü.applicationdata.folder1.folder2
textfile.CreateAsFolder

This doesn't:
ftab(f,4) = "Folder2"
textfile = new folderitem(SpecialFolder.ApplicationData)
textfile = textfile.child("Folder1").child(ftab(f,4))
msgbox textfile.absolutepath ' -> gives ...usera#o@u&.applicationdata.folder1.folder2
textfile.CreateAsFolder

No folder is created and when trying to write into it, a Nil Object Exp. is naturally triggered.
So why are the äöü being messed up with?

Any idea if it's a bug or a hint to get around it?
Peter

Author:  pkronen [ Mon Mar 28, 2011 5:35 am ]
Post subject:  Re: Pathname Encoding Trouble

Got it!

Found just out that table entries have no encodings, but strings UTF-8.

I used:
foldername = DefineEncoding(ftab(f,4),Encodings.UTF8)

and now it works in any case!

Author:  npalardy [ Mon Mar 28, 2011 8:41 am ]
Post subject:  Re: Pathname Encoding Trouble

What's the declaration for ftab ?
That might give a clue why there was no encoding and why you needed to do what you did

Author:  pkronen [ Tue Mar 29, 2011 9:20 am ]
Post subject:  Re: Pathname Encoding Trouble

Hi npalardy,

In method app, properties: ftab as string(12,4), f as integer

Peter

Author:  npalardy [ Tue Mar 29, 2011 4:17 pm ]
Post subject:  Re: Pathname Encoding Trouble

how did you populate it with the names of the files ?

Author:  pkronen [ Wed Apr 06, 2011 2:41 pm ]
Post subject:  Re: Pathname Encoding Trouble

Like this:

item = dbrs.field("PBSRecord").getstring
j = instr(item,"period:")
k = instr(item,"sequence:")
ftab(i,4) = mid(item,j+8,6)+mid(item,k+10,1)

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/