Port 2V0 UI Python bindings and app module link surface

This commit is contained in:
shen
2026-09-22 19:57:35 -07:00
parent a0ad587f78
commit b221a9eaf5
74 changed files with 18320 additions and 9 deletions
+67
View File
@@ -4,10 +4,14 @@
#include <cctype>
#include <chrono>
#include <cstdio>
#include <cstring>
#include <mutex>
#include <new>
#include <string>
#include <thread>
#include <vector>
#include <glob.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -44,6 +48,69 @@ int _access(const char* path, int mode)
return access(path, m);
}
namespace
{
struct FindState
{
std::vector<std::string> paths;
size_t next = 0;
};
void fill_find_data(const std::string& path, WIN32_FIND_DATA* data)
{
const size_t slash = path.find_last_of('/');
const std::string name = path.substr(slash == std::string::npos ? 0 : slash + 1);
std::snprintf(data->cFileName, sizeof(data->cFileName), "%s", name.c_str());
}
}
HANDLE FindFirstFile(const char* pattern, WIN32_FIND_DATA* data)
{
if (!pattern || !data)
return INVALID_HANDLE_VALUE;
std::string normalized(pattern);
for (char& ch : normalized)
if (ch == '\\') ch = '/';
glob_t matches{};
const int result = glob(normalized.c_str(), 0, nullptr, &matches);
if (result != 0 || matches.gl_pathc == 0)
{
globfree(&matches);
return INVALID_HANDLE_VALUE;
}
auto* state = new FindState;
for (size_t i = 0; i < matches.gl_pathc; ++i)
state->paths.emplace_back(matches.gl_pathv[i]);
globfree(&matches);
fill_find_data(state->paths[0], data);
state->next = 1;
return state;
}
BOOL FindNextFile(HANDLE handle, WIN32_FIND_DATA* data)
{
if (handle == INVALID_HANDLE_VALUE || !handle || !data)
return FALSE;
auto* state = static_cast<FindState*>(handle);
if (state->next >= state->paths.size())
return FALSE;
fill_find_data(state->paths[state->next++], data);
return TRUE;
}
BOOL FindClose(HANDLE handle)
{
if (handle == INVALID_HANDLE_VALUE || !handle)
return FALSE;
delete static_cast<FindState*>(handle);
return TRUE;
}
void Sleep(DWORD milliseconds)
{
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}
char* _strlwr(char* s)
{
for (char* p = s; *p; ++p)