Skip to content

Commit 298cb3c

Browse files
committed
Separated full and headless instances of Factorio to keep both as they come.
Refactored the download process of the Factorio game.
1 parent 74fc60c commit 298cb3c

18 files changed

+893
-928
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@
7373
"test-unit": "phpunit --testsuite unit-test --colors=always --coverage-html=test/coverage --coverage-clover=test/coverage/clover.xml",
7474
"test-serialize": "phpunit --testsuite serializer-test --colors=always",
7575
"post-autoload-dump": [
76-
"mkdir -p data/cache data/factorio data/log data/mods data/temp data/instances",
77-
"chmod 0777 data/cache data/factorio data/log data/mods data/temp data/instances"
76+
"mkdir -m a=rwx -p data/cache data/factorio data/factorio/full data/factorio/headless data/log data/mods data/temp data/instances"
7877
],
7978
"test": [
8079
"@composer validate --strict",

composer.lock

Lines changed: 424 additions & 332 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/autoload/dependencies.global.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
Command\ProcessStep\RenderIconsStep::class => AutoWireFactory::class,
4141
Command\ProcessStep\UploadStep::class => AutoWireFactory::class,
4242

43-
Factorio\FactorioDownloader::class => AutoWireFactory::class,
44-
4543
Helper\HashCalculator::class => AutoWireFactory::class,
4644
Helper\ZipArchiveExtractor::class => AutoWireFactory::class,
4745

@@ -82,6 +80,7 @@
8280
Serializer\Handler\ConstructorHandler::class => AutoWireFactory::class,
8381
Serializer\Handler\RawHandler::class => AutoWireFactory::class,
8482

83+
Service\FactorioDownloadService::class => AutoWireFactory::class,
8584
Service\FactorioExecutionService::class => AutoWireFactory::class,
8685
Service\ModDownloadService::class => AutoWireFactory::class,
8786
Service\ModFileService::class => AutoWireFactory::class,
@@ -104,9 +103,11 @@
104103
'int $numberOfParallelDownloads' => readConfig(ConfigKey::MAIN, ConfigKey::PARALLEL_DOWNLOADS),
105104
'int $numberOfParallelRenderProcesses' => readConfig(ConfigKey::MAIN, ConfigKey::PARALLEL_RENDERS),
106105

106+
'string $factorioApiToken' => readConfig(ModConfigKey::MAIN, ModConfigKey::OPTIONS, ModConfigKey::OPTION_TOKEN),
107+
'string $factorioApiUsername' => readConfig(ModConfigKey::MAIN, ModConfigKey::OPTIONS, ModConfigKey::OPTION_USERNAME),
108+
'string $fullFactorioDirectory' => readConfig(ConfigKey::MAIN, ConfigKey::DIRECTORIES, ConfigKey::DIRECTORY_FACTORIO_FULL),
107109
'string $factorioDirectory' => readConfig(ConfigKey::MAIN, ConfigKey::DIRECTORIES, ConfigKey::DIRECTORY_FACTORIO),
108-
'string $factorioDownloadToken' => readConfig(ModConfigKey::MAIN, ModConfigKey::OPTIONS, ModConfigKey::OPTION_TOKEN),
109-
'string $factorioDownloadUsername' => readConfig(ModConfigKey::MAIN, ModConfigKey::OPTIONS, ModConfigKey::OPTION_USERNAME),
110+
'string $headlessFactorioDirectory' => readConfig(ConfigKey::MAIN, ConfigKey::DIRECTORIES, ConfigKey::DIRECTORY_FACTORIO_HEADLESS),
110111
'string $instancesDirectory' => readConfig(ConfigKey::MAIN, ConfigKey::DIRECTORIES, ConfigKey::DIRECTORY_INSTANCES),
111112
'string $logsDirectory' => readConfig(ConfigKey::MAIN, ConfigKey::DIRECTORIES, ConfigKey::DIRECTORY_LOGS),
112113
'string $modsDirectory' => readConfig(ConfigKey::MAIN, ConfigKey::DIRECTORIES, ConfigKey::DIRECTORY_MODS),

config/autoload/development/export.local.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
ConfigKey::MAIN => [
1818
ConfigKey::DIRECTORIES => [
1919
// ConfigKey::DIRECTORY_CACHE => 'data/cache',
20-
ConfigKey::DIRECTORY_FACTORIO => 'data/factorio',
20+
ConfigKey::DIRECTORY_FACTORIO_FULL => 'data/factorio/full',
21+
ConfigKey::DIRECTORY_FACTORIO_HEADLESS => 'data/factorio/headless',
2122
ConfigKey::DIRECTORY_INSTANCES => 'data/instances',
2223
ConfigKey::DIRECTORY_LOGS => 'data/log',
2324
ConfigKey::DIRECTORY_MODS => 'data/mods',

src/Command/DownloadFactorioCommand.php

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
namespace FactorioItemBrowser\Export\Command;
66

77
use FactorioItemBrowser\Export\Constant\CommandName;
8-
use FactorioItemBrowser\Export\Factorio\FactorioDownloader;
8+
use FactorioItemBrowser\Export\Output\Console;
9+
use FactorioItemBrowser\Export\Service\FactorioDownloadService;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputArgument;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Output\OutputInterface;
14+
use Symfony\Component\Filesystem\Filesystem;
1315

1416
/**
1517
* The process for downloading the Factorio game itself.
@@ -19,13 +21,31 @@
1921
*/
2022
class DownloadFactorioCommand extends Command
2123
{
22-
protected FactorioDownloader $factorioDownloader;
24+
protected Console $console;
25+
protected FactorioDownloadService $factorioDownloadService;
26+
protected Filesystem $fileSystem;
2327

24-
public function __construct(FactorioDownloader $factorioDownloader)
25-
{
28+
protected string $fullFactorioDirectory;
29+
protected string $headlessFactorioDirectory;
30+
protected string $tempDirectory;
31+
32+
public function __construct(
33+
Console $console,
34+
FactorioDownloadService $factorioDownloadService,
35+
Filesystem $fileSystem,
36+
string $fullFactorioDirectory,
37+
string $headlessFactorioDirectory,
38+
string $tempDirectory,
39+
) {
2640
parent::__construct();
2741

28-
$this->factorioDownloader = $factorioDownloader;
42+
$this->console = $console;
43+
$this->factorioDownloadService = $factorioDownloadService;
44+
$this->fileSystem = $fileSystem;
45+
46+
$this->fullFactorioDirectory = (string) realpath($fullFactorioDirectory);
47+
$this->headlessFactorioDirectory = (string) realpath($headlessFactorioDirectory);
48+
$this->tempDirectory = (string) realpath($tempDirectory);
2949
}
3050

3151
protected function configure(): void
@@ -41,8 +61,39 @@ protected function configure(): void
4161
protected function execute(InputInterface $input, OutputInterface $output): int
4262
{
4363
$version = strval($input->getArgument('version'));
64+
$archiveFileFull = $this->tempDirectory . "/factorio_${version}_full.tar.xz";
65+
$archiveFileHeadless = $this->tempDirectory . "/factorio_${version}_headless.tar.xz";
66+
67+
$this->console->writeHeadline("Downloading and installing Factorio version {$version}");
68+
69+
$this->console->writeAction('Downloading full variant of Factorio');
70+
$fullProcess = $this->factorioDownloadService->createFactorioDownloadProcess(
71+
FactorioDownloadService::VARIANT_FULL,
72+
$version,
73+
$archiveFileFull,
74+
);
75+
$fullProcess->start();
76+
77+
$this->console->writeAction('Downloading headless variant of Factorio');
78+
$headlessProcess = $this->factorioDownloadService->createFactorioDownloadProcess(
79+
FactorioDownloadService::VARIANT_HEADLESS,
80+
$version,
81+
$archiveFileHeadless,
82+
);
83+
$headlessProcess->run();
84+
85+
$this->console->writeAction('Extracting headless variant of Factorio');
86+
$this->factorioDownloadService->extractFactorio($archiveFileHeadless, $this->headlessFactorioDirectory);
87+
88+
$fullProcess->wait();
89+
$this->console->writeAction('Extracting full variant of Factorio');
90+
$this->factorioDownloadService->extractFactorio($archiveFileFull, $this->fullFactorioDirectory);
91+
92+
$this->console->writeAction('Cleaning up');
93+
$this->fileSystem->remove($archiveFileHeadless);
94+
$this->fileSystem->remove($archiveFileFull);
4495

45-
$this->factorioDownloader->download($version);
96+
$this->console->writeMessage('Done.');
4697
return 0;
4798
}
4899
}

src/Constant/ConfigKey.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ interface ConfigKey
3232
*/
3333
public const DIRECTORY_FACTORIO = 'factorio';
3434

35+
/**
36+
* The key holding the directory of the installed full Factorio game.
37+
*/
38+
public const DIRECTORY_FACTORIO_FULL = 'factorio-full';
39+
40+
/**
41+
* The key holding the directory of the installed headless Factorio game.
42+
*/
43+
public const DIRECTORY_FACTORIO_HEADLESS = 'factorio-headless';
44+
3545
/**
3646
* The key holding the instances directory.
3747
*/

src/Factorio/FactorioDownloader.php

Lines changed: 0 additions & 213 deletions
This file was deleted.

src/Output/ProcessOutput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(ConsoleSectionOutput $output)
3232
public function addLine(string $line): self
3333
{
3434
$height = min($this->terminal->getHeight() - 6, self::NUMBER_OF_LINES);
35+
/** @var positive-int $width */
3536
$width = $this->terminal->getWidth();
3637

3738
$this->lines = array_slice(array_merge($this->lines, str_split($line, $width)), -$height);

0 commit comments

Comments
 (0)