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 { execFile } = require('child_process');
- const { promisify } = require('util');
- const promisifiedExecFile = promisify(execFile);
- async function download({ published_file_id, name, updated }) {
- 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
- }
- try {
- const { stdout, stderr } = await promisifiedExecFile(SteamCMD, args, { cwd: 'C:\\Users\\Thatguy553\\Downloads\\steamcmd\\' });
- // Process the stdout and stderr as needed
- console.log(stdout);
- console.log(stderr);
- console.log('Process completed successfully.');
- let path = stdout.substring(stdout.indexOf("\"") + 1);
- path = path.substring(0, path.indexOf("\""));
- let new_mod_dir = mod_dir + `\\${published_file_id}`;
- console.log("Moving...");
- console.log(`${path}\n${new_mod_dir}`);
- fs_extra.moveSync(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 and Mod ID properties
- workshop_object[app_id] = {};
- workshop_object[app_id][published_file_id] = {};
- // Assigning the mod data to the previously created Mod 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);
- return -1;
- } else {
- console.log('Successfully wrote file');
- };
- });
- return 1;
- } catch (error) {
- console.log('Error:', error);
- // Handle the error accordingly
- return 0;
- }
- }
- async function delete_mod(app_id, published_file_id) {
- }
- module.exports = { download };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement