Skip to content

Commit

Permalink
Merge pull request #5560 from Goober5000/fred_help
Browse files Browse the repository at this point in the history
improve launching of FRED help
  • Loading branch information
Goober5000 authored Aug 18, 2023
2 parents 03f0160 + e796a4f commit 91497d5
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions fred2/mainfrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CPoint Global_point2;
/**
* @brief Launches the default browser to open the given URL
*/
void url_launch(const char *url);
bool url_launch(const char *url);


#ifdef _DEBUG
Expand Down Expand Up @@ -257,20 +257,19 @@ void CMainFrame::OnFileMissionnotes() {
}

void CMainFrame::OnFredHelp() {
// try included documentation
auto res = cf_find_file_location("index.html", CF_TYPE_FREDDOCS);
if (!res.found) {
ReleaseWarning(LOCATION, "Could not find FRED help files!");
return;
}

if (res.offset != 0) {
// We need an actual file location so VP files are not valid
Error(LOCATION, "The FRED documentation was found in a pack (VP) file. This is not valid!");
return;
// We need an actual file location so VP files are not valid
if (res.found) {
if (res.offset == 0) {
url_launch(res.full_name.c_str());
return;
}
}

// shell_open url
url_launch(res.full_name.c_str());
// try online as a fallback
url_launch("https://fredzone.hard-light.net/freddocs/");
}

void CMainFrame::OnInitMenu(CMenu* pMenu) {
Expand Down Expand Up @@ -482,7 +481,8 @@ int color_combo_box::GetItemIndex(int ship_class)
return -1;
}

void url_launch(const char *url) {
bool url_launch(const char *url)
{
int r;

r = (int) ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOW);
Expand All @@ -501,13 +501,18 @@ void url_launch(const char *url) {
case SE_ERR_OOM: txt = XSTR("There was not enough memory to complete the operation.", 1115); break;
case SE_ERR_SHARE: txt = XSTR("A sharing violation occurred.", 1116); break;

// No browser installed message
case SE_ERR_NOASSOC:
// No browser installed message
case SE_ERR_NOASSOC: txt = XSTR("\r\nNo web browser found. There isn't one installed or if \r\none is installed, it isn't set to be the default browser.\r\n\r\n", 1117); break;

case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND: txt = XSTR("\r\nUnable to locate Fred Help file: \\data\\freddocs\\index.html\r\n", 1479); break;

default: txt = XSTR("Unknown error occurred.", 1118); break;
}

AfxMessageBox(txt, MB_OK | MB_ICONERROR);
return false;
}

return true;
}

0 comments on commit 91497d5

Please sign in to comment.