Skip to content

Commit

Permalink
Fix spelling and comment consistency in the source code. (SuperTux#2545)
Browse files Browse the repository at this point in the history
Aims to improve the readability, spelling, and consistency of the comments in the source code.
  • Loading branch information
bruhmoent authored Aug 12, 2023
1 parent d4e569e commit 5f5d018
Show file tree
Hide file tree
Showing 142 changed files with 1,083 additions and 1,111 deletions.
10 changes: 5 additions & 5 deletions src/addon/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Addon::Type addon_type_from_string(const std::string& type)
}
else
{
throw std::runtime_error("not a valid Addon::Type: " + type);
throw std::runtime_error("Not a valid Addon::Type: " + type);
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ std::string generate_menu_item_text(const Addon& addon)
}
else
{
// Only addon type and name, no need for translation.
// Only add-on type and name, no need for translation.
text = fmt::format("{} \"{}\"", type, addon.get_title());
}

Expand Down Expand Up @@ -130,12 +130,12 @@ Addon::parse(const ReaderMapping& mapping)

if (addon->m_id.empty())
{
throw std::runtime_error("addon id is empty");
throw std::runtime_error("Add-on id is empty");
}

if (addon->m_id.find_first_not_of(s_allowed_characters) != std::string::npos)
{
throw std::runtime_error("addon id contains illegal characters: " + addon->m_id);
throw std::runtime_error("Add-on id contains illegal characters: " + addon->m_id);
}

