Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
|
|
const { app, ipcMain } = require("electron");
|
|
|
|
const zlib = require("zlib");
|
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs/promises");
|
|
|
|
const { promisify } = require("util");
|
|
|
|
const gzip = promisify(zlib.gzip);
|
|
|
|
const gunzip = promisify(zlib.gunzip);
|
|
|
|
|
|
|
|
const greenworks = require("./greenworks");
|
|
|
|
const log = require("electron-log");
|
|
|
|
const flatten = require("lodash/flatten");
|
|
|
|
const Config = require("electron-config");
|
|
|
|
const config = new Config();
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/69418940
|
|
|
|
const dirSize = async (directory) => {
|
|
|
|
const files = await fs.readdir(directory);
|
2022-04-07 01:30:08 +02:00
|
|
|
const stats = files.map((file) => fs.stat(path.join(directory, file)));
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
return (await Promise.all(stats)).reduce((accumulator, { size }) => accumulator + size, 0);
|
2022-04-07 01:30:08 +02:00
|
|
|
};
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
|
|
|
|
const getDirFileStats = async (directory) => {
|
|
|
|
const files = await fs.readdir(directory);
|
|
|
|
const stats = files.map((f) => {
|
|
|
|
const file = path.join(directory, f);
|
|
|
|
return fs.stat(file).then((stat) => ({ file, stat }));
|
|
|
|
});
|
2022-04-07 01:30:08 +02:00
|
|
|
const data = await Promise.all(stats);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getNewestFile = async (directory) => {
|
2022-04-07 01:30:08 +02:00
|
|
|
const data = await getDirFileStats(directory);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
return data.sort((a, b) => b.stat.mtime.getTime() - a.stat.mtime.getTime())[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
const getAllSaves = async (window) => {
|
|
|
|
const rootDirectory = await getSaveFolder(window, true);
|
2022-04-07 01:30:08 +02:00
|
|
|
const data = await fs.readdir(rootDirectory, { withFileTypes: true });
|
|
|
|
const savesPromises = data
|
|
|
|
.filter((e) => e.isDirectory())
|
|
|
|
.map((dir) => path.join(rootDirectory, dir.name))
|
|
|
|
.map((dir) => getDirFileStats(dir));
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
const saves = await Promise.all(savesPromises);
|
|
|
|
const flat = flatten(saves);
|
|
|
|
return flat;
|
2022-04-07 01:30:08 +02:00
|
|
|
};
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
|
|
|
|
async function prepareSaveFolders(window) {
|
|
|
|
const rootFolder = await getSaveFolder(window, true);
|
|
|
|
const currentFolder = await getSaveFolder(window);
|
2022-04-07 01:30:08 +02:00
|
|
|
const backupsFolder = path.join(rootFolder, "/_backups");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
await prepareFolders(rootFolder, currentFolder, backupsFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function prepareFolders(...folders) {
|
|
|
|
for (const folder of folders) {
|
|
|
|
try {
|
|
|
|
// Making sure the folder exists
|
|
|
|
await fs.stat(folder);
|
|
|
|
} catch (error) {
|
2022-04-07 01:30:08 +02:00
|
|
|
if (error.code === "ENOENT") {
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
log.warn(`'${folder}' not found, creating it...`);
|
|
|
|
await fs.mkdir(folder);
|
|
|
|
} else {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getFolderSizeInBytes(saveFolder) {
|
|
|
|
try {
|
|
|
|
return await dirSize(saveFolder);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAutosaveConfig(value) {
|
|
|
|
config.set("autosave-enabled", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAutosaveEnabled() {
|
|
|
|
return config.get("autosave-enabled", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSaveCompressionConfig(value) {
|
|
|
|
config.set("save-compression-enabled", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSaveCompressionEnabled() {
|
|
|
|
return config.get("save-compression-enabled", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCloudEnabledConfig(value) {
|
|
|
|
config.set("cloud-enabled", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getSaveFolder(window, root = false) {
|
|
|
|
if (root) return path.join(app.getPath("userData"), "/saves");
|
|
|
|
const identifier = window.gameInfo?.player?.identifier ?? "";
|
|
|
|
return path.join(app.getPath("userData"), "/saves", `/${identifier}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isCloudEnabled() {
|
|
|
|
// If the Steam API could not be initialized on game start, we'll abort this.
|
|
|
|
if (global.greenworksError) return false;
|
|
|
|
|
|
|
|
// If the user disables it in Steam there's nothing we can do
|
|
|
|
if (!greenworks.isCloudEnabledForUser()) return false;
|
|
|
|
|
|
|
|
// Let's check the config file to see if it's been overriden
|
|
|
|
const enabledInConf = config.get("cloud-enabled", true);
|
|
|
|
if (!enabledInConf) return false;
|
|
|
|
|
|
|
|
const isAppEnabled = greenworks.isCloudEnabled();
|
|
|
|
if (!isAppEnabled) greenworks.enableCloud(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveCloudFile(name, content) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
greenworks.saveTextToFile(name, content, resolve, reject);
|
2022-04-07 01:30:08 +02:00
|
|
|
});
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFirstCloudFile() {
|
|
|
|
const nbFiles = greenworks.getFileCount();
|
2022-04-07 01:30:08 +02:00
|
|
|
if (nbFiles === 0) throw new Error("No files in cloud");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
const file = greenworks.getFileNameAndSize(0);
|
2022-04-07 01:30:08 +02:00
|
|
|
log.silly(`Found ${nbFiles} files.`);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
log.silly(`First File: ${file.name} (${file.size} bytes)`);
|
|
|
|
return file.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCloudFile() {
|
|
|
|
const file = getFirstCloudFile();
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
greenworks.readTextFromFile(file, resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteCloudFile() {
|
|
|
|
const file = getFirstCloudFile();
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
greenworks.deleteFile(file, resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getSteamCloudQuota() {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-04-07 01:30:08 +02:00
|
|
|
greenworks.getCloudQuota(resolve, reject);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function backupSteamDataToDisk(currentPlayerId) {
|
|
|
|
const nbFiles = greenworks.getFileCount();
|
|
|
|
if (nbFiles === 0) return;
|
|
|
|
|
|
|
|
const file = greenworks.getFileNameAndSize(0);
|
|
|
|
const previousPlayerId = file.name.replace(".json.gz", "");
|
|
|
|
if (previousPlayerId !== currentPlayerId) {
|
|
|
|
const backupSave = await getSteamCloudSaveString();
|
|
|
|
const backupFile = path.join(app.getPath("userData"), "/saves/_backups", `${previousPlayerId}.json.gz`);
|
2022-04-07 01:30:08 +02:00
|
|
|
const buffer = Buffer.from(backupSave, "base64").toString("utf8");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
saveContent = await gzip(buffer);
|
2022-04-07 01:30:08 +02:00
|
|
|
await fs.writeFile(backupFile, saveContent, "utf8");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
log.debug(`Saved backup game to '${backupFile}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function pushGameSaveToSteamCloud(base64save, currentPlayerId) {
|
|
|
|
if (!isCloudEnabled) return Promise.reject("Steam Cloud is not Enabled");
|
|
|
|
|
|
|
|
try {
|
|
|
|
backupSteamDataToDisk(currentPlayerId);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
const steamSaveName = `${currentPlayerId}.json.gz`;
|
|
|
|
|
|
|
|
// Let's decode the base64 string so GZIP is more efficient.
|
|
|
|
const buffer = Buffer.from(base64save, "base64");
|
|
|
|
const compressedBuffer = await gzip(buffer);
|
|
|
|
// We can't use utf8 for some reason, steamworks is unhappy.
|
|
|
|
const content = compressedBuffer.toString("base64");
|
|
|
|
log.debug(`Uncompressed: ${base64save.length} bytes`);
|
|
|
|
log.debug(`Compressed: ${content.length} bytes`);
|
|
|
|
log.debug(`Saving to Steam Cloud as ${steamSaveName}`);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await saveCloudFile(steamSaveName, content);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getSteamCloudSaveString() {
|
|
|
|
if (!isCloudEnabled()) return Promise.reject("Steam Cloud is not Enabled");
|
|
|
|
log.debug(`Fetching Save in Steam Cloud`);
|
|
|
|
const cloudString = await getCloudFile();
|
|
|
|
const gzippedBase64Buffer = Buffer.from(cloudString, "base64");
|
|
|
|
const uncompressedBuffer = await gunzip(gzippedBase64Buffer);
|
|
|
|
const content = uncompressedBuffer.toString("base64");
|
|
|
|
log.debug(`Compressed: ${cloudString.length} bytes`);
|
|
|
|
log.debug(`Uncompressed: ${content.length} bytes`);
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveGameToDisk(window, saveData) {
|
|
|
|
const currentFolder = await getSaveFolder(window);
|
|
|
|
let saveFolderSizeBytes = await getFolderSizeInBytes(currentFolder);
|
|
|
|
const maxFolderSizeBytes = config.get("autosave-quota", 1e8); // 100Mb per playerIndentifier
|
|
|
|
const remainingSpaceBytes = maxFolderSizeBytes - saveFolderSizeBytes;
|
|
|
|
log.debug(`Folder Usage: ${saveFolderSizeBytes} bytes`);
|
|
|
|
log.debug(`Folder Capacity: ${maxFolderSizeBytes} bytes`);
|
2022-04-07 01:30:08 +02:00
|
|
|
log.debug(
|
|
|
|
`Remaining: ${remainingSpaceBytes} bytes (${((saveFolderSizeBytes / maxFolderSizeBytes) * 100).toFixed(2)}% used)`,
|
|
|
|
);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
const shouldCompress = isSaveCompressionEnabled();
|
|
|
|
const fileName = saveData.fileName;
|
|
|
|
const file = path.join(currentFolder, fileName + (shouldCompress ? ".gz" : ""));
|
|
|
|
try {
|
|
|
|
let saveContent = saveData.save;
|
|
|
|
if (shouldCompress) {
|
|
|
|
// Let's decode the base64 string so GZIP is more efficient.
|
2022-04-07 01:30:08 +02:00
|
|
|
const buffer = Buffer.from(saveContent, "base64").toString("utf8");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
saveContent = await gzip(buffer);
|
|
|
|
}
|
2022-04-07 01:30:08 +02:00
|
|
|
await fs.writeFile(file, saveContent, "utf8");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
log.debug(`Saved Game to '${file}'`);
|
|
|
|
log.debug(`Save Size: ${saveContent.length} bytes`);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileStats = await getDirFileStats(currentFolder);
|
|
|
|
const oldestFiles = fileStats
|
|
|
|
.sort((a, b) => a.stat.mtime.getTime() - b.stat.mtime.getTime())
|
2022-04-07 01:30:08 +02:00
|
|
|
.map((f) => f.file)
|
|
|
|
.filter((f) => f !== file);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
|
|
|
|
while (saveFolderSizeBytes > maxFolderSizeBytes && oldestFiles.length > 0) {
|
|
|
|
const fileToRemove = oldestFiles.shift();
|
|
|
|
log.debug(`Over Quota -> Removing "${fileToRemove}"`);
|
|
|
|
try {
|
|
|
|
await fs.unlink(fileToRemove);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveFolderSizeBytes = await getFolderSizeInBytes(currentFolder);
|
|
|
|
log.debug(`Save Folder: ${saveFolderSizeBytes} bytes`);
|
2022-04-07 01:30:08 +02:00
|
|
|
log.debug(
|
|
|
|
`Remaining: ${maxFolderSizeBytes - saveFolderSizeBytes} bytes (${(
|
|
|
|
(saveFolderSizeBytes / maxFolderSizeBytes) *
|
|
|
|
100
|
|
|
|
).toFixed(2)}% used)`,
|
|
|
|
);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadLastFromDisk(window) {
|
|
|
|
const folder = await getSaveFolder(window);
|
|
|
|
const last = await getNewestFile(folder);
|
|
|
|
log.debug(`Last modified file: "${last.file}" (${last.stat.mtime.toLocaleString()})`);
|
|
|
|
return loadFileFromDisk(last.file);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadFileFromDisk(path) {
|
|
|
|
const buffer = await fs.readFile(path);
|
|
|
|
let content;
|
2022-04-07 01:30:08 +02:00
|
|
|
if (path.endsWith(".gz")) {
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
const uncompressedBuffer = await gunzip(buffer);
|
2022-04-07 01:30:08 +02:00
|
|
|
content = uncompressedBuffer.toString("base64");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
log.debug(`Uncompressed file content (new size: ${content.length} bytes)`);
|
|
|
|
} else {
|
2022-04-07 01:30:08 +02:00
|
|
|
content = buffer.toString("utf8");
|
|
|
|
log.debug(`Loaded file with ${content.length} bytes`);
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSaveInformation(window, save) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
ipcMain.once("get-save-info-response", async (event, data) => {
|
|
|
|
resolve(data);
|
|
|
|
});
|
|
|
|
window.webContents.send("get-save-info-request", save);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentSave(window) {
|
|
|
|
return new Promise((resolve) => {
|
2022-04-07 01:30:08 +02:00
|
|
|
ipcMain.once("get-save-data-response", (event, data) => {
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
resolve(data);
|
|
|
|
});
|
2022-04-07 01:30:08 +02:00
|
|
|
window.webContents.send("get-save-data-request");
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function pushSaveGameForImport(window, save, automatic) {
|
|
|
|
ipcMain.once("push-import-result", async (event, arg) => {
|
|
|
|
log.debug(`Was save imported? ${arg.wasImported ? "Yes" : "No"}`);
|
|
|
|
});
|
|
|
|
window.webContents.send("push-save-request", { save, automatic });
|
|
|
|
}
|
|
|
|
|
|
|
|
async function restoreIfNewerExists(window) {
|
|
|
|
const currentSave = await getCurrentSave(window);
|
|
|
|
const currentData = await getSaveInformation(window, currentSave.save);
|
|
|
|
const steam = {};
|
|
|
|
const disk = {};
|
|
|
|
|
|
|
|
try {
|
|
|
|
steam.save = await getSteamCloudSaveString();
|
|
|
|
steam.data = await getSaveInformation(window, steam.save);
|
|
|
|
} catch (error) {
|
|
|
|
log.error("Could not retrieve steam file");
|
|
|
|
log.debug(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-04-07 01:30:08 +02:00
|
|
|
const saves = (await getAllSaves()).sort((a, b) => b.stat.mtime.getTime() - a.stat.mtime.getTime());
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
if (saves.length > 0) {
|
|
|
|
disk.save = await loadFileFromDisk(saves[0].file);
|
|
|
|
disk.data = await getSaveInformation(window, disk.save);
|
|
|
|
}
|
2022-04-07 01:30:08 +02:00
|
|
|
} catch (error) {
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
log.error("Could not retrieve disk file");
|
|
|
|
log.debug(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
const lowPlaytime = 1000 * 60 * 15;
|
|
|
|
let bestMatch;
|
|
|
|
if (!steam.data && !disk.data) {
|
|
|
|
log.info("No data to import");
|
2022-03-11 16:32:48 +01:00
|
|
|
} else if (!steam.data) {
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
// We'll just compare using the lastSave field for now.
|
2022-04-07 01:30:08 +02:00
|
|
|
log.debug("Best potential save match: Disk");
|
2022-03-11 16:32:48 +01:00
|
|
|
bestMatch = disk;
|
|
|
|
} else if (!disk.data) {
|
2022-04-07 01:30:08 +02:00
|
|
|
log.debug("Best potential save match: Steam Cloud");
|
2022-03-11 16:32:48 +01:00
|
|
|
bestMatch = steam;
|
2022-04-07 01:30:08 +02:00
|
|
|
} else if (steam.data.lastSave >= disk.data.lastSave || steam.data.playtime + lowPlaytime > disk.data.playtime) {
|
2022-03-11 16:32:48 +01:00
|
|
|
// We want to prioritze steam data if the playtime is very close
|
2022-04-07 01:30:08 +02:00
|
|
|
log.debug("Best potential save match: Steam Cloud");
|
2022-03-11 16:32:48 +01:00
|
|
|
bestMatch = steam;
|
|
|
|
} else {
|
2022-04-07 01:30:08 +02:00
|
|
|
log.debug("Best potential save match: disk");
|
2022-03-11 16:32:48 +01:00
|
|
|
bestMatch = disk;
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
}
|
|
|
|
if (bestMatch) {
|
|
|
|
if (bestMatch.data.lastSave > currentData.lastSave + 5000) {
|
|
|
|
// We add a few seconds to the currentSave's lastSave to prioritize it
|
|
|
|
log.info("Found newer data than the current's save file");
|
|
|
|
log.silly(bestMatch.data);
|
|
|
|
await pushSaveGameForImport(window, bestMatch.save, true);
|
|
|
|
return true;
|
2022-04-07 01:30:08 +02:00
|
|
|
} else if (bestMatch.data.playtime > currentData.playtime && currentData.playtime < lowPlaytime) {
|
Add support for Steam Cloud & local filesystem
Adds actions to save the game's data directly in the filesystem and/or
into Steam Cloud. Them game will push an event with the save data
whenever the game is saved. Electron will use that data to persist it
into the User Data folder, until the folder reaches a certain size.
Once over the quota, it's going to remove previous saves.
Files are grouped according the the player's identifier, ensuring
backups off different playthroughs if importing.
Optionally, the file will be gzipped before saving to disk, largely
reducing file size.
Adds a way to save & load from Steam Cloud, currently manually only.
When loading a save, it'll trigger the new "Import Data Comparison" page
to accept or cancel the import.
When saving the game, it will save to Steam Cloud & to filesystem if the
options are enabled.
Add automatic game restore
Detects when the player has access to a newer game that has been saved
more recently than the one being loaded. It checks both in the Steam
Cloud and on the local filesystem. Adds an option to disable the
feature.
- Adds a "Save Game" menu item that triggers the game's save.
- Adds a "Export Game" menu item that triggers the download file popup.
- Adds a "Export Scripts" menu item that triggers the "download *"
terminal command.
- Adds a "Load Last Save" menu item that loads the latest file modified
in the user data folder.
- Adds a "Load from Steam Cloud" menu item.
- Adds a "Load From File" menu item that popups a file selector & loads
the file.
- Adds settings for "Saves Compression (.gz)", "Auto-save Backups" &
"Auto-save to Steam", toggleable through the menu.
- Adds a "Open Game Data","Open Saves", "Open Logs" & "Open User Data" menu items.
- Adds a "Quit" menu item.
2022-01-23 19:51:17 +01:00
|
|
|
log.info("Found older save, but with more playtime, and current less than 15 mins played");
|
|
|
|
log.silly(bestMatch.data);
|
|
|
|
await pushSaveGameForImport(window, bestMatch.save, true);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
log.debug("Current save data is the freshest");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2022-04-07 01:30:08 +02:00
|
|
|
getCurrentSave,
|
|
|
|
getSaveInformation,
|
|
|
|
restoreIfNewerExists,
|
|
|
|
pushSaveGameForImport,
|
|
|
|
pushGameSaveToSteamCloud,
|
|
|
|
getSteamCloudSaveString,
|
|
|
|
getSteamCloudQuota,
|
|
|
|
deleteCloudFile,
|
|
|
|
saveGameToDisk,
|
|
|
|
loadLastFromDisk,
|
|
|
|
loadFileFromDisk,
|
|
|
|
getSaveFolder,
|
|
|
|
prepareSaveFolders,
|
|
|
|
getAllSaves,
|
|
|
|
isCloudEnabled,
|
|
|
|
setCloudEnabledConfig,
|
|
|
|
isAutosaveEnabled,
|
|
|
|
setAutosaveConfig,
|
|
|
|
isSaveCompressionEnabled,
|
|
|
|
setSaveCompressionConfig,
|
|
|
|
};
|