Solved How do I open a maxon::Url in the default web browser?

Hi,

I have a Maxon::Url, containing the following:
file:///Applications/Maxon/Cinema 4D R22/plugins/myplugin/help/content/omyobject/omyobject.html#MYOBJECT_ATTRIBUTE.

The Url was assembled in a PluginHelpDelegate:

	maxon::Url url;
	url.SetUrl(GeGetPluginPath().GetString(), true) iferr_return;
	
	url.Append("help"_s) iferr_return;
	url.Append("content"_s) iferr_return;
	url.Append(baseType.ToLower()) iferr_return;
	url.Append(opType.ToLower() + ".html#"_s + property) iferr_return;

The Url is correct, if I copy & paste it into Safari or Chrome, the page opens as expected.

But trying to open it from within Cinema 4D, using GeOpenHTML(url.GetUrl()); just returns false. Why?

Cheers,
Frank

www.frankwilleke.de
Only asking personal code questions here.

Why not use IoShowInOS()? (didn't test it on macOS though).

maxon::Url url { "file:///D:/_tests/test.html"_s };
url.IoShowInOS(maxon::IOSHOWINOSFLAGS::OPEN_IN_EXPLORER) iferr_ignore("");

See Url Manual.

Ah, I made it work like this:

maxon::String urlStr = url.GetUrl();
urlStr.Replace(" "_s, "%20"_s) iferr_return;

...

GeOpenHTML(urlStr);

But this replacement seems clumsy. Isn't there a function in the API to escape URLs?

Cheers,
Frank

www.frankwilleke.de
Only asking personal code questions here.

hi,

the only way i found was using the old FilenameToURL witch is a static function that need a Filename and return a string.

static maxon::Tuple<maxon::String, Int32> EscapeUrl(maxon::Url& url)
{
	Filename urlToEscape = MaxonConvert(url);
	Int32 encoding;
	maxon::String myUrlAsEscapedString = HtmlViewerCustomGui::FilenameToURL(urlToEscape, &encoding);
	return { myUrlAsEscapedString, encoding };
}


static maxon::Result<void> pc12829_action(BaseDocument* doc)
{
	iferr_scope;
	maxon::Url  myUrl {"file:////Applications/Maxon/Cinema 4D R2/plugins/myplugin/help/content/omyobject/omyobject.html#MY OBJCT_ATTRIBU TE"_s };

	maxon::Tuple<maxon::String, Int32> convertedResult = EscapeUrl(myUrl);
	
	maxon::String myUrlAsEscapedString = convertedResult.GetFirst();
	Int32 encoding = convertedResult.GetSecond();


	ApplicationOutput("the url is @ and escaped is @ the url was escaped is @", myUrl, myUrlAsEscapedString, encoding == URL_ENCODING_ESCAPED);


	return maxon::OK;
}

But your # will be transform to %23 so you have to be careful with that. But property is something that you can control and shouldn't have space there.

Cheers,
Manuel

MAXON SDK Specialist

MAXON Registered Developer

Why not use IoShowInOS()? (didn't test it on macOS though).

maxon::Url url { "file:///D:/_tests/test.html"_s };
url.IoShowInOS(maxon::IOSHOWINOSFLAGS::OPEN_IN_EXPLORER) iferr_ignore("");

See Url Manual.

@PluginStudent said in How do I open a maxon::Url in the default web browser?:

Why not use IoShowInOS()? (didn't test it on macOS though).
maxon::Url url { "file:///D:/_tests/test.html"_s };
url.IoShowInOS(maxon::IOSHOWINOSFLAGS::OPEN_IN_EXPLORER) iferr_ignore("");

See Url Manual.

I was so focused on escaping the URL, thanks a lot @PluginStudent

MAXON SDK Specialist

MAXON Registered Developer

Oh, cool! I'll test that. Thank you!

www.frankwilleke.de
Only asking personal code questions here.

Hmmmm, well, on the one hand this function is a nice thing: It really does do the escaping for me, so the spaces in the URL are correctly replaced with "%20".

But it does not handle anchors in a URL.

This URL works fine:
file:///Applications/Maxon/Cinema 4D R22/plugins/myplugin/help/content/omyobject/omyobject.html

But this URL is not opened, instead an error (code -43) is thrown:
file:///Applications/Maxon/Cinema 4D R22/plugins/myplugin/help/content/omyobject/omyobject.html#MYOBJECT_ATTRIBUTE

That is a pity.

www.frankwilleke.de
Only asking personal code questions here.