mapping.get("version", addon->m_version);
Expand Down Expand Up @@ -194,7 +194,7 @@ Addon::parse(const std::string& fname)
auto root = doc.get_root();
if (root.get_name() != "supertux-addoninfo")
{
throw std::runtime_error("file is not a supertux-addoninfo file.");
throw std::runtime_error("File is not a supertux-addoninfo file.");
}
else
{
Expand Down
46 changes: 23 additions & 23 deletions src/addon/addon_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const char* ADDON_INFO_PATH = "/addons/repository.nfo";

MD5 md5_from_file(const std::string& filename)
{
// TODO: this does not work as expected for some files -- IFileStream seems to not always behave like an ifstream.
// TODO: This does not work as expected for some files -- IFileStream seems to not always behave like an ifstream.
//IFileStream ifs(installed_physfs_filename);
//std::string md5 = MD5(ifs).hex_digest();

Expand Down Expand Up @@ -98,7 +98,7 @@ static Addon& get_addon(const AddonManager::AddonMap& list, const AddonId& id,

static std::vector<AddonId> get_addons(const AddonManager::AddonMap& list)
{
// Use a map for storing sorted addon titles with their respective IDs.
// Use a map for storing sorted add-on titles with their respective IDs.
std::map<std::string, AddonId> sorted_titles;
for (const auto& [id, addon] : list)
{
Expand All @@ -121,7 +121,7 @@ static PHYSFS_EnumerateCallbackResult add_to_dictionary_path(void *data, const c
if (physfsutil::is_directory(full_path))
{
log_debug << "Adding \"" << full_path << "\" to dictionary search path" << std::endl;
// We want translations from addons to have precedence
// We want translations from add-ons to have precedence.
g_dictionary_manager->add_directory(full_path, true);
}
return PHYSFS_ENUM_OK;
Expand Down Expand Up @@ -163,7 +163,7 @@ AddonManager::AddonManager(const std::string& addon_directory,

add_installed_addons();

// FIXME: We should also restore the order here
// FIXME: We should also restore the order here.
for (auto& addon : m_addon_config)
{
if (addon.enabled)
Expand Down Expand Up @@ -216,7 +216,7 @@ AddonManager::AddonManager(const std::string& addon_directory,

AddonManager::~AddonManager()
{
// sync enabled/disabled add-ons into the config for saving
// Sync enabled/disabled add-ons into the config for saving.
m_addon_config.clear();
for (const auto& [id, addon] : m_installed_addons)
{
Expand Down Expand Up @@ -301,11 +301,11 @@ AddonManager::check_online()
TransferStatusListPtr
AddonManager::request_install_addon(const AddonId& addon_id)
{
// remove addon if it already exists
// Remove add-on if it already exists.
auto it = m_installed_addons.find(addon_id);
if (it != m_installed_addons.end())
{
log_debug << "reinstalling addon " << addon_id << std::endl;
log_debug << "Reinstalling add-on " << addon_id << std::endl;
if (it->second->is_enabled())
{
disable_addon(it->first);
Expand All @@ -314,7 +314,7 @@ AddonManager::request_install_addon(const AddonId& addon_id)
}
else
{
log_debug << "installing addon " << addon_id << std::endl;
log_debug << "Installing add-on " << addon_id << std::endl;
}

auto& addon = get_repository_addon(addon_id);
Expand All @@ -331,7 +331,7 @@ AddonManager::request_install_addon(const AddonId& addon_id)
{
if (success)
{
// complete the addon install
// Complete the add-on installation.
Addon& repository_addon = get_repository_addon(addon_id);

MD5 md5 = md5_from_file(install_filename);
Expand Down Expand Up @@ -403,11 +403,11 @@ AddonManager::request_install_addon_dependencies(const AddonId& addon_id)
void
AddonManager::install_addon(const AddonId& addon_id)
{
{ // remove addon if it already exists
{ // remove addon if it already exists.
auto it = m_installed_addons.find(addon_id);
if (it != m_installed_addons.end())
{
log_debug << "reinstalling addon " << addon_id << std::endl;
log_debug << "Reinstalling add-on " << addon_id << std::endl;
if (it->second->is_enabled())
{
disable_addon(it->first);
Expand All @@ -416,7 +416,7 @@ AddonManager::install_addon(const AddonId& addon_id)
}
else
{
log_debug << "installing addon " << addon_id << std::endl;
log_debug << "Installing add-on " << addon_id << std::endl;
}
}

Expand Down Expand Up @@ -469,13 +469,13 @@ AddonManager::install_addon_from_local_file(const std::string& filename)
void
AddonManager::uninstall_addon(const AddonId& addon_id)
{
log_debug << "uninstalling addon " << addon_id << std::endl;
log_debug << "Uninstalling add-on " << addon_id << std::endl;
auto& addon = get_installed_addon(addon_id);
if (addon.is_enabled())
{
disable_addon(addon_id);
}
log_debug << "deleting file \"" << addon.get_install_filename() << "\"" << std::endl;
log_debug << "Deleting file \"" << addon.get_install_filename() << "\"" << std::endl;
const auto it = m_installed_addons.find(addon.get_id());
if (it != m_installed_addons.end())
{
Expand All @@ -487,7 +487,7 @@ AddonManager::uninstall_addon(const AddonId& addon_id)
}
else
{
throw std::runtime_error(_("Error uninstalling addon: Addon with id ") + addon_id + _(" not found."));
throw std::runtime_error(_("Error uninstalling add-on: Addon with id ") + addon_id + _(" not found."));
}
}

Expand Down Expand Up @@ -733,12 +733,12 @@ AddonManager::scan_for_archives() const
{
std::vector<std::string> archives;

// Search for archives and add them to the search path
// Search for archives and add them to the search path.
physfsutil::enumerate_files(m_addon_directory, [this, &archives](const std::string& filename) {
const std::string fullpath = FileSystem::join(m_addon_directory, filename);
if (physfsutil::is_directory(fullpath))
{
// ignore dot files (e.g. '.git/'), as well as the addon cache directory
// ignore dot files (e.g. '.git/'), as well as the addon cache directory.
if (filename[0] != '.' && fullpath != m_cache_directory) {
archives.push_back(fullpath);
}
Expand All @@ -765,7 +765,7 @@ AddonManager::scan_for_info(const std::string& archive_os_path) const
{
std::string nfo_filename = FileSystem::join("/", file);

// make sure it's in the current archive_os_path
// Make sure it's in the current archive_os_path.
const char* realdir = PHYSFS_getRealDir(nfo_filename.c_str());
if (!realdir)
{
Expand Down Expand Up @@ -826,7 +826,7 @@ AddonManager::add_installed_archive(const std::string& archive, const std::strin
}
catch(...)
{
// save addon title and author on stack before std::move
// Save add-on title and author on stack before std::move.
const std::string addon_title = addon->get_title();
const std::string addon_author = addon->get_author();
m_installed_addons[addon_id] = std::move(addon);
Expand All @@ -842,7 +842,7 @@ AddonManager::add_installed_archive(const std::string& archive, const std::strin
}
Dialog::show_message(fmt::format(_("Add-on {} by {} successfully installed."),
addon_title, addon_author));
// if currently opened menu is addons menu refresh it
// If currently opened menu is add-ons menu refresh it.
AddonMenu* addon_menu = dynamic_cast<AddonMenu*>(MenuManager::instance().current_menu());
if (addon_menu)
addon_menu->refresh();
Expand Down Expand Up @@ -942,7 +942,7 @@ AddonManager::check_for_langpack_updates()
try
{
const std::string& addon_id = "language-pack";
log_debug << "Looking for language addon with ID " << addon_id << "..." << std::endl;
log_debug << "Looking for language add-on with ID " << addon_id << "..." << std::endl;
Addon& langpack = get_repository_addon(addon_id);

try
Expand All @@ -951,7 +951,7 @@ AddonManager::check_for_langpack_updates()
if (installed_langpack.get_md5() == langpack.get_md5() ||
installed_langpack.get_version() > langpack.get_version())
{
log_debug << "Language addon " << addon_id << " is already the latest version." << std::endl;
log_debug << "Language add-on " << addon_id << " is already the latest version." << std::endl;
return;
}

Expand Down Expand Up @@ -982,7 +982,7 @@ AddonManager::check_for_langpack_updates()
}
catch(std::exception&)
{
log_debug << "Language addon for current locale not found." << std::endl;
log_debug << "Language add-on for current locale not found." << std::endl;
}
}
catch(...)
Expand Down
25 changes: 13 additions & 12 deletions src/addon/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

namespace {

// This one is necessary for a download function
// This one is necessary for a download function.
size_t my_curl_string_append(void* ptr, size_t size, size_t nmemb, void* userdata)
{
std::string& s = *static_cast<std::string*>(userdata);
Expand Down Expand Up @@ -296,7 +296,8 @@ class Transfer final
curl_easy_setopt(m_handle, CURLOPT_PROGRESSFUNCTION, &Transfer::on_progress_wrap);
}
#else
// Avoid code injection from funny callers
// Sanitize input to prevent code injection from malicious callers.
// Escape backslashes and single quotes in the URL and file path to ensure safe usage.
auto url_clean = StringUtil::replace_all(StringUtil::replace_all(url, "\\", "\\\\"), "'", "\\'");
auto path_clean = StringUtil::replace_all(StringUtil::replace_all(FileSystem::join(std::string(PHYSFS_getWriteDir()), outfile), "\\", "\\\\"), "'", "\\'");
emscripten_run_script(("supertux_xhr_download(" + std::to_string(m_id) + ", '" + url_clean + "', '" + path_clean + "');").c_str());
Expand Down Expand Up @@ -442,7 +443,7 @@ Downloader::download(const std::string& url,
throw std::runtime_error(url + ": download failed: " + why);
}
#else
log_warning << "Direct download not yet implemented for Emscripten" << std::endl;
log_warning << "Direct download not yet implemented for Emscripten." << std::endl;
// FUTURE MAINTAINERS: If this needs to be implemented, take a look at
// emscripten_wget(), emscripten_async_wget(), emscripten_wget_data() and
// emscripten_async_wget_data():
Expand All @@ -467,7 +468,7 @@ Downloader::download(const std::string& url, const std::string& filename)
PHYSFS_close);
download(url, my_curl_physfs_write, fout.get());
#else
log_warning << "Direct download not yet implemented for Emscripten" << std::endl;
log_warning << "Direct download not yet implemented for Emscripten." << std::endl;
// FUTURE MAINTAINERS: If this needs to be implemented, take a look at
// emscripten_wget(), emscripten_async_wget(), emscripten_wget_data() and
// emscripten_async_wget_data():
Expand Down Expand Up @@ -514,15 +515,15 @@ Downloader::update()
if (m_last_update_time == g_real_time) return;
m_last_update_time = g_real_time;

// read data from the network
// Read data from the network.
CURLMcode ret;
int running_handles;
while ((ret = curl_multi_perform(m_multi_handle, &running_handles)) == CURLM_CALL_MULTI_PERFORM)
{
log_debug << "updating" << std::endl;
}

// check if any downloads got finished
// Check if any downloads got finished.
int msgs_in_queue;
CURLMsg* msg;
while ((msg = curl_multi_info_read(m_multi_handle, &msgs_in_queue)))
Expand Down Expand Up @@ -584,7 +585,7 @@ Downloader::update()
break;

default:
log_warning << "unhandled cURL message: " << msg->msg << std::endl;
log_warning << "Unhandled cURL message: " << msg->msg << std::endl;
break;
}
}
Expand All @@ -594,7 +595,7 @@ Downloader::update()
TransferStatusPtr
Downloader::request_download(const std::string& url, const std::string& outfile)
{
log_info << "request_download: " << url << std::endl;
log_info << "Requesting download for: " << url << std::endl;
auto transfer = std::make_unique<Transfer>(*this, m_next_transfer_id++, url, outfile);
#ifndef EMSCRIPTEN
curl_multi_add_handle(m_multi_handle, transfer->get_curl_handle());
Expand All @@ -611,7 +612,7 @@ Downloader::onDownloadProgress(int id, int loaded, int total)
auto it = m_transfers.find(id);
if (it == m_transfers.end())
{
log_warning << "transfer not found: " << id << std::endl;
log_warning << "Transfer not found: " << id << std::endl;
}
else
{
Expand All @@ -625,7 +626,7 @@ Downloader::onDownloadFinished(int id)
auto it = m_transfers.find(id);
if (it == m_transfers.end())
{
log_warning << "transfer not found: " << id << std::endl;
log_warning << "Transfer not found: " << id << std::endl;
}
else
{
Expand All @@ -649,7 +650,7 @@ Downloader::onDownloadError(int id)
auto it = m_transfers.find(id);
if (it == m_transfers.end())
{
log_warning << "transfer not found: " << id << std::endl;
log_warning << "Transfer not found: " << id << std::endl;
}
else
{
Expand All @@ -673,7 +674,7 @@ Downloader::onDownloadAborted(int id)
auto it = m_transfers.find(id);
if (it == m_transfers.end())
{
log_warning << "transfer not found: " << id << std::endl;
log_warning << "Transfer not found: " << id << std::endl;
}
else
{
Expand Down
Loading

0 comments on commit 5f5d018

Please sign in to comment.