Created
February 17, 2017 15:20
-
-
Save comp500/d87b86fc71ebb307105c930cf5e5c43a to your computer and use it in GitHub Desktop.
Curse to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require modules | |
var path = require('path'); | |
var fs = require('fs'); | |
var url = require('url'); | |
var prompt = require('prompt'); | |
if (!process.env.APPDATA) { // Check for AppData existence | |
throw new Error("AppData not found. Are you on windows?"); | |
} | |
var instancesFile = path.join(process.env.APPDATA, "Curse Client/GameInstances/MinecraftGameInstance.json"); // find instances file | |
fs.readFile(instancesFile, function(err, data) { // read file | |
if (err) { | |
console.error("Curse Launcher metadata file could not be read, ensure " + instancesFile + " exists"); // report if unreadable | |
throw err; | |
} | |
var instances = JSON.parse(data); // parse file | |
for (var i = 0; i < instances.length; i++) { | |
console.log((i + 1) + ": " + instances[i].name + " (" + instances[i].gameVersion + ")"); // list instances in file | |
} | |
prompt.start(); // start prompt for instance | |
prompt.get({ | |
type: 'number', | |
description: 'Enter the number for the instance you want to select', | |
message: 'Must be a valid instance number', | |
required: true, | |
conform: function (value) { | |
return (value > 0) && (value < (instances.length + 1)); // must be a valid instance | |
} | |
}, function (err, result) { | |
var instance = instances[result.question - 1]; | |
console.log(instance.name + " selected, " + instance.installedAddons.length + " addons installed, " + instance.cachedScans.length + " mods cached."); | |
var installedAddonFiles = []; | |
var cachedFiles = []; | |
var csvOutput = []; | |
for (var i = 0; i < instance.installedAddons.length; i++) { | |
var modUrl = instance.installedAddons[i].installedFile.DownloadURL; | |
var fileName = path.parse(instance.installedAddons[i].installedFile.FileNameOnDisk).name; | |
installedAddonFiles.push(instance.installedAddons[i].installedFile.FileNameOnDisk); | |
var fileSplit = fileName.split('-'); | |
var name, version; | |
if (fileSplit.length > 1) { // TODO: Maybe prioritise space seperation over dash seperation | |
name = fileSplit[0]; | |
fileSplit.shift(); | |
version = fileSplit.join('-'); | |
} else { | |
fileSplit = fileName.split(' '); | |
name = fileSplit[0]; | |
fileSplit.shift(); | |
version = fileSplit.join(' '); | |
} | |
csvOutput.push(name + "," + version + "," + modUrl); | |
} | |
for (var i = 0; i < instance.cachedScans.length; i++) { | |
if (instance.cachedScans[i].folderName.toLowerCase() == "test") { | |
// do nothing | |
} else { | |
cachedFiles.push(instance.cachedScans[i].folderName); | |
} | |
} | |
cachedFiles = cachedFiles.filter(function(val) { | |
return installedAddonFiles.indexOf(val) == -1; | |
}); | |
for (var i = 0; i < cachedFiles.length; i++) { | |
var fileName = path.parse(cachedFiles[i]).name; | |
var fileSplit = fileName.split('-'); | |
var name, version; | |
if (fileSplit.length > 1) { // TODO: Maybe prioritise space seperation over dash seperation | |
name = fileSplit[0]; | |
fileSplit.shift(); | |
version = fileSplit.join('-'); | |
} else { | |
fileSplit = fileName.split(' '); | |
name = fileSplit[0]; | |
fileSplit.shift(); | |
version = fileSplit.join(' '); | |
} | |
csvOutput.push(name + "," + version + ","); | |
} | |
fs.writeFile(instance.name + ".cfg", csvOutput.join("\n"), function (err) { | |
if (err) throw err; | |
console.log('Config file saved.'); | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "curse-to-csv", | |
"version": "1.0.0", | |
"description": "Converts minecraft Curse Launcher profiles to CSV files for PackUpdate", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "comp500", | |
"license": "ISC", | |
"dependencies": { | |
"prompt": "^1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment