Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 13, 2019 4:40 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Pathname Encoding Trouble
PostPosted: Sat Mar 19, 2011 8:46 am 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Wed Mar 23, 2011 11:50 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
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

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Sat Mar 26, 2011 5:27 pm 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Sun Mar 27, 2011 2:16 am 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Sun Mar 27, 2011 3:14 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
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

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Mon Mar 28, 2011 4:06 am 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Mon Mar 28, 2011 5:35 am 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Mon Mar 28, 2011 8:41 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
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

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Tue Mar 29, 2011 9:20 am 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
Hi npalardy,

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

Peter


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Tue Mar 29, 2011 4:17 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
how did you populate it with the names of the files ?

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Pathname Encoding Trouble
PostPosted: Wed Apr 06, 2011 2:41 pm 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
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)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group