Symbian^3 port

This commit is contained in:
Shinovon 2026-04-29 05:15:13 +05:00
parent 77cdaaf97e
commit 3eb71f2cc5
106 changed files with 2098 additions and 745 deletions

View file

@ -26,35 +26,19 @@ void GetLocalTime_CP(SYSTEMTIME *out) {
// Compatible with Linux/POSIX and MinGW on Windows
#ifndef _WIN32
HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) {
char pathCopy[MAX_PATH];
strcpy(pathCopy, pathname);
char newpathname[64];
snprintf(newpathname, sizeof(newpathname), "E:/data/gta3/%s", pathname);
char* path = strtok(newpathname, "\\*");
strncpy(firstfile->folder, path, sizeof(firstfile->folder));
char *folder = strtok(pathCopy, "*");
char *extension = strtok(NULL, "*");
// because I remember like strtok might not return NULL for last delimiter
if (extension && extension - folder == strlen(pathname))
extension = nil;
// Case-sensitivity and backslashes...
// Will be freed at the bottom
char *realFolder = casepath(folder);
if (realFolder) {
folder = realFolder;
}
strncpy(firstfile->folder, folder, sizeof(firstfile->folder));
if (extension)
strncpy(firstfile->extension, extension, sizeof(firstfile->extension));
// Both w/ extension and w/o extension is ok
if (strlen(path) + 2 != strlen(pathname))
strncpy(firstfile->extension, strtok(NULL, "\\*"), sizeof(firstfile->extension));
else
firstfile->extension[0] = '\0';
if (realFolder)
free(realFolder);
strncpy(firstfile->extension, "", sizeof(firstfile->extension));
HANDLE d;
if ((d = (HANDLE)opendir(firstfile->folder)) == NULL || !FindNextFile(d, firstfile))
if ((d = (HANDLE)opendir(path)) == NULL || !FindNextFile(d, firstfile))
return NULL;
return d;
@ -67,12 +51,11 @@ bool FindNextFile(HANDLE d, WIN32_FIND_DATA* finddata) {
int extensionLen = strlen(finddata->extension);
while ((file = readdir((DIR*)d)) != NULL) {
// We only want "DT_REG"ular Files, but reportedly some FS and OSes gives DT_UNKNOWN as type.
if ((file->d_type == DT_UNKNOWN || file->d_type == DT_REG || file->d_type == DT_LNK) &&
(extensionLen == 0 || strncasecmp(&file->d_name[strlen(file->d_name) - extensionLen], finddata->extension, extensionLen) == 0)) {
if ((extensionLen == 0 || strncmp(&file->d_name[strlen(file->d_name) - extensionLen], finddata->extension, extensionLen) == 0)) {
sprintf(relativepath, "%s/%s", finddata->folder, file->d_name);
realpath(relativepath, path);
// realpath(relativepath, path);
strcpy(path, relativepath);
stat(path, &fileStats);
strncpy(finddata->cFileName, file->d_name, sizeof(finddata->cFileName));
finddata->ftLastWriteTime = fileStats.st_mtime;
@ -182,115 +165,26 @@ int _caserename(const char *old_filename, const char *new_filename)
// Returned string should freed manually (if exists)
char* casepath(char const* path, bool checkPathFirst)
{
if (checkPathFirst && access(path, F_OK) != -1) {
// File path is correct
return nil;
}
size_t l = strlen(path);
char data_path[512];
getcwd(data_path, sizeof(data_path));
char* out = (char*)malloc(l + strlen(data_path) + 2);
size_t l = strlen(path);
char* p = (char*)alloca(l + 1);
char* out = (char*)malloc(l + 3); // for extra ./
strcpy(p, path);
if (strncmp(path, "E:", 2) == 0 || strncmp(path, "F:", 2) == 0) {
strcpy(out, path);
} else {
sprintf(out, "%s/%s", data_path, path);
}
// my addon: linux doesn't handle filenames with spaces at the end nicely
p = trim(p);
l = strlen(out);
for (int i = l-1; i >= 0; i--) {
if (out[i] == '\\' || out[i] == '/' || out[i] == ' ')
out[i] = '\0';
else
break;
}
size_t rl = 0;
DIR* d;
char* c;
#if defined(__SWITCH__) || defined(PSP2)
if( (c = strstr(p, ":/")) != NULL) // scheme used by some environments, eg. switch, vita
{
size_t deviceNameOffset = c - p + 3;
char* deviceNamePath = (char*)alloca(deviceNameOffset + 1);
strlcpy(deviceNamePath, p, deviceNameOffset);
deviceNamePath[deviceNameOffset] = 0;
d = opendir(deviceNamePath);
p = c + 1;
}
else
#endif
if (p[0] == '/' || p[0] == '\\')
{
d = opendir("/");
}
else
{
d = opendir(".");
out[0] = '.';
out[1] = 0;
rl = 1;
}
bool cantProceed = false; // just convert slashes in what's left in string, don't correct case of letters(because we can't)
bool mayBeTrailingSlash = false;
while (c = strsep(&p, "/\\"))
{
// May be trailing slash(allow), slash at the start(avoid), or multiple slashes(avoid)
if (*c == '\0')
{
mayBeTrailingSlash = true;
continue;
} else {
mayBeTrailingSlash = false;
}
out[rl] = '/';
rl += 1;
out[rl] = 0;
if (cantProceed)
{
strcpy(out + rl, c);
rl += strlen(c);
continue;
}
struct dirent* e;
while (e = readdir(d))
{
if (strcasecmp(c, e->d_name) == 0)
{
strcpy(out + rl, e->d_name);
int reportedLen = (int)strlen(e->d_name);
rl += reportedLen;
assert(reportedLen == strlen(c) && "casepath: This is not good at all");
closedir(d);
d = opendir(out);
// Either it wasn't a folder, or permission error, I/O error etc.
if (!d) {
cantProceed = true;
}
break;
}
}
if (!e)
{
printf("casepath couldn't find dir/file \"%s\", full path was %s\n", c, path);
// No match, add original name and continue converting further slashes.
strcpy(out + rl, c);
rl += strlen(c);
cantProceed = true;
}
}
if (d) closedir(d);
if (mayBeTrailingSlash) {
out[rl] = '/'; rl += 1;
out[rl] = '\0';
}
if (rl > l + 2) {
printf("\n\ncasepath: Corrected path length is longer then original+2:\n\tOriginal: %s (%zu chars)\n\tCorrected: %s (%zu chars)\n\n", path, l, out, rl);
}
return out;
return out;
}
#endif