Skip to content

Commit

Permalink
Fix customUpdateRules failing because of missing backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed May 5, 2023
1 parent 69f21b5 commit d3ed122
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/updater/helpers/customUpdateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 22.02.2022 17:39:21
* Author: 3urobeat
*
* Last Modified: 05.05.2023 14:18:44
* Last Modified: 05.05.2023 23:44:10
* Modified By: 3urobeat
*
* Copyright (c) 2022 3urobeat <https://github.com/HerrEurobeat>
Expand All @@ -20,9 +20,14 @@ const fs = require("fs");

/**
* Applies custom update rules for a few files (gets called by downloadUpdate.js)
* @param {any} compatibilityfeaturedone Legacy param, is unused
* @param {Object} oldconfig The old config from before the update
* @param {Object} oldadvancedconfig The old advancedconfig from before the update
* @param {Object} olddatafile The old datafile from before the update
* @param {function} callback Legacy param, will be called if defined with no parameters
* @returns {Promise} Resolves when we can proceed
*/
module.exports.customUpdateRules = (oldconfig, oldadvancedconfig, oldextdata) => {
module.exports.customUpdateRules = (compatibilityfeaturedone, oldconfig, oldadvancedconfig, olddatafile, callback) => {
return new Promise((resolve) => {

/* --------------------- config.json --------------------- */
Expand Down Expand Up @@ -100,9 +105,9 @@ module.exports.customUpdateRules = (oldconfig, oldadvancedconfig, oldextdata) =>
// Transfer a few specific values to the new datafile
logger("", `${logger.colors.fgyellow}Transferring changes to new data.json...${logger.colors.reset}`, true, false, logger.animation("loading"));

newextdata.urlrequestsecretkey = oldextdata.urlrequestsecretkey;
newextdata.timesloggedin = oldextdata.timesloggedin;
newextdata.totallogintime = oldextdata.totallogintime;
newextdata.urlrequestsecretkey = olddatafile.urlrequestsecretkey;
newextdata.timesloggedin = olddatafile.timesloggedin;
newextdata.totallogintime = olddatafile.totallogintime;

// Write changes to file
logger("", `${logger.colors.fgyellow}Writing new data to data.json...`, true, false, logger.animation("loading"));
Expand All @@ -115,6 +120,7 @@ module.exports.customUpdateRules = (oldconfig, oldadvancedconfig, oldextdata) =>

// Resolve when the last write finished
resolve();
if (callback) callback(); // Call the old callback function if one was passed to keep backwards compatibility
});

});
Expand Down
6 changes: 3 additions & 3 deletions src/updater/helpers/downloadUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 05.05.2023 14:40:28
* Last Modified: 05.05.2023 23:41:46
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -106,8 +106,8 @@ const download = require("download"); // TODO: Does it make a difference if we r
if (newfiles.length == i + 1) {
fs.rmSync(`./steam-comment-service-bot-${controller.data.datafile.branch}`, { recursive: true }); // Remove the remains of the download folder

// Run custom update rules for a few files
await require("./customUpdateRules.js").customUpdateRules(oldconfig, oldadvancedconfig, olddatafile);
// Run custom update rules for a few files. Note: This will load the new file but call with old parameters. Sounds like a recipe for disaster
await require("./customUpdateRules.js").customUpdateRules(null, oldconfig, oldadvancedconfig, olddatafile);

// Make callback with no error message to let caller carry on
resolve(null);
Expand Down

0 comments on commit d3ed122

Please sign in to comment.