Skip to content

Commit

Permalink
put filesystem.cpp changes behind #define
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Jan 6, 2024
1 parent 884d527 commit 0c066ad
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@
# include "platform_win.h"
#endif

#if defined(EMSCRIPTEN)
#include <emscripten.h>

void setFsNeedsSync()
{
EM_ASM(window.idb_needs_sync = true;);
}
#else
void setFsNeedsSync()
{
}
#endif

bool assure_dir_exist( const std::string &path )
{
return assure_dir_exist( fs::u8path( path ) );
Expand All @@ -33,7 +44,7 @@ bool assure_dir_exist( const cata_path &path )

bool assure_dir_exist( const fs::path &path )
{
EM_ASM(window.idb_needs_sync = true;);
setFsNeedsSync();
std::error_code ec;
bool exists{false};
bool created{false};
Expand Down Expand Up @@ -104,7 +115,7 @@ bool remove_file( const std::string &path )

bool remove_file( const fs::path &path )
{
EM_ASM(window.idb_needs_sync = true;);
setFsNeedsSync();
std::error_code ec;
return fs::remove( path, ec );
}
Expand All @@ -116,7 +127,7 @@ bool rename_file( const std::string &old_path, const std::string &new_path )

bool rename_file( const fs::path &old_path, const fs::path &new_path )
{
EM_ASM(window.idb_needs_sync = true;);
setFsNeedsSync();
std::error_code ec;
fs::rename( old_path, new_path, ec );
return !ec;
Expand All @@ -140,7 +151,7 @@ bool remove_directory( const std::string &path )
bool remove_directory( const fs::path &path )
{
std::error_code ec;
EM_ASM(window.idb_needs_sync = true;);
setFsNeedsSync();
return fs::remove( path, ec );
}

Expand Down

0 comments on commit 0c066ad

Please sign in to comment.