mirror of
https://github.com/zeropingheroes/lancache-autofill
synced 2024-11-10 10:24:12 +00:00
Fixing DOS newlines
This commit is contained in:
parent
cf58753079
commit
31ae989b8c
6 changed files with 348 additions and 348 deletions
80
lancache-autofill
Normal file → Executable file
80
lancache-autofill
Normal file → Executable file
|
@ -1,41 +1,41 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
// Import Laravel modules
|
||||
use Illuminate\Console\Application;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
// Import available commands
|
||||
use Zeropingheroes\LancacheAutofill\Console\Commands\Steam\{UpdateAppList, SearchApps, QueueApp, ShowQueue};
|
||||
use Zeropingheroes\LancacheAutofill\Console\Commands\CreateDatabase;
|
||||
|
||||
// Load Composer's autoloader
|
||||
if (file_exists($a = __DIR__.'/../../autoload.php')) {
|
||||
require_once $a;
|
||||
} else {
|
||||
require_once __DIR__.'/vendor/autoload.php';
|
||||
}
|
||||
|
||||
// Set up the console app
|
||||
$app = new Application(new Container, new Dispatcher, '5.4');
|
||||
|
||||
// Set up the SQLite database connection
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
'driver' => 'sqlite',
|
||||
'database' => __DIR__.'/database.sqlite',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$capsule->setAsGlobal();
|
||||
|
||||
// Make commands available
|
||||
$app->add(new CreateDatabase);
|
||||
$app->add(new UpdateAppList);
|
||||
$app->add(new SearchApps);
|
||||
$app->add(new QueueApp);
|
||||
$app->add(new ShowQueue);
|
||||
|
||||
// Run the console app
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
// Import Laravel modules
|
||||
use Illuminate\Console\Application;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
// Import available commands
|
||||
use Zeropingheroes\LancacheAutofill\Console\Commands\Steam\{UpdateAppList, SearchApps, QueueApp, ShowQueue};
|
||||
use Zeropingheroes\LancacheAutofill\Console\Commands\CreateDatabase;
|
||||
|
||||
// Load Composer's autoloader
|
||||
if (file_exists($a = __DIR__.'/../../autoload.php')) {
|
||||
require_once $a;
|
||||
} else {
|
||||
require_once __DIR__.'/vendor/autoload.php';
|
||||
}
|
||||
|
||||
// Set up the console app
|
||||
$app = new Application(new Container, new Dispatcher, '5.4');
|
||||
|
||||
// Set up the SQLite database connection
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
'driver' => 'sqlite',
|
||||
'database' => __DIR__.'/database.sqlite',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$capsule->setAsGlobal();
|
||||
|
||||
// Make commands available
|
||||
$app->add(new CreateDatabase);
|
||||
$app->add(new UpdateAppList);
|
||||
$app->add(new SearchApps);
|
||||
$app->add(new QueueApp);
|
||||
$app->add(new ShowQueue);
|
||||
|
||||
// Run the console app
|
||||
$app->run();
|
|
@ -1,47 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class CreateDatabase extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:create-database';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create the database';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Creating database');
|
||||
|
||||
Capsule::schema()->create('steam_apps', function ($table) {
|
||||
$table->integer('appid')->unique();
|
||||
$table->string('name');
|
||||
});
|
||||
|
||||
Capsule::schema()->create('steam_queue', function ($table) {
|
||||
$table->increments('id')->unique();
|
||||
$table->integer('appid')->unique();
|
||||
$table->string('name');
|
||||
$table->string('status');
|
||||
$table->string('message')->nullable();
|
||||
|
||||
});
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class CreateDatabase extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:create-database';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create the database';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Creating database');
|
||||
|
||||
Capsule::schema()->create('steam_apps', function ($table) {
|
||||
$table->integer('appid')->unique();
|
||||
$table->string('name');
|
||||
});
|
||||
|
||||
Capsule::schema()->create('steam_queue', function ($table) {
|
||||
$table->increments('id')->unique();
|
||||
$table->integer('appid')->unique();
|
||||
$table->string('name');
|
||||
$table->string('status');
|
||||
$table->string('message')->nullable();
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,60 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class QueueApp extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:queue-app {app_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Queue a Steam app for donwloading';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$app = Capsule::table('steam_apps')
|
||||
->where('appid', $this->argument('app_id'))
|
||||
->first();
|
||||
|
||||
if( ! $app )
|
||||
{
|
||||
$this->error('Steam app with ID '.$this->argument('app_id').' not found');
|
||||
die();
|
||||
}
|
||||
|
||||
$alreadyQueued = Capsule::table('steam_queue')
|
||||
->where('appid', $app->appid)
|
||||
->count();
|
||||
|
||||
if( $alreadyQueued )
|
||||
{
|
||||
$this->error('Steam app "' . $app->name .'" already in download queue');
|
||||
die();
|
||||
}
|
||||
|
||||
Capsule::table('steam_queue')->insert([
|
||||
'appid' => $app->appid,
|
||||
'name' => $app->name,
|
||||
'status'=> 'Queued'
|
||||
]);
|
||||
|
||||
$this->info('Steam app "' . $app->name .'" added to download queue');
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class QueueApp extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:queue-app {app_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Queue a Steam app for donwloading';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$app = Capsule::table('steam_apps')
|
||||
->where('appid', $this->argument('app_id'))
|
||||
->first();
|
||||
|
||||
if( ! $app )
|
||||
{
|
||||
$this->error('Steam app with ID '.$this->argument('app_id').' not found');
|
||||
die();
|
||||
}
|
||||
|
||||
$alreadyQueued = Capsule::table('steam_queue')
|
||||
->where('appid', $app->appid)
|
||||
->count();
|
||||
|
||||
if( $alreadyQueued )
|
||||
{
|
||||
$this->error('Steam app "' . $app->name .'" already in download queue');
|
||||
die();
|
||||
}
|
||||
|
||||
Capsule::table('steam_queue')->insert([
|
||||
'appid' => $app->appid,
|
||||
'name' => $app->name,
|
||||
'status'=> 'Queued'
|
||||
]);
|
||||
|
||||
$this->info('Steam app "' . $app->name .'" added to download queue');
|
||||
|
||||
}
|
||||
}
|
|
@ -1,40 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class SearchApps extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:search-apps {name}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Search Steam apps by name';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$apps = Capsule::table('steam_apps')
|
||||
->where('name', 'like', '%' . $this->argument('name') . '%')
|
||||
->get();
|
||||
|
||||
foreach($apps as $app)
|
||||
{
|
||||
$this->info($app->appid ."\t". $app->name);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class SearchApps extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:search-apps {name}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Search Steam apps by name';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$apps = Capsule::table('steam_apps')
|
||||
->where('name', 'like', '%' . $this->argument('name') . '%')
|
||||
->get();
|
||||
|
||||
foreach($apps as $app)
|
||||
{
|
||||
$this->info($app->appid ."\t". $app->name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class ShowQueue extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:show-queue {status?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Show the Steam app download queue';
|
||||
|
||||
/**
|
||||
* The permissible statuses.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const STATUSES = ['queued', 'completed', 'failed'];
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if( $this->argument('status') && ! in_array($this->argument('status'), $this::STATUSES))
|
||||
{
|
||||
$this->error('Invalid status specified. Available statuses are: '. implode(' ', $this::STATUSES));
|
||||
die();
|
||||
}
|
||||
|
||||
// If a status is specified, display only apps of that status
|
||||
if( $this->argument('status') )
|
||||
{
|
||||
$this->displayAppsWithStatus( $this->argument('status') );
|
||||
die();
|
||||
}
|
||||
|
||||
foreach($this::STATUSES as $status)
|
||||
{
|
||||
$this->displayAppsWithStatus($status);
|
||||
}
|
||||
}
|
||||
|
||||
private function displayAppsWithStatus( $status )
|
||||
{
|
||||
switch($status)
|
||||
{
|
||||
case 'queued':
|
||||
$messageStyle = 'comment';
|
||||
break;
|
||||
case 'completed':
|
||||
$messageStyle = 'info';
|
||||
break;
|
||||
case 'failed':
|
||||
$messageStyle = 'error';
|
||||
break;
|
||||
default:
|
||||
$messageStyle = 'info';
|
||||
}
|
||||
|
||||
$apps = Capsule::table('steam_queue')
|
||||
->where('status', $status)
|
||||
->orderBy('message')
|
||||
->get();
|
||||
|
||||
if ( ! count($apps) )
|
||||
return;
|
||||
|
||||
|
||||
$this->{$messageStyle}(ucfirst($status) . ':');
|
||||
|
||||
foreach( $apps as $app )
|
||||
{
|
||||
$this->{$messageStyle}( $app->appid ."\t". $app->name . "\t" . $app->message );
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class ShowQueue extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:show-queue {status?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Show the Steam app download queue';
|
||||
|
||||
/**
|
||||
* The permissible statuses.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const STATUSES = ['queued', 'completed', 'failed'];
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if( $this->argument('status') && ! in_array($this->argument('status'), $this::STATUSES))
|
||||
{
|
||||
$this->error('Invalid status specified. Available statuses are: '. implode(' ', $this::STATUSES));
|
||||
die();
|
||||
}
|
||||
|
||||
// If a status is specified, display only apps of that status
|
||||
if( $this->argument('status') )
|
||||
{
|
||||
$this->displayAppsWithStatus( $this->argument('status') );
|
||||
die();
|
||||
}
|
||||
|
||||
foreach($this::STATUSES as $status)
|
||||
{
|
||||
$this->displayAppsWithStatus($status);
|
||||
}
|
||||
}
|
||||
|
||||
private function displayAppsWithStatus( $status )
|
||||
{
|
||||
switch($status)
|
||||
{
|
||||
case 'queued':
|
||||
$messageStyle = 'comment';
|
||||
break;
|
||||
case 'completed':
|
||||
$messageStyle = 'info';
|
||||
break;
|
||||
case 'failed':
|
||||
$messageStyle = 'error';
|
||||
break;
|
||||
default:
|
||||
$messageStyle = 'info';
|
||||
}
|
||||
|
||||
$apps = Capsule::table('steam_queue')
|
||||
->where('status', $status)
|
||||
->orderBy('message')
|
||||
->get();
|
||||
|
||||
if ( ! count($apps) )
|
||||
return;
|
||||
|
||||
|
||||
$this->{$messageStyle}(ucfirst($status) . ':');
|
||||
|
||||
foreach( $apps as $app )
|
||||
{
|
||||
$this->{$messageStyle}( $app->appid ."\t". $app->name . "\t" . $app->message );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,75 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class UpdateAppList extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:update-app-list';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Get the latest list of apps from Steam';
|
||||
|
||||
/**
|
||||
* The URL to get the list of Steam apps from.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STEAM_APP_LIST_URL = 'https://api.steampowered.com/ISteamApps/GetAppList/v2';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Clearing apps from database');
|
||||
Capsule::table('steam_apps')->truncate();
|
||||
|
||||
$this->info('Downloading app list from Steam Web API');
|
||||
$client = new Client();
|
||||
$result = $client->request('GET', self::STEAM_APP_LIST_URL);
|
||||
|
||||
if ( $result->getStatusCode() != 200 )
|
||||
{
|
||||
$this->error('Steam Web API unreachable');
|
||||
die();
|
||||
}
|
||||
|
||||
$response = json_decode($result->getBody(), TRUE);
|
||||
|
||||
$apps = $response['applist']['apps'];
|
||||
|
||||
// Laravel's SQLite driver can only insert a maximum of 500 records
|
||||
// at a time in one compound INSERT statements, so we chunk the list
|
||||
// of ~50,000 apps into chunks of 500
|
||||
$appsChunked = array_chunk($apps, 500);
|
||||
|
||||
$bar = $this->output->createProgressBar(count($appsChunked));
|
||||
$bar->setFormat("%bar% %percent%%");
|
||||
|
||||
$this->info('Inserting records into database');
|
||||
foreach($appsChunked as $appChunk)
|
||||
{
|
||||
Capsule::table('steam_apps')->insert($appChunk);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
|
||||
$this->info(PHP_EOL . 'Done');
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class UpdateAppList extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'steam:update-app-list';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Get the latest list of apps from Steam';
|
||||
|
||||
/**
|
||||
* The URL to get the list of Steam apps from.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STEAM_APP_LIST_URL = 'https://api.steampowered.com/ISteamApps/GetAppList/v2';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Clearing apps from database');
|
||||
Capsule::table('steam_apps')->truncate();
|
||||
|
||||
$this->info('Downloading app list from Steam Web API');
|
||||
$client = new Client();
|
||||
$result = $client->request('GET', self::STEAM_APP_LIST_URL);
|
||||
|
||||
if ( $result->getStatusCode() != 200 )
|
||||
{
|
||||
$this->error('Steam Web API unreachable');
|
||||
die();
|
||||
}
|
||||
|
||||
$response = json_decode($result->getBody(), TRUE);
|
||||
|
||||
$apps = $response['applist']['apps'];
|
||||
|
||||
// Laravel's SQLite driver can only insert a maximum of 500 records
|
||||
// at a time in one compound INSERT statements, so we chunk the list
|
||||
// of ~50,000 apps into chunks of 500
|
||||
$appsChunked = array_chunk($apps, 500);
|
||||
|
||||
$bar = $this->output->createProgressBar(count($appsChunked));
|
||||
$bar->setFormat("%bar% %percent%%");
|
||||
|
||||
$this->info('Inserting records into database');
|
||||
foreach($appsChunked as $appChunk)
|
||||
{
|
||||
Capsule::table('steam_apps')->insert($appChunk);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
|
||||
$this->info(PHP_EOL . 'Done');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue