Skip to content

Storage

Francisco Dias edited this page Dec 17, 2024 · 2 revisions

Storage

This is a module for managing cloud storage files.

Functions

This module offers a collection of functions designed to address specific tasks and provide utilities for various purposes. Explore the available functions to make the most of the functionalities provided by this module.



Back To Top

GOG_Storage_DownloadSharedFile

This function downloads a previously shared file. This is an asynchronous function that will trigger a Social Async Event when the task is finished.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.


Syntax:

GOG_Storage_DownloadSharedFile(sharedFileID)
Argument Type Description
sharedFileID Int64 The ID of the shared file.



Returns:

N/A


Triggers:

Social Async Event

Key Type Description
type String "GOG_Storage_DownloadSharedFile"
error String The error message; only if request failed ✴️ OPTIONAL
sharedFileID String The ID of the shared file.
fileName String Name of the shared file

Example:

GOG_Storage_DownloadSharedFile(sharedFileID);

The code sample above starts a task to download a shared file. The results can be caught inside a Social Async Event event.

if (async_load[? "type"] == "GOG_Storage_DownloadSharedFile")
{
    if (ds_map_exists(async_load, "error"))
    {
        show_debug_message(async_load[?"error"]);
        exit;
    }

    var _sharedFileID = async_load[?"sharedFileID"];
    var _fileName = async_load[?"fileName"];

    show_debug_message("DownloadSharedFile SUCCESS");
}

This code sample provides an example of handling the returned callback data.




Back To Top

GOG_Storage_FileDelete

This function deletes the given file.

Warning

REQUIREMENT The name that specifies the file has to be provided in the form of a relative path that uses slashes as separators. Every part of the path must not refer to any special or restricted name on any of the supported platforms. Backslashes are not allowed.


Syntax:

GOG_Storage_FileDelete(fileName)
Argument Type Description
fileName String The name of the file in the form of a path



Returns:

N/A


Example:

GOG_Storage_FileDelete(fileName);

The code above provides a simple usage example.




Back To Top

GOG_Storage_FileExists

This function returns if the given file exists.

Warning

REQUIREMENT The name that specifies the file has to be provided in the form of a relative path that uses slashes as separators. Every part of the path must not refer to any special or restricted name on any of the supported platforms. Backslashes are not allowed.


Syntax:

GOG_Storage_FileExists(fileName)
Argument Type Description
fileName String The name of the file in the form of a path



Returns:

Boolean


Example:

if(GOG_Storage_FileExists(fileName))
{
   //File exists, do something
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_FileRead

This function reads file content into the buffer.

Warning

REQUIREMENT The name that specifies the file has to be provided in the form of a relative path that uses slashes as separators. Every part of the path must not refer to any special or restricted name on any of the supported platforms. Backslashes are not allowed.

Warning

This function creates a new buffer everytime it is called, unless a buffer is already specified. You need to ensure you correctly delete the buffer when you don't need it anymore using the buffer_delete function. Failing to do so will result in memory leaks.


Syntax:

GOG_Storage_FileRead(fileName, bufferID=undefined, byteOffset=undefined)
Argument Type Description
fileName String The name of the file in the form of a path
bufferID Buffer OPTIONAL: use an existing buffer instead of allocating a new one
byteOffset Real OPTIONAL: write data to a specific offset in the buffer



Returns:

Buffer


Example:

var _buffer = GOG_Storage_FileRead(fileName);

The code above provides a simple usage example.




Back To Top

GOG_Storage_FileShare

This function uploads the file for sharing. This is an asynchronous function that will trigger a Social Async Event when the task is finished.

Warning

REQUIREMENT The name that specifies the file has to be provided in the form of a relative path that uses slashes as separators. Every part of the path must not refer to any special or restricted name on any of the supported platforms. Backslashes are not allowed.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.


Syntax:

GOG_Storage_FileShare(fileName)
Argument Type Description
fileName String The name of the file in the form of a path



Returns:

N/A


Triggers:

Social Async Event

Key Type Description
type String "GOG_Storage_FileShare"
error String The error message; only if request failed ✴️ OPTIONAL
sharedFileID String The ID of the shared file.
fileName String Name of the shared file

Example:

GOG_Storage_FileShare(fileName);

The code sample above starts a task for sharing a file, which results can be caught inside a Social Async Event event.

if (async_load[? "type"] == "GOG_Storage_FileShare")
{
    if (ds_map_exists(async_load, "error"))
    {
        show_debug_message(async_load[?"error"]);
        exit;
    }

    var _sharedFileID = async_load[?"sharedFileID"];
    var _fileName = async_load[?"fileName"];

    show_debug_message("FileShare SUCCESS");
}

This code sample provides an example of handling the returned callback data.




Back To Top

GOG_Storage_FileWrite

This function writes data into the file.

Warning

REQUIREMENT The name that specifies the file has to be provided in the form of a relative path that uses slashes as separators. Every part of the path must not refer to any special or restricted name on any of the supported platforms. Backslashes are not allowed.

Note

The files created using this method will be stored in GOG Galaxy internal directory and should be accessed only via Galaxy SDK methods.


Syntax:

GOG_Storage_FileWrite(fileName, buffer)
Argument Type Description
fileName String Name of the file
buffer Buffer Buffer with data



Returns:

N/A


Example:

GOG_Storage_FileWrite(fileName, buffer);

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetDownloadedSharedFileByIndex

This function returns the ID of the open downloaded shared file.


Syntax:

GOG_Storage_GetDownloadedSharedFileByIndex(index)
Argument Type Description
index Real Index as an integer in the range of [0, number of open downloaded shared files].



Returns:

Real


Example:

for(var i = 0 ; i < GetDownloadedSharedFileCount() ; i++)
{
   var _sharedFileID= GOG_Storage_GetDownloadedSharedFileByIndex(i);
   var _fileName = GOG_Storage_GetSharedFileName(_sharedFileID);
   var _fileSize = GOG_Storage_GetSharedFileSize(_sharedFileID);
   var _owner = GOG_Storage_GetSharedFileOwner(_sharedFileID);
   var _buffer = GOG_Storage_SharedFileRead(_sharedFileID);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetDownloadedSharedFileCount

This function returns the number of open downloaded shared files.


Syntax:

GOG_Storage_GetDownloadedSharedFileCount()



Returns:

Real


Example:

for(var i = 0 ; i < GetDownloadedSharedFileCount() ; i++)
{
   var _sharedFileID = GOG_Storage_GetDownloadedSharedFileByIndex(i);
   var _fileName = GOG_Storage_GetSharedFileName(_sharedFileID);
   var _fileSize = GOG_Storage_GetSharedFileSize(_sharedFileID);
   var _owner = GOG_Storage_GetSharedFileOwner(_sharedFileID);
   var _buffer = GOG_Storage_SharedFileRead(_sharedFileID);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetFileCount

This function returns the number of files in the storage.


Syntax:

GOG_Storage_GetFileCount()



Returns:

Real


Example:

for(i = 0 ; i < GOG_Storage_GetFileCount() ; i++)
{
   var _filename = GOG_Storage_GetFileNameByIndex(i);
   var _fileSize = GOG_Storage_GetFileSize(_filename);
   var _fileTimestamp = GOG_Storage_GetFileTimestamp(_filename);
   var _fileSize = GOG_Storage_GetSharedFileSize(_filename);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetFileNameByIndex

This function returns the name of the file.


Syntax:

GOG_Storage_GetFileNameByIndex(index)
Argument Type Description
index Real The index as an integer in the range of [0, number of files].



Returns:

String


Example:

for(i = 0 ; i < GOG_Storage_GetFileCount() ; i++)
{
   var _filename = GOG_Storage_GetFileNameByIndex(i);
   var _fileSize = GOG_Storage_GetFileSize(__filename);
   var _fileTimestamp = GOG_Storage_GetFileTimestamp(_filename);
   var _fileSize = GOG_Storage_GetSharedFileSize(_filename);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetFileSize

This function returns the size of the file.

Warning

REQUIREMENT The name that specifies the file has to be provided in the form of a relative path that uses slashes as separators. Every part of the path must not refer to any special or restricted name on any of the supported platforms. Backslashes are not allowed.


Syntax:

GOG_Storage_GetFileSize(filename)
Argument Type Description
filename String The name of the file in the form of a path.



Returns:

Real


Example:

for(i = 0 ; i < GOG_Storage_GetFileCount() ; i++)
{
   var _filename = GOG_Storage_GetFileNameByIndex(i);
   var _fileSize = GOG_Storage_GetFileSize(_filename);
   var _fileTimestamp = GOG_Storage_GetFileTimestamp(_filename);
   var _fileSize = GOG_Storage_GetSharedFileSize(_filename);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetFileTimestamp

This function returns the timestamp of the last file modification.

Warning

REQUIREMENT The name that specifies the file has to be provided in the form of a relative path that uses slashes as separators. Every part of the path must not refer to any special or restricted name on any of the supported platforms. Backslashes are not allowed.


Syntax:

GOG_Storage_GetFileTimestamp(filename)
Argument Type Description
filename String The name of the file in the form of a path.



Returns:

Real


Example:

for(i = 0 ; i < GOG_Storage_GetFileCount() ; i++)
{
   var _filename = GOG_Storage_GetFileNameByIndex(i);
   var _fileSize = GOG_Storage_GetFileSize(_filename);
   var _fileTimestamp = GOG_Storage_GetFileTimestamp(_filename);
   var _fileSize = GOG_Storage_GetSharedFileSize(_filename);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetSharedFileName

This function gets the name of a downloaded shared file.


Syntax:

GOG_Storage_GetSharedFileName(sharedFileID)
Argument Type Description
sharedFileID Int64 The ID of the shared file.



Returns:

String


Example:

for(var i = 0 ; i < GetDownloadedSharedFileCount() ; i++)
{
   var _sharedFileID = GOG_Storage_GetDownloadedSharedFileByIndex(i);
   var _fileName = GOG_Storage_GetSharedFileName(_sharedFileID);
   var _fileSize = GOG_Storage_GetSharedFileSize(_sharedFileID);
   var _owner = GOG_Storage_GetSharedFileOwner(_sharedFileID);
   var _buffer = GOG_Storage_SharedFileRead(_sharedFileID);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetSharedFileOwner

This function gets the owner GalaxyID of a downloaded shared file.


Syntax:

GOG_Storage_GetSharedFileOwner(sharedFileID)
Argument Type Description
sharedFileID Int64 The ID of the shared file.



Returns:

GalaxyID


Example:

for(var i = 0 ; i < GetDownloadedSharedFileCount() ; i++)
{
   var _sharedFileID = GOG_Storage_GetDownloadedSharedFileByIndex(i);
   var _fileName = GOG_Storage_GetSharedFileName(sharedFileID);
   var _fileSize = GOG_Storage_GetSharedFileSize(sharedFileID);
   var _owner = GOG_Storage_GetSharedFileOwner(sharedFileID);
   var _buffer = GOG_Storage_SharedFileRead(sharedFileID);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_GetSharedFileSize

This function gets the size of a downloaded shared file.


Syntax:

GOG_Storage_GetSharedFileSize(sharedFileID)
Argument Type Description
sharedFileID Int64 The ID of the shared file.



Returns:

Real


Example:

for(var i = 0 ; i < GetDownloadedSharedFileCount() ; i++)
{
   var _sharedFileID = GOG_Storage_GetDownloadedSharedFileByIndex(i);
   var _fileName = GOG_Storage_GetSharedFileName(_sharedFileID);
   var _fileSize = GOG_Storage_GetSharedFileSize(_sharedFileID);
   var _owner = GOG_Storage_GetSharedFileOwner(_sharedFileID);
   var _buffer = GOG_Storage_SharedFileRead(_sharedFileID);
}

The code above provides a simple usage example.




Back To Top

GOG_Storage_SharedFileClose

This function closes the given downloaded shared file and frees the memory.


Syntax:

GOG_Storage_SharedFileClose(sharedFileID)
Argument Type Description
sharedFileID Int64 The ID of the shared file.



Returns:

N/A


Example:

GOG_Storage_SharedFileClose(sharedFileID);

The code above provides a simple usage example.




Back To Top

GOG_Storage_SharedFileRead

This function reads the given downloaded shared file's contents into the buffer.

Warning

This function creates a new buffer everytime it is called, unless a buffer is already specified. You need to ensure you correctly delete the buffer when you don't need it anymore using the buffer_delete function. Failing to do so will result in memory leaks.


Syntax:

GOG_Storage_SharedFileRead(sharedFileID, bufferID=undefined, byteOffset=undefined)
Argument Type Description
sharedFileID Int64 The ID of the shared file.
bufferID Buffer OPTIONAL: use an existing buffer instead of allocating a new one
byteOffset Real OPTIONAL: write data to a specific offset in the buffer



Returns:

Buffer


Example:

for(var i = 0 ; i < GetDownloadedSharedFileCount() ; i++)
{
   var _sharedFileID = GOG_Storage_GetDownloadedSharedFileByIndex(i);
   var _fileName = GOG_Storage_GetSharedFileName(_sharedFileID);
   var _fileSize = GOG_Storage_GetSharedFileSize(_sharedFileID);
   var _owner = GOG_Storage_GetSharedFileOwner(_sharedFileID);
   var _buffer = GOG_Storage_SharedFileRead(_sharedFileID);
}

The code above provides a simple usage example.