pcbjam/wasm/kiplatform/io.cpp
Istvan Matejcsok cdaa96250d fix(wasm): KiCad 10 kiplatform/libgit2 stubs, e2e fixtures, asyncify -g hook
- wasm/kiplatform: add EnableDarkMode, IO::TimestampDir, UI::AllowNetworkFileSystems,
  UI::CancelPendingScroll, SECRETS::DeleteSecret (new KiCad 10 functions).
- wasm/stubs/libgit2_stub.c: ~156 no-op stubs for KiCad 10's restructured git
  backend + git-backed local history + text_eval VCS.
- tests/kicad: bump the demo project dir 9.99 -> 10.0 (KiCad 10 stores projects
  under /home/kicad/documents/kicad/10.0/) — fixes load-pcb + 3d-viewer e2e.
- scripts/common/apply-asyncify.sh: ASYNCIFY_EXTRA_OPTS hook (e.g. -g for
  symbolizable wasm traces).
- kicad submodule -> ef00c2d3 (KiCad 10 link + runtime adaptations).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 10:30:25 +02:00

84 lines
2.1 KiB
C++

/*
* WASM implementation of kiplatform/io.h
* Provides file I/O functions for WASM virtual filesystem
*/
#include <kiplatform/io.h>
#include <wx/string.h>
#include <wx/filename.h>
#include <wx/dir.h>
#include <stdio.h>
#include <sys/stat.h>
namespace KIPLATFORM
{
namespace IO
{
FILE* SeqFOpen( const wxString& aPath, const wxString& mode )
{
// WASM doesn't have special sequential read hints
// Just use standard fopen
return fopen( aPath.utf8_str(), mode.utf8_str() );
}
bool DuplicatePermissions( const wxString& aSrc, const wxString& aDest )
{
// WASM virtual filesystem doesn't have detailed permissions
return true;
}
bool MakeWriteable( const wxString& aFilePath )
{
// All files in WASM virtual filesystem are writeable
return true;
}
bool IsFileHidden( const wxString& aFileName )
{
// Check for Unix-style hidden files (starting with .)
wxFileName fn( aFileName );
wxString name = fn.GetFullName();
return !name.IsEmpty() && name[0] == '.';
}
void LongPathAdjustment( wxFileName& aFilename )
{
// No-op on non-Windows platforms
}
long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
{
// Mirror the native implementations: accumulate (mtime, size) over files
// matching the spec so callers can detect library-directory changes. The
// Emscripten virtual filesystem supports stat(), so this works for MEMFS-
// backed local libraries (git/network libraries are handled JS-side).
long long timestamp = 0;
wxDir dir( aDirPath );
if( !dir.IsOpened() )
return timestamp;
wxString filename;
bool cont = dir.GetFirst( &filename, aFilespec, wxDIR_FILES );
while( cont )
{
wxString fullPath = aDirPath + wxFILE_SEP_PATH + filename;
struct stat entryStat;
if( stat( fullPath.fn_str(), &entryStat ) == 0 )
{
timestamp += static_cast<long long>( entryStat.st_mtime ) * 1000;
timestamp += entryStat.st_size;
}
cont = dir.GetNext( &filename );
}
return timestamp;
}
} // namespace IO
} // namespace KIPLATFORM