Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let workshop_object = require("./workshop.json");
- const fs = require('fs');
- const fs_extra = require("fs-extra");
- const util = require('util');
- async function download({ published_file_id, name, updated }) {
- const execFile = util.promisify(require('child_process').execFile);
- let { steam_user, steam_pass, app_id, mod_dir, SteamCMD } = require('./config.json');
- let args = [
- // `+force_install_dir ${mod_dir}`, wee thing doesnt just throw the downloaded folders into the directory, it creates the whole steam tree
- `+login ${steam_user} ${steam_pass}`,
- `+workshop_download_item ${app_id} ${published_file_id}`,
- `+quit`
- ];
- console.log("Checking Directory Existence...")
- if (fs.existsSync(mod_dir + `\\${published_file_id}`)) {
- console.log("Directory Exists Already");
- return -4; // Mod Already Exists
- }
- // Process currently doesnt seem to exit. Need to solve this somehow
- let process = await execFile(SteamCMD, args, (error, stderr, stdout) => {
- if (error) {
- console.log("Error:");
- console.log(error);
- return -1; // Some Other Error, likely with execFile call
- };
- if (stderr.search("Success") == -1) {
- console.log("STDError:");
- console.log(stderr);
- return -2; // Download Error
- };
- if (stderr.search("Success") > -1) {
- console.log("SUCCESS");
- console.log(stderr);
- };
- let path = stderr.substring(stderr.indexOf("\"") + 1);
- path = path.substring(0, path.indexOf("\""));
- let new_mod_dir = mod_dir + `\\${published_file_id}`;
- console.log("Moving...");
- fs_extra.move(path, new_mod_dir, err => {
- if (err) return -3; // Move Destination Error
- console.log(`Your mod has been moved to the following directory:\n${new_mod_dir}`)
- })
- console.log("Creating Workshop Object...");
- // Creating the game ID property
- workshop_object[app_id] = workshop_object[app_id];
- // Creating the mod ID property inside the newly created (or existing) game id property
- workshop_object[app_id][published_file_id] = { name: name, updated: updated};
- console.log(workshop_object);
- const jsonString = JSON.stringify(workshop_object);
- console.log("Updating Workshop.json...")
- fs.writeFileSync('./workshop.json', jsonString, err => {
- if (err) {
- console.log('Error writing file, reverting changes', err);
- fs_extra.remove(new_mod_dir);
- } else {
- console.log('Successfully wrote file');
- };
- });
- // SteamCMD doesnt use stdout for some reason?
- // console.log(stdout);
- return 0; // Shouldnt get this code, just an in-case thing
- });
- }
- async function delete_mod(app_id, published_file_id) {
- }
- module.exports = { download };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement