Adding app names to download status (#19) and cleaning up messages

This commit is contained in:
ilumos 2018-02-03 14:57:10 +00:00
parent c44a3d5703
commit c5ae9cbe8b

View file

@ -3,10 +3,11 @@
namespace Zeropingheroes\LancacheAutofill\Commands\Steam;
use Illuminate\Console\Command;
use Illuminate\Database\Capsule\Manager as Capsule;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Zeropingheroes\LancacheAutofill\Services\SteamCmd\SteamCmd;
use Zeropingheroes\LancacheAutofill\Models\SteamQueueItem;
use Zeropingheroes\LancacheAutofill\Models\SteamAccount;
class StartDownloading extends Command
{
@ -45,7 +46,13 @@ class StartDownloading extends Command
// Attempt download using each authorised Steam account in turn
foreach ($this->steamAccounts() as $account) {
$this->info('Starting download of '.$item->app_id.' for '.$item->platform.' from Steam account '.$account);
if (isset($item->app->name)) {
$appName = $item->app->name;
} else {
$appName = 'Unknown';
}
$this->info('Starting download of ' . $appName . ' (App ID: ' . $item->app_id . ') for ' . $item->platform . ' from Steam account "' . $account . '"');
try {
@ -67,18 +74,16 @@ class StartDownloading extends Command
throw new ProcessFailedException($steamCmd);
}
$this->info('Successfully completed download of '.$item->app_id.' for '.$item->platform.' from Steam account '.$account);
$this->info('Successfully completed download of ' . $appName . ' (App ID: ' . $item->app_id . ') for ' . $item->platform . '. Deleting from disk.');
$this->updateQueueItemStatus($item->id, 'completed');
// Delete download directory
$this->info('Deleting '.$item->app_id.' from disk');
$remove = new Process('rm -rf ' . $downloadPath);
$remove->run(function ($type, $buffer) {
if (Process::ERR === $type) {
$this->error(str_replace(["\r", "\n"], '', $buffer));
}
else {
} else {
$this->line(str_replace(["\r", "\n"], '', $buffer));
}
@ -103,7 +108,7 @@ class StartDownloading extends Command
// Removing ANSI codes
$message = preg_replace('#\x1b\[[0-9;]*[a-zA-Z]#', '', $message);
$this->error('Failed to download '.$item->app_id.' for '.$item->platform.' from Steam account '.$account);
$this->error('Failed to download ' . $appName . ' (App ID: ' . $item->app_id . ') for ' . $item->platform . ' from Steam account ' . $account);
$this->updateQueueItemStatus($item->id, 'failed', $message);
}
}
@ -117,8 +122,7 @@ class StartDownloading extends Command
*/
private function nextApp()
{
return Capsule::table('steam_queue')
->where('status', 'queued')
return SteamQueueItem::where('status', 'queued')
->first();
}
@ -132,8 +136,7 @@ class StartDownloading extends Command
*/
private function updateQueueItemStatus($id, $status, $message = null)
{
return Capsule::table('steam_queue')
->where('id', $id)
return SteamQueueItem::where('id', $id)
->update(['status' => $status, 'message' => $message]);
}
@ -144,8 +147,7 @@ class StartDownloading extends Command
*/
private function queuedItems()
{
return Capsule::table('steam_queue')
->where('status', 'queued')
return SteamQueueItem::where('status', 'queued')
->count();
}
@ -156,7 +158,7 @@ class StartDownloading extends Command
*/
private function steamAccounts()
{
return Capsule::table('steam_accounts')->pluck('username');
return SteamAccount::all()->pluck('username');
}
/**