Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions templates/xbox/src/HostContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class HostContext {
// (Windows は %LOCALAPPDATA%\Next2D。既定が無い OS ではメモリ上にだけ保持する)。
std::string storage_dir;

// 保存先のファイルへ書き込んだ直後に呼ばれる (埋め込み側が、書いた内容を確定する
// 必要のある保存先を使う場合のための通知)。name は保存したストレージの名前。不要なら nullptr。
void (*storage_saved)(const char* name, void* user) = nullptr;
void* storage_saved_user = nullptr;

static HostContext* From(v8::Isolate* isolate)
{
return static_cast<HostContext*>(isolate->GetData(kHostContextSlot));
Expand Down
12 changes: 10 additions & 2 deletions templates/xbox/src/bindings/DomShims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,18 @@ void StorageSave(const v8::FunctionCallbackInfo<v8::Value>& args)
MemoryStorage()[name] = data;
return;
}
std::ofstream ofs(path, std::ios::binary | std::ios::trunc);
if (ofs) {
{
std::ofstream ofs(path, std::ios::binary | std::ios::trunc);
if (!ofs) {
return;
}
ofs.write(data.data(), static_cast<std::streamsize>(data.size()));
}
// ファイルを閉じてから、埋め込み側へ知らせる
HostContext* host = HostContext::From(isolate);
if (host && host->storage_saved) {
host->storage_saved(name.c_str(), host->storage_saved_user);
}
}

// new OffscreenCanvas(width, height)
Expand Down
2 changes: 2 additions & 0 deletions templates/xbox/src/core/HostCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ Next2DHost* next2d_host_create(const Next2DHostConfig* config)
if (config->storage_dir) {
h->host.storage_dir = config->storage_dir;
}
h->host.storage_saved = config->storage_saved;
h->host.storage_saved_user = config->user;
h->gles = std::make_unique<CallbackGlesContext>(*config);
h->host.gles = h->gles.get();

Expand Down
7 changes: 6 additions & 1 deletion templates/xbox/src/core/next2d_host_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
extern "C" {
#endif

#define NEXT2D_HOST_CORE_API_VERSION 2u
#define NEXT2D_HOST_CORE_API_VERSION 3u

typedef struct Next2DHost Next2DHost;

Expand Down Expand Up @@ -70,6 +70,11 @@ typedef struct Next2DHostConfig {
/* localStorage / indexedDB の保存先ディレクトリ。UTF-8。NULL なら OS の既定
* (既定の保存先が無い OS では保存されず、終了すると消える)。 */
const char* storage_dir;

/* storage_dir のファイルへ書き込んだ直後に呼ばれる。書いた内容を確定する操作が必要な
* 保存先を使う場合に、その合図として使う。name は保存したストレージの名前
* (例 "localStorage")。next2d_host_frame を呼んだスレッドから呼ばれる。不要なら NULL。 */
void (*storage_saved)(const char* name, void* user);
} Next2DHostConfig;

/* ポインタイベントの種類。 */
Expand Down
Loading