bitburner-src/electron/storage.js

399 lines
13 KiB
JavaScript
Raw Normal View History

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 Store = require("electron-store");
const { isBinaryFormat } = require("./saveDataBinaryFormat");
const store = new Store();
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
// 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) {
store.set("autosave-enabled", value);
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 isAutosaveEnabled() {
return store.get("autosave-enabled", true);
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 setCloudEnabledConfig(value) {
store.set("cloud-enabled", value);
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 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 = store.get("cloud-enabled", true);
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 (!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 backupSaveData = await getSteamCloudSaveData();
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 backupFile = path.join(app.getPath("userData"), "/saves/_backups", `${previousPlayerId}.json.gz`);
await fs.writeFile(backupFile, backupSaveData, "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}`);
}
}
/**
* The name of save file is `${currentPlayerId}.json.gz`. The content of save file is weird: it's a base64 string of the
* binary data of compressed json save string. It's weird because the extension is .json.gz while the content is a
* base64 string. Check the comments in the implementation to see why it is like that.
*/
async function pushSaveDataToSteamCloud(saveData, currentPlayerId) {
if (!isCloudEnabled()) {
return Promise.reject("Steam Cloud is not Enabled");
}
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
try {
backupSteamDataToDisk(currentPlayerId);
} catch (error) {
log.error(error);
}
const steamSaveName = `${currentPlayerId}.json.gz`;
/**
* When we push save file to Steam Cloud, we use greenworks.saveTextToFile. It seems that this method expects a string
* as the file content. That is why saveData is encoded in base64 and pushed to Steam Cloud as a text file.
*
* Encoding saveData in UTF-8 (with buffer.toString("utf8")) is not the proper way to convert binary data to string.
* Quote from buffer's documentation: "If encoding is 'utf8' and a byte sequence in the input is not valid UTF-8, then
* each invalid byte is replaced with the replacement character U+FFFD.". The proper way to do it is to use
* String.fromCharCode or String.fromCodePoint.
*
* Instead of implementing it, the old code (encoding in base64) is used here for backward compatibility.
*/
const content = Buffer.from(saveData).toString("base64");
log.debug(`saveData: ${saveData.length} bytes`);
log.debug(`Base64 string of saveData: ${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
log.debug(`Saving to Steam Cloud as ${steamSaveName}`);
try {
await saveCloudFile(steamSaveName, content);
} catch (error) {
log.error(error);
}
}
/**
* This function processes the save file in Steam Cloud and returns the save data in the binary format.
*/
async function getSteamCloudSaveData() {
if (!isCloudEnabled()) {
return Promise.reject("Steam Cloud is not Enabled");
}
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(`Fetching Save in Steam Cloud`);
const cloudString = await getCloudFile();
// Decode cloudString to get save data back.
const saveData = Buffer.from(cloudString, "base64");
log.debug(`SaveData: ${saveData.length} bytes`);
return saveData;
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 saveGameToDisk(window, electronGameData) {
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 currentFolder = await getSaveFolder(window);
let saveFolderSizeBytes = await getFolderSizeInBytes(currentFolder);
const maxFolderSizeBytes = store.get("autosave-quota", 1e8); // 100Mb per playerIndentifier
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 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)`,
);
let saveData = electronGameData.save;
const file = path.join(currentFolder, electronGameData.fileName);
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
try {
await fs.writeFile(file, saveData, "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: ${saveData.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
} 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;
if (isBinaryFormat(buffer)) {
// Save file is in the binary format.
content = buffer;
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
} else {
// Save file is in the base64 format.
2022-04-07 01:30:08 +02:00
content = buffer.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
}
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 getSteamCloudSaveData();
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
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");
} 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");
bestMatch = disk;
} else if (!disk.data) {
2022-04-07 01:30:08 +02:00
log.debug("Best potential save match: Steam Cloud");
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) {
// 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");
bestMatch = steam;
} else {
2022-04-07 01:30:08 +02:00
log.debug("Best potential save match: disk");
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);
pushSaveGameForImport(window, bestMatch.save, true);
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 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);
pushSaveGameForImport(window, bestMatch.save, true);
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 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,
pushSaveDataToSteamCloud,
getSteamCloudSaveData,
2022-04-07 01:30:08 +02:00
getSteamCloudQuota,
deleteCloudFile,
saveGameToDisk,
loadLastFromDisk,
loadFileFromDisk,
getSaveFolder,
prepareSaveFolders,
getAllSaves,
isCloudEnabled,
setCloudEnabledConfig,
isAutosaveEnabled,
setAutosaveConfig,
};