mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-07 10:21:31 +00:00
EMSCRIPTEN: Add support for saving logfiles
This commit is contained in:
parent
45c5f4673a
commit
bc73ee4b71
@ -44,6 +44,25 @@ EM_JS(void, toggleFullscreen, (bool enable), {
|
||||
}
|
||||
});
|
||||
|
||||
EM_JS(void, downloadFile, (const char *filenamePtr, char *dataPtr, int dataSize), {
|
||||
const view = new Uint8Array(Module.HEAPU8.buffer, dataPtr, dataSize);
|
||||
const blob = new Blob([view], {
|
||||
type:
|
||||
'octet/stream'
|
||||
});
|
||||
const filename = UTF8ToString(filenamePtr);
|
||||
setTimeout(() => {
|
||||
const a = document.createElement('a');
|
||||
a.style = 'display:none';
|
||||
document.body.appendChild(a);
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
// Overridden functions
|
||||
bool OSystem_Emscripten::hasFeature(Feature f) {
|
||||
@ -70,8 +89,37 @@ void OSystem_Emscripten::setFeatureState(Feature f, bool enable) {
|
||||
}
|
||||
}
|
||||
|
||||
Common::Path OSystem_Emscripten::getDefaultLogFileName() {
|
||||
return Common::Path("/tmp/scummvm.log");
|
||||
}
|
||||
|
||||
Common::Path OSystem_Emscripten::getDefaultConfigFileName() {
|
||||
return Common::Path(Common::String::format("%s/scummvm.ini", getenv("HOME")));
|
||||
}
|
||||
|
||||
bool OSystem_Emscripten::displayLogFile() {
|
||||
if (_logFilePath.empty())
|
||||
return false;
|
||||
|
||||
exportFile(_logFilePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void OSystem_Emscripten::exportFile(const Common::Path &filename) {
|
||||
Common::File file;
|
||||
Common::FSNode node(filename);
|
||||
file.open(node);
|
||||
if (!file.isOpen()) {
|
||||
warning("Could not open file %s!", filename.toString(Common::Path::kNativeSeparator).c_str());
|
||||
return;
|
||||
}
|
||||
Common::String exportName = filename.getLastComponent().toString(Common::Path::kNativeSeparator);
|
||||
const int32 size = file.size();
|
||||
char *bytes = new char[size + 1];
|
||||
file.read(bytes, size);
|
||||
file.close();
|
||||
downloadFile(exportName.c_str(), bytes, size);
|
||||
delete[] bytes;
|
||||
}
|
||||
#endif
|
||||
|
@ -29,9 +29,12 @@ public:
|
||||
bool hasFeature(Feature f) override;
|
||||
void setFeatureState(Feature f, bool enable) override;
|
||||
bool getFeatureState(Feature f) override;
|
||||
bool displayLogFile() override;
|
||||
void exportFile(const Common::Path &filename);
|
||||
|
||||
protected:
|
||||
Common::Path getDefaultConfigFileName() override;
|
||||
Common::Path getDefaultLogFileName() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user