started implementing download method for mods and authentication for download.
This commit is contained in:
parent
8e2c931ad5
commit
20cd7d51c6
|
@ -44,6 +44,12 @@ class FactorioMod {
|
||||||
*/
|
*/
|
||||||
private $mod_folder = null;
|
private $mod_folder = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $game_folder - Path to the Factorio game folder.
|
||||||
|
*/
|
||||||
|
private $game_folder = "factorio";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads all Mods as FactorioMod objects to an array.
|
* Reads all Mods as FactorioMod objects to an array.
|
||||||
* @param string $modFolder Path to the mods folder.
|
* @param string $modFolder Path to the mods folder.
|
||||||
|
@ -223,7 +229,14 @@ class FactorioMod {
|
||||||
* @return bool True if the mod was downloaded, false otherwise.
|
* @return bool True if the mod was downloaded, false otherwise.
|
||||||
*/
|
*/
|
||||||
private function download() : bool {
|
private function download() : bool {
|
||||||
// TODO: implement
|
|
||||||
|
// TODO: continue implementing.. where player-data.json..
|
||||||
|
$player_data = json_decode(file_get_contents($this->game_folder. "/player-data.json"), true);
|
||||||
|
$token = $player_data["service-token"];
|
||||||
|
$username = $player_data["service-username"];
|
||||||
|
|
||||||
|
$url = "https://mods.factorio.com" . $this->getLastVersionInfo()->download_url . "?username=$username&token=$token";
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +272,11 @@ class FactorioMod {
|
||||||
* @return bool True if the mod settings have been loaded successfully, false otherwise.
|
* @return bool True if the mod settings have been loaded successfully, false otherwise.
|
||||||
*/
|
*/
|
||||||
private function loadModSettings() : bool {
|
private function loadModSettings() : bool {
|
||||||
// TODO: implement
|
|
||||||
|
$this->mod_settings = json_decode(
|
||||||
|
file_get_contents($this->mod_folder. "/settings.json")
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,6 +288,28 @@ class FactorioMod {
|
||||||
return $this->mod_settings;
|
return $this->mod_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the path to the game folder.
|
||||||
|
* @param string $game_folder Path to the game folder.
|
||||||
|
* @return FactorioMod The instance of FactorioMod for chaining.
|
||||||
|
*/
|
||||||
|
public function setGameFolder(string $game_folder) : FactorioMod {
|
||||||
|
|
||||||
|
$this->game_folder = $game_folder;
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the path to the game folder.
|
||||||
|
* @return string Path to the game folder.
|
||||||
|
*/
|
||||||
|
public function getGameFolder() : string {
|
||||||
|
|
||||||
|
return $this->game_folder;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the changes in the mod settings for all mods (enabled/disabled) to the settings.json file.
|
* Saves the changes in the mod settings for all mods (enabled/disabled) to the settings.json file.
|
||||||
* @return bool True if the mod settings have been saved successfully, false otherwise.
|
* @return bool True if the mod settings have been saved successfully, false otherwise.
|
||||||
|
@ -278,9 +317,15 @@ class FactorioMod {
|
||||||
private function saveModSettings() : bool {
|
private function saveModSettings() : bool {
|
||||||
|
|
||||||
$j = json_encode($this->mod_settings);
|
$j = json_encode($this->mod_settings);
|
||||||
// TODO: implement
|
|
||||||
|
|
||||||
return false;
|
$r = file_put_contents($this->mod_folder. "/settings.json", $j);
|
||||||
|
|
||||||
|
if($r === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( $r === strlen($j) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue