plutonium-installer
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -20,2 +20,3 @@ #!/usr/bin/env node | ||
// Options | ||
InstallGameCommand.option("-p, --path <string>", "Installation path", "./"); | ||
InstallGameCommand.option("-v, --verbose", "Enables verbose mode", false); | ||
@@ -25,3 +26,3 @@ InstallGameCommand.option("-s, --server", "Removes files for server use", false); | ||
// Main functionality | ||
InstallGameCommand.action((Game, Options) => { | ||
InstallGameCommand.action(async (Game, Options) => { | ||
// Make sure a valid game is entered | ||
@@ -33,3 +34,4 @@ if (TGameKeys.includes(Game) == false) { | ||
console.log("Installing..."); | ||
InstallGame(Game, "./", Options.verbose, Options.server, Options.force); | ||
await InstallGame(Game, Options.path, Options.verbose, Options.server, Options.force); | ||
console.log("Installed!"); | ||
}); | ||
@@ -40,6 +42,8 @@ } | ||
const InstallLauncher = program.command("install-launcher").description("Install the plutonium launcher"); | ||
// Options | ||
InstallLauncher.option("-p, --path <string>", "Installation path", "./"); | ||
// Main functionaity | ||
InstallLauncher.action(async () => { | ||
InstallLauncher.action(async (Options) => { | ||
console.log("Installing..."); | ||
await InstallPlutoniumLauncher("./"); | ||
await InstallPlutoniumLauncher(Options.path); | ||
console.log("Installed!"); | ||
@@ -53,4 +57,6 @@ }); | ||
InstallConfig.argument("<game>", "the game you want to install. e.g. t6"); | ||
// Options | ||
InstallConfig.option("-p, --path <string>", "Installation path", "./"); | ||
// Main functionaity | ||
InstallConfig.action(async (Game) => { | ||
InstallConfig.action(async (Game, Options) => { | ||
// Make sure a valid game is entered | ||
@@ -62,3 +68,3 @@ if (TGameKeys.includes(Game) == false) { | ||
console.log("Installing..."); | ||
await InstallServerConfig(Game, "./"); | ||
await InstallServerConfig(Game, Options.path); | ||
console.log("Installed!"); | ||
@@ -71,2 +77,3 @@ }); | ||
// Options | ||
Cleanup.option("-p, --path <string>", "Installation path", "./"); | ||
Cleanup.option("-v, --verbose", "Enable verbose mode", false); | ||
@@ -76,3 +83,3 @@ // Main functionality | ||
console.log("Cleaning..."); | ||
CleanupInstall("./", Options.verbose); | ||
CleanupInstall(Options.path, Options.verbose); | ||
console.log("Cleaned!"); | ||
@@ -79,0 +86,0 @@ }); |
@@ -5,3 +5,3 @@ export declare function InstallServerConfig(Game: TGame, Path: string): Promise<void>; | ||
export declare type TGame = typeof TGameKeys[number]; | ||
export declare function InstallGame(Game: TGame, Path: string, Verbose?: boolean, Server?: boolean, Force?: boolean): void; | ||
export declare function InstallGame(Game: TGame, Path: string, Verbose?: boolean, Server?: boolean, Force?: boolean): Promise<void>; | ||
//# sourceMappingURL=Installer.d.ts.map |
@@ -35,62 +35,96 @@ // Dependencies | ||
export function InstallGame(Game, Path, Verbose = false, Server = false, Force = false) { | ||
// Vars | ||
const TorrentURL = `https://plutonium.pw/pluto_${Game}_full_game.torrent`; | ||
const TorrentClient = new WebTorrent(); | ||
// Start the download | ||
const torrent = TorrentClient.add(TorrentURL, { | ||
path: Path, | ||
}, function (torrent_) { | ||
return new Promise((resolve, reject) => { | ||
// Force | ||
if (fs.readdirSync(Path).length != 0) { | ||
console.log("WARN: install path is not empty"); | ||
if (fs.existsSync(Path) && fs.readdirSync(Path).length != 0) { | ||
if (Verbose) | ||
console.warn("WARN: install path is not empty"); | ||
if (Force) | ||
console.log("WARN: Forcing..."); | ||
else { | ||
console.log("ERROR: stopping install"); | ||
torrent_.destroy(); | ||
process.exit(1); | ||
} | ||
if (Verbose) | ||
console.warn("WARN: Forcing..."); | ||
else { | ||
if (Verbose) | ||
console.error("ERROR: stopping install"); | ||
return reject(new Error("install path is not empty, stopping install")); | ||
} | ||
} | ||
// Make sure is server - for ignoring | ||
if (Server == false) | ||
return; | ||
// Warning | ||
console.log("WARN: torrent deselect is not fully working!"); | ||
// Deselect everything | ||
torrent_.files.forEach(file => file.deselect()); | ||
torrent_.deselect(0, torrent_.pieces.length - 1, false); | ||
// | ||
for (const file of torrent_.files) { | ||
// Check path | ||
const ParentPath = path.basename(path.dirname(file.path)); | ||
// Removing files | ||
const EnglishFileCheck = ParentPath == "english" && KeepEnglish.includes(file.name) == false; | ||
const AllFileCheck = ParentPath == "all" && KeepAll.includes(file.name) == false; | ||
const FolderCheck = RemoveFolders.includes(ParentPath); | ||
if (AllFileCheck || EnglishFileCheck || FolderCheck) { | ||
file.deselect(); | ||
continue; | ||
// Vars | ||
const TorrentURL = `https://plutonium.pw/pluto_${Game}_full_game.torrent`; | ||
const TorrentClient = new WebTorrent(); | ||
// Start the download | ||
return TorrentClient.add(TorrentURL, { | ||
path: Path | ||
}, function (torrent) { | ||
// Output | ||
if (Verbose) | ||
console.log("Got torrent metadata!"); | ||
// Error tracker | ||
torrent.on('error', function (err) { | ||
console.error('ERROR:', err); | ||
}); | ||
// Progress tracker | ||
let LastLog = new Date().getTime(); | ||
torrent.on('download', function (bytes) { | ||
// Only log every second | ||
let CurrentTime = new Date().getTime(); | ||
if (Verbose && CurrentTime - LastLog >= 1000) { | ||
console.log(`${(torrent.progress * 100).toPrecision(2)}% | ${(torrent.downloadSpeed / 1e6).toPrecision(4)}Mbps`); | ||
LastLog = CurrentTime; | ||
} | ||
}); | ||
// See whenever it is done | ||
torrent.on("done", function () { | ||
// Done | ||
if (Verbose) | ||
console.log("Torrent finished!"); | ||
// Installing server config | ||
if (Verbose) | ||
console.log("Installing Server Config..."); | ||
InstallServerConfig(Game, Path).then(() => { | ||
console.log("Installed Server Config!"); | ||
// Installing the plutonium launcher | ||
if (Verbose) | ||
console.log("Installing plutonium launcher..."); | ||
InstallPlutoniumLauncher(Path).then(() => { | ||
if (Verbose) | ||
console.log("Installed plutonium launcher!"); | ||
return resolve(); | ||
}); | ||
}); | ||
// Destroy the torrent | ||
torrent.pause(); | ||
torrent.destroy(); | ||
}); | ||
// Make sure is server - for ignoring | ||
if (Server == false) | ||
return; | ||
// Warning | ||
if (Verbose) | ||
console.log("WARN: torrent deselect is not fully working, you may have to cleanup after!"); | ||
// Deselect everything | ||
torrent.files.forEach(file => file.deselect()); | ||
torrent.deselect(0, torrent.pieces.length - 1, false); | ||
// Selecting files | ||
const Ignored = []; | ||
const Selected = []; | ||
for (const file of torrent.files) { | ||
// Check path | ||
const ParentPath = path.basename(path.dirname(file.path)); | ||
// Removing files | ||
const EnglishFileCheck = ParentPath == "english" && KeepEnglish.includes(file.name) == false; | ||
const AllFileCheck = ParentPath == "all" && KeepAll.includes(file.name) == false; | ||
const FolderCheck = RemoveFolders.includes(ParentPath); | ||
if (AllFileCheck || EnglishFileCheck || FolderCheck) { | ||
file.deselect(); | ||
Ignored.push(file.path); | ||
continue; | ||
} | ||
// File is wanted, add to selections | ||
file.select(); | ||
Selected.push(file.path); | ||
} | ||
// File is wanted, add to selections | ||
file.select(); | ||
} | ||
}); | ||
// Progress tracker | ||
torrent.on('download', function (bytes) { | ||
if (Verbose) | ||
console.log(`${torrent.progress}% | ${torrent.downloadSpeed / 1e6}Mbps`); | ||
}); | ||
// See whenever it is done | ||
torrent.on("done", () => { | ||
// Done | ||
console.log("Torrent finished!"); | ||
// Installing server confi g | ||
console.log("Installing Server Config..."); | ||
InstallServerConfig(Game, Path).then(() => { | ||
console.log("Installed Server Config!"); | ||
// Installing the plutonium launcher | ||
console.log("Installing plutonium launcher..."); | ||
InstallPlutoniumLauncher(Path).then(() => { | ||
console.log("Installed plutonium launcher!"); | ||
}); | ||
// Output Ignored and Selected | ||
if (Verbose) { | ||
fs.writeFileSync(`${Path}/ignored.txt`, Ignored.join("\n")); | ||
fs.writeFileSync(`${Path}/selected.txt`, Selected.join("\n")); | ||
} | ||
}); | ||
@@ -97,0 +131,0 @@ }); |
{ | ||
"name": "plutonium-installer", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Lets you install plutonium games for both personal use and server use", | ||
@@ -5,0 +5,0 @@ "exports": "./lib/index.js", |
@@ -26,2 +26,3 @@ #!/usr/bin/env node | ||
// Options | ||
InstallGameCommand.option("-p, --path <string>", "Installation path", "./") | ||
InstallGameCommand.option("-v, --verbose", "Enables verbose mode", false) | ||
@@ -32,3 +33,3 @@ InstallGameCommand.option("-s, --server", "Removes files for server use", false) | ||
// Main functionality | ||
InstallGameCommand.action((Game, Options) => { | ||
InstallGameCommand.action(async (Game, Options) => { | ||
// Make sure a valid game is entered | ||
@@ -41,3 +42,4 @@ if (TGameKeys.includes(Game) == false){ | ||
console.log("Installing...") | ||
InstallGame(Game, "./", Options.verbose, Options.server, Options.force) | ||
await InstallGame(Game, Options.path, Options.verbose, Options.server, Options.force) | ||
console.log("Installed!") | ||
}) | ||
@@ -50,6 +52,9 @@ } | ||
// Options | ||
InstallLauncher.option("-p, --path <string>", "Installation path", "./") | ||
// Main functionaity | ||
InstallLauncher.action(async () => { | ||
InstallLauncher.action(async (Options) => { | ||
console.log("Installing...") | ||
await InstallPlutoniumLauncher("./") | ||
await InstallPlutoniumLauncher(Options.path) | ||
console.log("Installed!") | ||
@@ -66,4 +71,7 @@ }) | ||
// Options | ||
InstallConfig.option("-p, --path <string>", "Installation path", "./") | ||
// Main functionaity | ||
InstallConfig.action(async (Game) => { | ||
InstallConfig.action(async (Game, Options) => { | ||
// Make sure a valid game is entered | ||
@@ -76,3 +84,3 @@ if (TGameKeys.includes(Game) == false){ | ||
console.log("Installing...") | ||
await InstallServerConfig(Game, "./") | ||
await InstallServerConfig(Game, Options.path) | ||
console.log("Installed!") | ||
@@ -87,2 +95,3 @@ }) | ||
// Options | ||
Cleanup.option("-p, --path <string>", "Installation path", "./") | ||
Cleanup.option("-v, --verbose", "Enable verbose mode", false) | ||
@@ -93,3 +102,3 @@ | ||
console.log("Cleaning...") | ||
CleanupInstall("./", Options.verbose) | ||
CleanupInstall(Options.path, Options.verbose) | ||
console.log("Cleaned!") | ||
@@ -96,0 +105,0 @@ }) |
@@ -41,75 +41,104 @@ // Dependencies | ||
export function InstallGame(Game: TGame, Path: string, Verbose: boolean = false, Server: boolean = false, Force: boolean = false) { | ||
// Vars | ||
const TorrentURL = `https://plutonium.pw/pluto_${Game}_full_game.torrent` | ||
const TorrentClient = new WebTorrent() | ||
// Start the download | ||
const torrent = TorrentClient.add(TorrentURL, { | ||
path: Path, | ||
}, function (torrent_) { | ||
return new Promise<void>((resolve, reject) => { | ||
// Force | ||
if (fs.readdirSync(Path).length != 0){ | ||
console.log("WARN: install path is not empty") | ||
if (fs.existsSync(Path) && fs.readdirSync(Path).length != 0){ | ||
if (Verbose) console.warn("WARN: install path is not empty") | ||
if (Force) | ||
console.log("WARN: Forcing...") | ||
if (Verbose) console.warn("WARN: Forcing...") | ||
else { | ||
console.log("ERROR: stopping install") | ||
torrent_.destroy() | ||
process.exit(1) | ||
if (Verbose) console.error("ERROR: stopping install") | ||
return reject(new Error("install path is not empty, stopping install")) | ||
} | ||
} | ||
// Make sure is server - for ignoring | ||
if (Server == false) return | ||
// Warning | ||
console.log("WARN: torrent deselect is not fully working!") | ||
// Vars | ||
const TorrentURL = `https://plutonium.pw/pluto_${Game}_full_game.torrent` | ||
const TorrentClient = new WebTorrent() | ||
// Deselect everything | ||
torrent_.files.forEach(file => file.deselect()) | ||
torrent_.deselect(0, torrent_.pieces.length - 1, <any>false) | ||
// Start the download | ||
return TorrentClient.add(TorrentURL, { | ||
path: Path | ||
}, function (torrent) { | ||
// Output | ||
if (Verbose) console.log("Got torrent metadata!") | ||
// | ||
for (const file of torrent_.files) { | ||
// Check path | ||
const ParentPath = path.basename(path.dirname(file.path)) | ||
// Error tracker | ||
torrent.on('error', function (err) { | ||
console.error('ERROR:', err) | ||
}) | ||
// Removing files | ||
const EnglishFileCheck = ParentPath == "english" && KeepEnglish.includes(file.name) == false | ||
const AllFileCheck = ParentPath == "all" && KeepAll.includes(file.name) == false | ||
const FolderCheck = RemoveFolders.includes(ParentPath) | ||
if (AllFileCheck || EnglishFileCheck || FolderCheck) { | ||
file.deselect() | ||
continue | ||
} | ||
// Progress tracker | ||
let LastLog = new Date().getTime() | ||
torrent.on('download', function (bytes) { | ||
// Only log every second | ||
let CurrentTime = new Date().getTime() | ||
if (Verbose && CurrentTime - LastLog >= 1000){ | ||
console.log(`${(torrent.progress * 100).toPrecision(2)}% | ${(torrent.downloadSpeed / 1e6).toPrecision(4)}Mbps`) | ||
LastLog = CurrentTime | ||
} | ||
}) | ||
// File is wanted, add to selections | ||
file.select() | ||
} | ||
}) | ||
// See whenever it is done | ||
torrent.on("done", function() { | ||
// Done | ||
if (Verbose) console.log("Torrent finished!") | ||
// Progress tracker | ||
torrent.on('download', function (bytes) { | ||
if (Verbose) | ||
console.log(`${torrent.progress}% | ${torrent.downloadSpeed / 1e6}Mbps`) | ||
}) | ||
// Installing server config | ||
if (Verbose) console.log("Installing Server Config...") | ||
InstallServerConfig(Game, Path).then(() => { | ||
console.log("Installed Server Config!") | ||
// See whenever it is done | ||
torrent.on("done", () => { | ||
// Done | ||
console.log("Torrent finished!") | ||
// Installing the plutonium launcher | ||
if (Verbose) console.log("Installing plutonium launcher...") | ||
InstallPlutoniumLauncher(Path).then(() => { | ||
if (Verbose) console.log("Installed plutonium launcher!") | ||
return resolve() | ||
}) | ||
}) | ||
// Installing server confi g | ||
console.log("Installing Server Config...") | ||
InstallServerConfig(Game, Path).then(() => { | ||
console.log("Installed Server Config!") | ||
// Destroy the torrent | ||
torrent.pause() | ||
torrent.destroy() | ||
}) | ||
// Installing the plutonium launcher | ||
console.log("Installing plutonium launcher...") | ||
InstallPlutoniumLauncher(Path).then(() => { | ||
console.log("Installed plutonium launcher!") | ||
}) | ||
// Make sure is server - for ignoring | ||
if (Server == false) return | ||
// Warning | ||
if (Verbose) console.log("WARN: torrent deselect is not fully working, you may have to cleanup after!") | ||
// Deselect everything | ||
torrent.files.forEach(file => file.deselect()) | ||
torrent.deselect(0, torrent.pieces.length - 1, <any>false) | ||
// Selecting files | ||
const Ignored = [] | ||
const Selected = [] | ||
for (const file of torrent.files) { | ||
// Check path | ||
const ParentPath = path.basename(path.dirname(file.path)) | ||
// Removing files | ||
const EnglishFileCheck = ParentPath == "english" && KeepEnglish.includes(file.name) == false | ||
const AllFileCheck = ParentPath == "all" && KeepAll.includes(file.name) == false | ||
const FolderCheck = RemoveFolders.includes(ParentPath) | ||
if (AllFileCheck || EnglishFileCheck || FolderCheck) { | ||
file.deselect() | ||
Ignored.push(file.path) | ||
continue | ||
} | ||
// File is wanted, add to selections | ||
file.select() | ||
Selected.push(file.path) | ||
} | ||
// Output Ignored and Selected | ||
if (Verbose){ | ||
fs.writeFileSync(`${Path}/ignored.txt`, Ignored.join("\n")) | ||
fs.writeFileSync(`${Path}/selected.txt`, Selected.join("\n")) | ||
} | ||
}) | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53727
958