63 lines
3.1 KiB
JavaScript
63 lines
3.1 KiB
JavaScript
(function () {
|
|
/* ---------------------Single commands--------------------- */
|
|
|
|
/* Create a directory */
|
|
p7.commands.createDirectory = async (name, filesystem) => await p7.send.singleCommand(flashCommandSubtype.createDirectory, 0, 0, [name, '', '', '', filesystem, '']);
|
|
|
|
/* Delete a directory */
|
|
p7.commands.deleteDirectory = async (name, filesystem) => await p7.send.singleCommand(flashCommandSubtype.deleteDirectory, 0, 0, [name, '', '', '', filesystem, '']);
|
|
|
|
/* Rename a directory */
|
|
p7.commands.renameDirectory = async (oldName, newName, filesystem) => await p7.send.singleCommand(flashCommandSubtype.renameDirectory, 0, 0, [oldName, newName, '', '', filesystem, '']);
|
|
|
|
/* Change working directory */
|
|
p7.commands.changeDirectory = async (name, filesystem) => await p7.send.singleCommand(flashCommandSubtype.changeDirectory, 0, 0, [name, '', '', '', filesystem, '']);
|
|
|
|
/* Delete a file */
|
|
p7.commands.deleteFile = async (directory, name, filesystem) => await p7.send.singleCommand(flashCommandSubtype.deleteFile, 0, 0, [directory, name, '', '', filesystem, '']);
|
|
|
|
/* Rename a file */
|
|
p7.commands.renameFile = async (directory, oldName, newName, filesystem) => await p7.send.singleCommand(flashCommandSubtype.renameFile, 0, 0, [directory, oldName, newName, '', filesystem, '']);
|
|
|
|
/* Copy a file */
|
|
p7.commands.copyFile = async (oldDirectory, oldName, newDirectory, newName, filesystem) => await p7.send.singleCommand(flashCommandSubtype.copyFile, 0, 0, [oldDirectory, oldName, newDirectory, newName, filesystem, '']);
|
|
|
|
/* Reset flash? */
|
|
p7.commands.resetFlash = async (filesystem) => await p7.send.singleCommand(flashCommandSubtype.resetFlash, 0, 0, ['', '', '', '', filesystem, '']);
|
|
|
|
/* Optimize filesystem */
|
|
p7.commands.optimizeFilesystem = async (filesystem) => await p7.send.singleCommand(flashCommandSubtype.optimizeFileSystem, 0, 0, ['', '', '', '', filesystem, '']);
|
|
|
|
/* ---------------------Single command requests--------------------- */
|
|
|
|
/* Get free space */
|
|
p7.commands.getCapacity = async function (filesystem) {
|
|
try {
|
|
return (await p7.send.singleCommandRoleswap(flashCommandSubtype.capacityTransmitRequest, 0, 0, ['', '', '', '', filesystem, ''],
|
|
() => p7.decode.commandPacketFileSize()
|
|
))[0];
|
|
} catch (err) {
|
|
err.message = "Couldn't get the size of the free space: " + err.message;
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
/* List files */
|
|
p7.commands.list = async function (filesystem) {
|
|
try {
|
|
return await p7.send.singleCommandRoleswap(flashCommandSubtype.fileInfoTransferAllRequest, 0, 0, ['', '', '', '', filesystem, ''],
|
|
() => ({
|
|
size: p7.decode.commandPacketFileSize(),
|
|
DirectoryName: p7.decode.commandPacketDataField(1),
|
|
name: p7.decode.commandPacketDataField(2)
|
|
})
|
|
);
|
|
} catch (err) {
|
|
err.message = "Couldn't list files: " + err.message;
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
|
|
}) ();
|