Skip to content

Commit

Permalink
Added NCINE_BUILD_FLATPAK, fixed FileSystem, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Dec 27, 2023
1 parent e84ac28 commit 8b993f6
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 55 deletions.
470 changes: 464 additions & 6 deletions Sources/Shared/Containers/StringUtils.cpp

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion Sources/Shared/Containers/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,25 @@ namespace Death { namespace Containers { namespace StringUtils {
String uppercase(String string);

/**
@brief Determines whether two strings have the same value, ignoring case (ASCII characters only)
@brief Convert characters in a UTF-8 string to lowercase with slower Unicode-aware method
Allocates a copy and replaces most of the Latin, Greek, Cyrillic, Armenian, Georgian, Cherokee,
Glagolitic, Coptic, Deseret, Osage, Old Hungarian, Warang Citi, Medefaidrin and Adlam characters.
Doesn't support locale-specific replacements.
*/
String lowercaseUnicode(const StringView string);

/**
@brief Convert characters in a UTF-8 string to uppercase with slower Unicode-aware method
Allocates a copy and replaces most of the Latin, Greek, Cyrillic, Armenian, Georgian, Cherokee,
Glagolitic, Coptic, Deseret, Osage, Old Hungarian, Warang Citi, Medefaidrin and Adlam characters.
Doesn't support locale-specific replacements.
*/
String uppercaseUnicode(const StringView string);

/**
@brief Determine whether two strings have the same value, ignoring case (ASCII characters only)
*/
inline bool equalsIgnoreCase(const StringView string1, const StringView string2) {
std::size_t size1 = string1.size();
Expand Down Expand Up @@ -139,4 +157,5 @@ namespace Death { namespace Containers { namespace StringUtils {
@brief Replace all occurrences of a character in a string with another character in-place
*/
void replaceAllInPlace(const MutableStringView string, char search, char replace);

}}}
12 changes: 6 additions & 6 deletions Sources/Shared/Containers/StringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,21 +979,21 @@ namespace Death { namespace Containers {
}

StringView StringViewConverter<const char, std::string>::from(const std::string& other) {
return StringView { other.data(), other.size(), StringViewFlags::NullTerminated };
return StringView{other.data(), other.size(), StringViewFlags::NullTerminated};
}

std::string StringViewConverter<const char, std::string>::to(StringView other) {
return std::string { other.data(), other.size() };
return std::string{other.data(), other.size()};
}

MutableStringView StringViewConverter<char, std::string>::from(std::string& other) {
// .data() returns a const pointer until C++17, so have to use &other[0]. It's guaranteed to return a pointer
// to a single null character if the string is empty.
return MutableStringView { &other[0], other.size(), StringViewFlags::NullTerminated };
// .data() returns a const pointer until C++17, so have to use &other[0]. It's guaranteed
// to return a pointer to a single null character if the string is empty.
return MutableStringView{&other[0], other.size(), StringViewFlags::NullTerminated};
}

std::string StringViewConverter<char, std::string>::to(MutableStringView other) {
return std::string { other.data(), other.size() };
return std::string{other.data(), other.size()};
}
}
}}
67 changes: 33 additions & 34 deletions Sources/Shared/IO/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,6 @@ namespace Death { namespace IO {
# endif
}
#else
static bool CallStat(const char* path, struct stat& sb)
{
return (::lstat(path, &sb) != -1);
}

static FileSystem::Permission NativeModeToEnum(std::uint32_t nativeMode)
{
FileSystem::Permission mode = FileSystem::Permission::None;
Expand Down Expand Up @@ -290,7 +285,7 @@ namespace Death { namespace IO {

String fileName = FileSystem::CombinePath(path, p->d_name);
struct stat sb;
if (CallStat(fileName.data(), sb)) {
if (::lstat(fileName.data(), &sb) == 0) { // Don't follow symbolic links
if (S_ISDIR(sb.st_mode)) {
DeleteDirectoryInternal(fileName);
} else {
Expand All @@ -306,6 +301,7 @@ namespace Death { namespace IO {
}
return (r == 0);
# else
// Don't follow symbolic links
return ::nftw(String::nullTerminatedView(path).data(), DeleteDirectoryInternalCallback, 64, FTW_DEPTH | FTW_PHYS) == 0;
# endif
}
Expand Down Expand Up @@ -947,9 +943,9 @@ namespace Death { namespace IO {
result[resultLength] = '\0';

struct stat sb;
if (!CallStat(result, sb)) {
if (::lstat(result, &sb) != 0) {
if (errno == ENOENT && p == nullptr) {
return String { result, resultLength };
return String{result, resultLength};
}
return { };
}
Expand Down Expand Up @@ -1165,8 +1161,8 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
return (sb.st_mode & S_IFMT) == S_IFDIR;
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
return ((sb.st_mode & S_IFMT) == S_IFDIR);
}
return false;
#endif
Expand All @@ -1190,8 +1186,8 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
return (sb.st_mode & S_IFMT) == S_IFREG;
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
return ((sb.st_mode & S_IFMT) == S_IFREG);
}
return false;
#endif
Expand All @@ -1215,7 +1211,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
return CallStat(nullTerminatedPath.data(), sb);
return (::lstat(nullTerminatedPath.data(), &sb) == 0);
#endif
}

Expand All @@ -1237,8 +1233,8 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
return (sb.st_mode & S_IRUSR);
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
return ((sb.st_mode & S_IRUSR) != 0);
}
return false;
#endif
Expand All @@ -1262,8 +1258,8 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
return (sb.st_mode & S_IWUSR);
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
return ((sb.st_mode & S_IWUSR) != 0);
}
return false;
#endif
Expand Down Expand Up @@ -1317,8 +1313,8 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
return (sb.st_mode & S_IFMT) == S_IFREG && (sb.st_mode & S_IRUSR);
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
return ((sb.st_mode & S_IFMT) == S_IFREG && (sb.st_mode & S_IRUSR) != 0);
}
#endif
return false;
Expand All @@ -1342,8 +1338,8 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
return (sb.st_mode & S_IFMT) == S_IFREG && (sb.st_mode & S_IWUSR);
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
return ((sb.st_mode & S_IFMT) == S_IFREG && (sb.st_mode & S_IWUSR) != 0);
}
#endif
return false;
Expand Down Expand Up @@ -1371,7 +1367,7 @@ namespace Death { namespace IO {
strncpy(buffer, path.data(), pathLength);
buffer[pathLength] = '\0';
const char* baseName = ::basename(buffer);
return (baseName && baseName[0] == '.');
return (baseName != nullptr && baseName[0] == '.');
#endif
}

Expand Down Expand Up @@ -1543,7 +1539,7 @@ namespace Death { namespace IO {
if (fullPath[i] == '/' || fullPath[i] == '\\') {
if (i > 0) {
fullPath[i] = '\0';
if (!CallStat(fullPath.data(), sb)) {
if (::lstat(fullPath.data(), &sb) != 0) {
if (::mkdir(fullPath.data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0 && errno != EEXIST) {
LOGW("Cannot create directory \"%s\"", fullPath.data());
return false;
Expand Down Expand Up @@ -1724,7 +1720,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (!CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) != 0) {
return -1;
}
return static_cast<std::int64_t>(sb.st_size);
Expand All @@ -1748,8 +1744,9 @@ namespace Death { namespace IO {
}
::CloseHandle(hFile);
#elif defined(DEATH_TARGET_APPLE) && defined(_DARWIN_FEATURE_64_BIT_INODE)
auto nullTerminatedPath = String::nullTerminatedView(path);
struct stat sb;
if (CallStat(String::nullTerminatedView(path).data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
date = DateTime(sb.st_birthtimespec.tv_sec);
date.SetMillisecond(sb.st_birthtimespec.tv_nsec / 1000000);
}
Expand All @@ -1761,7 +1758,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
// Creation time is not available on Linux, return the last change of inode instead
date = DateTime(sb.st_ctime);
}
Expand All @@ -1786,8 +1783,9 @@ namespace Death { namespace IO {
}
::CloseHandle(hFile);
#elif defined(DEATH_TARGET_APPLE) && defined(_DARWIN_FEATURE_64_BIT_INODE)
auto nullTerminatedPath = String::nullTerminatedView(path);
struct stat sb;
if (CallStat(String::nullTerminatedView(path).data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
date = DateTime(sb.st_mtimespec.tv_sec);
date.SetMillisecond(sb.st_mtimespec.tv_nsec / 1000000);
}
Expand All @@ -1799,7 +1797,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
date = DateTime(sb.st_mtime);
}
#endif
Expand All @@ -1823,8 +1821,9 @@ namespace Death { namespace IO {
}
::CloseHandle(hFile);
#elif defined(DEATH_TARGET_APPLE) && defined(_DARWIN_FEATURE_64_BIT_INODE)
auto nullTerminatedPath = String::nullTerminatedView(path);
struct stat sb;
if (CallStat(String::nullTerminatedView(path).data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
date = DateTime(sb.st_atimespec.tv_sec);
date.SetMillisecond(sb.st_atimespec.tv_nsec / 1000000);
}
Expand All @@ -1836,7 +1835,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) == 0) {
date = DateTime(sb.st_atime);
}
#endif
Expand Down Expand Up @@ -1869,7 +1868,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (!CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) != 0) {
return Permission::None;
}
return NativeModeToEnum(sb.st_mode);
Expand Down Expand Up @@ -1903,7 +1902,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (!CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) != 0) {
return false;
}
const std::uint32_t currentMode = sb.st_mode;
Expand Down Expand Up @@ -1935,7 +1934,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (!CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) != 0) {
return false;
}
const std::uint32_t currentMode = sb.st_mode;
Expand Down Expand Up @@ -1967,7 +1966,7 @@ namespace Death { namespace IO {
}
# endif
struct stat sb;
if (!CallStat(nullTerminatedPath.data(), sb)) {
if (::stat(nullTerminatedPath.data(), &sb) != 0) {
return false;
}
const std::uint32_t currentMode = sb.st_mode;
Expand Down
2 changes: 1 addition & 1 deletion Sources/project.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Name=@NCINE_APP_NAME@
Comment=@NCINE_APP_DESCRIPTION@
TryExec=@CPACK_EXECUTABLE_NAME@
Exec=@CPACK_EXECUTABLE_NAME@
Icon=@CPACK_EXECUTABLE_NAME@
Icon=@PACKAGE_NAME@
StartupWMClass=@CPACK_PACKAGE_STARTUPWMCLASS@
Terminal=false
Type=Application
Expand Down
80 changes: 80 additions & 0 deletions Sources/project.metainfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>tk.deat.Jazz2Resurrection</id>
<name>Jazz² Resurrection</name>
<summary>A re-implementation of Jazz Jackrabbit 2</summary>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0-only</project_license>
<developer id="deat.tk">
<name>Daniel Rajf</name>
<url>https://deat.tk</url>
</developer>
<supports>
<control>pointing</control>
<control>keyboard</control>
<control>touch</control>
<control>gamepad</control>
</supports>
<description>
<p>
Jazz² Resurrection is re-implementation of the game Jazz Jackrabbit 2 released in 1998. It supports various versions of the game, specifically:
</p>
<ul>
<li>The shareware demo.</li>
<li><em>Holiday Hare &apos;98</em>.</li>
<li><em>The Secret Files</em> (recommended).</li>
<li><em>Christmas Chronicles</em>.</li>
</ul>
<p>
Also, it partially supports some features of the JJ2+ extension and MLLE.
</p>
</description>

<categories>
<category>Game</category>
<category>ActionGame</category>
<category>ArcadeGame</category>
</categories>

<launchable type="desktop-id">tk.deat.Jazz2Resurrection.desktop</launchable>

<url type="homepage">https://deat.tk/jazz2/</url>
<url type="bugtracker">https://github.com/deathkiller/jazz2-native/issues</url>
<url type="faq">https://deat.tk/jazz2/help</url>

<provides>
<binary>jazz2</binary>
</provides>

<releases>
<release version="2.4.0" date="2023-12-09"/>
<release version="2.3.0" date="2023-11-26"/>
<release version="2.2.2" date="2023-11-11"/>
<release version="2.2.1" date="2023-11-08"/>
<release version="2.2.0" date="2023-11-05"/>
<release version="2.1.0" date="2023-08-23"/>
<release version="2.0.0" date="2023-07-13"/>
<release version="1.9.1" date="2023-05-12"/>
<release version="1.9.0" date="2023-05-12"/>
<release version="1.8.0" date="2023-04-12"/>
<release version="1.7.0" date="2023-02-19"/>
<release version="1.6.1" date="2023-01-24"/>
<release version="1.6.0" date="2023-01-20"/>
<release version="1.5.0" date="2023-01-14"/>
<release version="1.4.0" date="2022-12-15"/>
<release version="1.3.0" date="2022-12-06"/>
<release version="1.2.0" date="2022-11-21"/>
<release version="1.1.0" date="2022-11-05"/>
<release version="1.0.0" date="2022-10-08"/>
</releases>

<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">moderate</content_attribute>
<content_attribute id="violence-fantasy">moderate</content_attribute>
<content_attribute id="violence-bloodshed">mild</content_attribute>
<content_attribute id="sex-themes">mild</content_attribute>
<content_attribute id="language-profanity">mild</content_attribute>
<content_attribute id="language-humor">mild</content_attribute>
</content_rating>

</component>
Loading

0 comments on commit 8b993f6

Please sign in to comment.