html-files in an app-sub-folder

Mac OSX specific forum
5mware
User
User
Posts: 30
Joined: Mon Dec 14, 2015 2:14 pm

html-files in an app-sub-folder

Post by 5mware »

hi guys,

i have a problem that cost me lots of time, but i couldnt solve it.

Filesystem-history:
help.app/Contents/MacOS/helpfiles/

The app is called "help"
the html-files are how you see above in a sub-folder called "helpfiles"

the damn webgadget should show me the shit with file://

I have a sidebar-list on the left-side of the window and the webgadget at the rightside.

if i click on a html-file in the list, it shell show the damn content in the webgadget.

now the problem:

the app works in the compiled-directory very well. think the compiled-directory is just the project directory. think something like this:

/Users/myhome/myprojects/myhelpApp/

in that path is my source-code and if I compile the whole shit, I get there my help.app

if i double click on it, everything works perfect.

if i copy the shit to another directory on my computer, the program loads, but the html-files wont see.

i cannot post the whole code, because its to large. this is my code to find the correct root permanently:

Code: Select all

Global myPath.s = ""
myPath = GetPathPart(ProgramFilename())
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  #sys_char = "\"
CompilerElse
  #sys_char = "/"
CompilerEndIf
If Right( myPath, 1 ) <> #sys_char
  myPath + #sys_char
EndIf
Global myFiles.s = myPath + "helpfiles/"
in my code, i call the url to a damn file like this:

Code: Select all

SetGadgetText( webGadgetID, "files://" + myFiles + currentFile )
i checked "currentfile" it is correctly filled by the filename from the list:

Code: Select all

If eventCode = #PB_Event_Gadget And EventGadget() = MyListID And EventType() = #PB_EventType_Change
  currentFile = GetGadgetItemText( MyListID, GetGadgetState(MyListID) )
  SetGadgetText( webGadgetID, "files://" + myFiles + currentFile )
EndIf
i think it has something to do with user-rights but i am not sure. i checked the file properties with the Information-Dialog of the mac and set the rights to everyone to read and write. I did it also for the entire help.app-directory and it's content. but doesn't work.

what do you i wrong?

has anyone an idea?
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: html-files in an app-sub-folder

Post by Wolfram »

You must set the path to the main.html file relative.
"Resources/helpfiles/" or "Resources/helpfiles/main.html"

And than copy you help files folder inside the Resources inside of the help.app
macOS Catalina 10.15.7
5mware
User
User
Posts: 30
Joined: Mon Dec 14, 2015 2:14 pm

Re: html-files in an app-sub-folder

Post by 5mware »

the relative-path is a good idea. i tried it.

the files become loaded into the listviewgadget successfully, but i cannot load the currentfile into the damn webgadget.

??
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: html-files in an app-sub-folder

Post by Wolfram »

5mware wrote:the relative-path is a good idea. i tried it.

the files become loaded into the listviewgadget successfully, but i cannot load the currentfile into the damn webgadget.

??

Code: Select all

Bundle = CocoaMessage(0, 0, "NSBundle mainBundle")
BundlePath = CocoaMessage(0, Bundle, "bundlePath")
Path.s = PeekS(CocoaMessage(0, BundlePath, "UTF8String"), -1, #PB_UTF8)
Debug Path +"/Resources/helpfiles/"
macOS Catalina 10.15.7
5mware
User
User
Posts: 30
Joined: Mon Dec 14, 2015 2:14 pm

Re: html-files in an app-sub-folder

Post by 5mware »

could the webgadget has a bug?

is there any special thing to do to get it work? maybe something with cocoa. e.g. pathing the url by cocoa instead of SetGadgetText()?

url = file://Resources/helpfiles/index.html

Cheching like this:

Code: Select all

MessageRequester(Str(Filesize(currentFile)),currentFile)
is successful. In both ways (relative position and with the bundlepath from cocoa).

but the webgadget doens't respond anyway. it's blank.

I checked my html-files with firefox, chrome, opera. all fine. no problem.

??
5mware
User
User
Posts: 30
Joined: Mon Dec 14, 2015 2:14 pm

Re: html-files in an app-sub-folder

Post by 5mware »

code:

Code: Select all

  If pure_event = #PB_Event_Gadget And EventGadget() = #MyListID And EventType() = #PB_EventType_Change
    SetGadgetText( #WebGadgetID, "file://" + currentFile )
    SetWindowTitle( #MyWindow, URL = " + GetGadgetText(#WebGadgetID) )
  EndIf
result:

The webgadget keeps blank. no response.
but it returns the full-path to the html-file correctly to the window-title.

maybe a bug??
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: html-files in an app-sub-folder

Post by Wolfram »

This is tested and works.

Code: Select all

Bundle = CocoaMessage(0, 0, "NSBundle mainBundle")
BundlePath = CocoaMessage(0, Bundle, "bundlePath")
Path.s = PeekS(CocoaMessage(0, BundlePath, "UTF8String"), -1, #PB_UTF8)
Path +"/Contents/Resources/helpfiles/Main.html"
Debug Path


If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
    WebGadget(0, 10, 10, 580, 280, "file://" +Path)

    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
macOS Catalina 10.15.7
5mware
User
User
Posts: 30
Joined: Mon Dec 14, 2015 2:14 pm

Re: html-files in an app-sub-folder

Post by 5mware »

ok i solved it.

in your first code-snip you wrote

Code: Select all

Bundle = CocoaMessage(0, 0, "NSBundle mainBundle")
BundlePath = CocoaMessage(0, Bundle, "bundlePath")
Path.s = PeekS(CocoaMessage(0, BundlePath, "UTF8String"), -1, #PB_UTF8)
Debug Path +"/Resources/helpfiles/"
in your last post your added "/Contents/Resource/helpfiles/". That helped and it works.

but i found the main reason why it doens't work, if you copy help.app to another directory.

the problem was white-spaces in the directory-names. Sample:
/Users/myhome/mydir1/sample dir/help.app
... doens't work. dont know why.
/Users/myhome/mydir1/sample-dir/help.app
or
/Users/myhome/mydir1/sample_dir/help.app
works perfect.

maybe that would help some one who have the same problem.

:-) thanks.
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: html-files in an app-sub-folder

Post by Wolfram »

5mware wrote:
/Users/myhome/mydir1/sample dir/help.app
... doens't work. dont know why.
/Users/myhome/mydir1/sample-dir/help.app
or
/Users/myhome/mydir1/sample_dir/help.app
works perfect.

Add this code to your app.

Code: Select all

Path = URLEncoder(Path)
macOS Catalina 10.15.7
5mware
User
User
Posts: 30
Joined: Mon Dec 14, 2015 2:14 pm

Re: html-files in an app-sub-folder

Post by 5mware »

i solved the problem.

the webgadget does not accept white-spaces in the url. but you can change the white-spaces into %20. then it works without any problems.

:-)
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: html-files in an app-sub-folder

Post by Wolfram »

It is not just the space (%20), there are more characters that have this problem.
So you must use the URLEncoder() function!

Code: Select all

Path = URLEncoder(Path)
macOS Catalina 10.15.7
Post Reply