Files
a293e22ca0 Add Javadoc comments to all Ship directory headers (#1077)
* Add Javadoc comments to CoreAudioAudioPlayer.h and SoundMatrixDecoder.h

Add documentation comments to all undocumented classes, structs, methods,
and important member variables in:
- CoreAudioAudioPlayer.h: class, constructor, Buffered, DoInit, DoClose,
  DoPlay, CoreAudioRenderCallback, and ring buffer member variables
- SoundMatrixDecoder.h: BiquadCascade, FilterCoefficients, AllPassChain,
  CircularDelay structs, and DesignLowPass, DesignHighPass, ProcessFilter,
  PrepareAllPass, ProcessAllPass, ProcessDelay, Saturate methods

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* Add Javadoc-style comments to controller mapping header files

Add /** ... */ documentation with @brief, @param, and @return tags to all
classes, structs, enums, constructors, and public/protected methods in:

- ControllerMapping.h
- ControllerInputMapping.h
- ControllerAxisDirectionMapping.h
- ControllerButtonMapping.h
- ControllerGyroMapping.h
- ControllerRumbleMapping.h
- ControllerLEDMapping.h
- ControllerDefaultMappings.h

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* Add Javadoc comments to keyboard, mouse, SDL, and factory mapping headers

Add /** ... */ documentation with @brief, @param, and @return tags to all
classes, structs, enums, constructors, and public/protected methods across
26 controller mapping header files. Existing Javadoc comments (e.g. in
KeyboardScancodes.h) are left untouched.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* Add Javadoc-style comments to physical device, control device, resource, and factory headers

Add /** ... */ documentation with @brief, @param, @return tags to all
classes, structs, enums, public/protected methods, and constructors in:

- ConnectedPhysicalDeviceManager.h
- GlobalSDLDeviceSettings.h
- PhysicalDeviceType.h
- SDLAddRemoveDeviceEventHandler.h
- ResourceFactoryBinary.h
- ResourceFactoryXML.h
- Blob.h, Json.h, Shader.h
- BlobFactory.h, JsonFactory.h, ShaderFactory.h
- FolderArchive.h

Files that were already fully documented (ControlDevice.h, ResourceFactory.h,
ResourceType.h, File.h) are left unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* docs: add Javadoc-style comments to utility header files

Add /** ... */ documentation with @brief, @param, and @return tags to:
- Directory.h, DiskFile.h, FileHelper.h, Path.h, PathHelper.h
- glob.h, macUtils.h, stox.h

Files already documented (color.h, StrHash64.h, endianness.h) are left unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* Add Javadoc-style comments to window, GUI, and resource headers

Add /** ... */ documentation with @brief, @param, and @return tags to:
- FileDropMgr.h: class, typedef, and all public methods
- MouseStateManager.h: class and all public/protected methods
- EventDebuggerWindow.h: class and lifecycle overrides
- Fonts.h: file-level documentation for embedded font data
- IconsFontAwesome4.h: file-level documentation for icon constants
- StatsWindow.h: destructor (class and methods already documented)
- Font.h: class, resource type macro, public methods, and data members
- FontFactory.h: class and ReadResource method
- GuiTexture.h: struct, class, resource type macro, methods, and members
- GuiTextureFactory.h: class and ReadResource method

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* Add Javadoc-style comments to public headers

Add /** ... */ documentation comments with @brief, @param, and @return
tags to all classes, structs, enums, free functions, macros, and public
methods in the following header files:

- include/ship/Api.h
- include/ship/events/CoreEvents.h
- include/ship/port/mobile/MobileImpl.h
- include/ship/scripting/LibraryLoader.h
- include/ship/security/Keystore.h

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* docs: add missing Javadoc comments to Controller.h and InputEditorWindow.h

Add Javadoc-style comments to all undocumented methods:

- Controller.h: Add doc for ~Controller() destructor
- InputEditorWindow.h: Add docs for ~InputEditorWindow() destructor and
  all 24 private methods (Draw*, Update*, GetButtonColors*, OffsetMappingPopup)

FileHelper.h and DiskFile.h already have complete Javadoc coverage from
prior commits on this branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* style: apply clang-format-14 to fix formatting violations

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* fix: rename WheelDirections x/y to X/Y per CamelCase naming convention

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* docs: address review comments - fix inaccurate Doxygen comments in DiskFile, Shader, LibraryLoader, stox, Path, PathHelper

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* fix: auto-enable DISABLE_SCRIPTING for iOS to fix build-ios CI failure

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/e409640e-005b-4dce-a9cd-db23e80d5385

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* Flip tcc scripting to opt-in (#1084)

* Flip tcc scripting to opt-in

Per #1074

* Adhere to lgpl
Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* docs: update README dependency list with tree structure and correct links (#1088)

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/dae72d20-385d-41c2-bba9-9229493d9e17

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* fix: remove stale DISABLE_SCRIPTING iOS override (superseded by ENABLE_SCRIPTING opt-in from #1084)

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/e409640e-005b-4dce-a9cd-db23e80d5385

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* no changes yet

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/62cd9f10-ed50-45ab-b3fb-19f689b83025

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* fix: WriteAllBytes always creates parent dirs; GetFileNameExtension throws explicitly; fix Shader/MobileImpl docs; fix clang-tidy CI

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/62cd9f10-ed50-45ab-b3fb-19f689b83025

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* fix: revert MobileImpl.h to origin/main — removes it from PR diff, fixing clang-tidy CI

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/05a2642f-75da-4384-a7c5-4cc249a03f51

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* refactor: move library file writing from ScriptLoader into LibraryLoader; fix Init/Unload docstrings

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/8e68fb32-b97d-4c50-b75d-7268d54c7448

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* fix: add missing <cstdint> include to LibraryLoader.h for uint8_t

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/e9c0cf04-6e25-4714-9132-3556d3d93da0

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>
Co-authored-by: Jeod <47716344+JeodC@users.noreply.github.com>
2026-04-29 06:49:11 -04:00

154 lines
5.2 KiB
C++

#pragma once
#include <cstdio>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "PathHelper.h"
#include "Directory.h"
namespace Ship {
/**
* @brief Utility class providing static helpers for reading and writing files on disk.
*
* Similar to DiskFile but lives inside the Ship namespace. All methods are static
* and operate directly on filesystem paths.
*/
class FileHelper {
public:
/**
* @brief Checks whether a file exists and is readable.
* @param filePath Path to the file to check.
* @return true if the file can be opened for reading, false otherwise.
*/
static bool Exists(const fs::path& filePath) {
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
return file.good();
}
/**
* @brief Reads the entire contents of a file into a byte vector.
* @param filePath Path to the file to read.
* @return Vector containing every byte of the file, or an empty vector if the file cannot be opened.
*/
static std::vector<uint8_t> ReadAllBytes(const fs::path& filePath) {
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
if (!file) {
return std::vector<uint8_t>();
}
int32_t fileSize = (int32_t)file.tellg();
file.seekg(0);
char* data = nullptr;
std::vector<uint8_t> result;
try {
data = new char[fileSize];
file.read(data, fileSize);
result = std::vector<uint8_t>(data, data + fileSize);
} catch (const std::exception& e) {
delete[] data;
throw e;
}
delete[] data;
return result;
};
/**
* @brief Reads the entire contents of a file as a text string.
* @param filePath Path to the file to read.
* @return String containing the full file contents.
*/
static std::string ReadAllText(const fs::path& filePath) {
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
int32_t fileSize = (int32_t)file.tellg();
file.seekg(0);
char* data = nullptr;
std::string str;
try {
data = new char[fileSize + 1];
memset(data, 0, fileSize + 1);
file.read(data, fileSize);
str = std::string((const char*)data);
} catch (const std::exception& e) {
delete[] data;
throw e;
}
delete[] data;
return str;
};
/**
* @brief Reads a file and splits it into lines.
* @param filePath Path to the file to read.
* @return Vector of strings, one per line.
*/
static std::vector<std::string> ReadAllLines(const fs::path& filePath) {
std::string text = ReadAllText(filePath);
std::vector<std::string> lines = StringHelper::Split(text, "\n");
return lines;
};
/**
* @brief Writes a byte vector to a file, overwriting any existing content.
* @note Creates parent directories if they do not already exist.
* @param filePath Path to the file to write.
* @param data Bytes to write.
*/
static void WriteAllBytes(const fs::path& filePath, const std::vector<uint8_t>& data) {
if (!Directory::Exists(PathHelper::GetDirectoryName(filePath))) {
Directory::MakeDirectory(PathHelper::GetDirectoryName(filePath).string());
}
std::ofstream file(filePath, std::ios::binary);
file.write((char*)data.data(), data.size());
};
/**
* @brief Writes a char vector to a file, overwriting any existing content.
* @note Creates parent directories if they do not already exist.
* @param filePath Path to the file to write.
* @param data Characters to write.
*/
static void WriteAllBytes(const std::string& filePath, const std::vector<char>& data) {
if (!Directory::Exists(PathHelper::GetDirectoryName(filePath))) {
Directory::MakeDirectory(PathHelper::GetDirectoryName(filePath).string());
}
std::ofstream file(filePath, std::ios::binary);
file.write((char*)data.data(), data.size());
};
/**
* @brief Writes raw data to a file from a pointer and size, overwriting any existing content.
* @note Creates parent directories if they do not already exist.
* @param filePath Path to the file to write.
* @param data Pointer to the data to write.
* @param dataSize Number of bytes to write.
*/
static void WriteAllBytes(const std::string& filePath, const char* data, int dataSize) {
if (!Directory::Exists(PathHelper::GetDirectoryName(filePath))) {
Directory::MakeDirectory(PathHelper::GetDirectoryName(filePath).string());
}
std::ofstream file(filePath, std::ios::binary);
file.write((char*)data, dataSize);
};
/**
* @brief Writes a string to a file as text, overwriting any existing content.
* @param filePath Path to the file to write.
* @param text String to write.
*/
static void WriteAllText(const fs::path& filePath, const std::string& text) {
std::ofstream file(filePath, std::ios::out | std::ios::binary);
file.write(text.c_str(), text.size());
}
};
} // namespace Ship