Recent

Author Topic: FileExistUTF8 problem  (Read 10655 times)

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
FileExistUTF8 problem
« on: June 28, 2018, 11:29:58 pm »
Hi, i'm currently try to resolve a problem with the function FileExistUTF8.

In my application i have :

Code: Pascal  [Select][+][-]
  1. Folder := '.' + PathDelim + FileDir + PathDelim;    //
  2.     LF := Folder + 'lclstrconsts' + '.' + Language + '.' + C_PoExtension;
  3.     if FileExistsUTF8(LF) then // existe-t-il ?
  4.       Translations.TranslateUnitResourceStrings('LCLStrConsts', LF,Language, UpperCase(Language)) // on traduit
  5.     else
  6.       ShowMessage('FileNotFound : '+LF);  
   

Note LazUTF8 and LazFileUTils are in uses (not FileUtils)

The FileExistsUTF8 always return me "file not found"

My application work well on Linux Manjaro 64 bit and Windows 10 64 bit

I'm on MacOS High Sierra and Lazarus 1.8.5 32 bit with carbon.

What can i do ?

Thanks

Best regards                                                                 

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: FileExistUTF8 problem
« Reply #1 on: June 29, 2018, 12:13:22 am »
use expandfilename to convert the relative path to absolute and see if that leads to the file you assume it points.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FileExistUTF8 problem
« Reply #2 on: June 29, 2018, 03:00:44 pm »
Hi

Expandfilename doing anything. I'm also tried by assigned folder value in hard like

/Users/usename/Documents/Projets/Lazarus/Components/GIFViewer/demos/gifview/languages/

I'm also tried FileExist(UTF8ToAnsi(LF); same issue.

Do you think is related to MacOS High Sierra ?

balazsszekely

  • Guest
Re: FileExistUTF8 problem
« Reply #3 on: June 29, 2018, 03:41:48 pm »
@BeanzMaster
I tested FileExist/FileExistsUTF8, both works fine on High Sierra.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FileExistUTF8 problem
« Reply #4 on: June 30, 2018, 01:00:39 am »
@GetMem
It is the demo gifviewer is trandlated to english or french when you change language ?

If yes, the problem gone from my MacOS or with ?????

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FileExistUTF8 problem
« Reply #5 on: June 30, 2018, 01:30:35 am »
If i do
Code: Pascal  [Select][+][-]
  1. ExtractFilePath(Application.ExeName)
it return

"/Users/usename/Documents/Projets/Lazarus/Components/GIFViewer/demos/gifview.app/Contents/MacOS/"

if i do
Code: Pascal  [Select][+][-]
  1. getCurrentDir
it returns "/"

So what's the trick under MacOS ?

balazsszekely

  • Guest
Re: FileExistUTF8 problem
« Reply #6 on: June 30, 2018, 11:02:36 am »
Quote
It is the demo gifviewer is trandlated to english or french when you change language ?
I did not test with gifviewer, just with a regular file. 

Quote
If i do  ExtractFilePath(Application.ExeName) it returns:
"/Users/usename/Documents/Projets/Lazarus/Components/GIFViewer/demos/gifview.app/Contents/MacOS/"
Yes because gifview.app(bundle) is basically a directory. When you're done with the development, you should copy the executable "gifview"(located in your main development folder) into the bundle("gifview.app/Contents/MacOS/") and replace the symlink with the executable. You can achieve this by right clicking gifview.app then "Show Package Contents". It's common practice(OSX) to keep the resources(images, language files, etc) inside the bundle, however if you wish a solution which will work on every major platform you can do something like this:
Code: Pascal  [Select][+][-]
  1. var
  2.   PathToLangFiles: String;
  3. begin
  4.   {$IFDEF LCLcarbon}
  5.     PathToLangFiles := Copy(Application.ExeName, 1, Pos(ApplicationName + '.app', Application.ExeName) - 1) + PathDelim + 'languages';
  6.   {$ELSE}
  7.     PathToLangFiles := Application.ExeName + PathDelim + 'languages';
  8.   {$ENDIF}          
  9. end;      
  10.  

The above code will return the languages directory located in the main development folder, beside the executable(bundle on osx).

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FileExistUTF8 problem
« Reply #7 on: June 30, 2018, 03:08:26 pm »
Quote
It is the demo gifviewer is trandlated to english or french when you change language ?
I did not test with gifviewer, just with a regular file. 

Quote
If i do  ExtractFilePath(Application.ExeName) it returns:
"/Users/usename/Documents/Projets/Lazarus/Components/GIFViewer/demos/gifview.app/Contents/MacOS/"
Yes because gifview.app(bundle) is basically a directory. When you're done with the development, you should copy the executable "gifview"(located in your main development folder) into the bundle("gifview.app/Contents/MacOS/") and replace the symlink with the executable. You can achieve this by right clicking gifview.app then "Show Package Contents". It's common practice(OSX) to keep the resources(images, language files, etc) inside the bundle, however if you wish a solution which will work on every major platform you can do something like this:
Code: Pascal  [Select][+][-]
  1. var
  2.   PathToLangFiles: String;
  3. begin
  4.   {$IFDEF LCLcarbon}
  5.     PathToLangFiles := Copy(Application.ExeName, 1, Pos(ApplicationName + '.app', Application.ExeName) - 1) + PathDelim + 'languages';
  6.   {$ELSE}
  7.     PathToLangFiles := Application.ExeName + PathDelim + 'languages';
  8.   {$ENDIF}          
  9. end;      
  10.  

The above code will return the languages directory located in the main development folder, beside the executable(bundle on osx).

Thanks GetMem. Yesterday i see, i enable the gdb output. This is because i've  enabled "Include Application Informations" in the project's option.
I had also some problem with GDB and this project du to the symlinks  and by disable it all gone to the normal.

I'll test your piece of code

Thanks

Cheers

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FileExistUTF8 problem
« Reply #8 on: July 01, 2018, 11:21:28 am »
Thanks Getmem it solve the path problem, but ui is never translated  :o

balazsszekely

  • Guest
Re: FileExistUTF8 problem
« Reply #9 on: July 02, 2018, 08:25:13 am »
Quote
Thanks Getmem it solve the path problem, but ui is never translated  :o
You're welcome. Did you try to debug it? Unfortunately the debugger is not working properly on my OSX.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FileExistUTF8 problem
« Reply #10 on: July 04, 2018, 12:40:55 am »
Hi,
You're welcome. Did you try to debug it? Unfortunately the debugger is not working properly on my OSX.

Me to, i have some problem with GDB on some application it work and sometime not GDB not stop and run continusly in background. Each time i want recompile lazarus ask me to stop DBG and i need to launch without debug.

So i resolve my problem with path i'm use Application.Location for Win and Linux and
Code: Pascal  [Select][+][-]
  1. Copy(Application.ExeName, 1, Pos(ApplicationName + '.app', Application.ExeName) - 1);
for Mac

Thanks again

 

TinyPortal © 2005-2018