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");
- async function download({ published_file_id, name, updated }) {
- const { execFile } = require('child_process');
- 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
- }
- console.log("Dir");
- await execFile(SteamCMD, args, (error, stderr, stdout) => {
- console.log("error");
- if (error) {
- console.log("Error:");
- console.log(error);
- return -1; // Some Other Error, likely with execFile call
- };
- console.log("succ");
- 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("\""));
- console.log("Moving...");
- fs_extra.move(path, mod_dir + `\\${published_file_id}`, err => {
- if (err) return -3; // Move Destination Error
- console.log("Creating Workshop Object...");
- workshop_object[app_id] = {};
- 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', err)
- } else {
- console.log('Successfully wrote file')
- }
- });
- console.log(`Your mod has been moved to the following directory:\n${mod_dir + `\\${published_file_id}`}`)
- return 1; // 1 == true
- })
- };
- return 0; // Shouldnt get this code, just an in-case thing
- // SteamCMD doesnt use stdout for some reason?
- // console.log(stdout);
- });
- }
- async function delete_mod(app_id, published_file_id) {
- }
- module.exports = { download };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement